diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright Jake Wheat 2010
+Copyright Jake Wheat 2010-2014
 
 All rights reserved.
 
diff --git a/README b/README
--- a/README
+++ b/README
@@ -1,12 +1,13 @@
 A parser, pretty printer, and type checker for SQL written in
-Haskell. Supports PostgreSQL SQL and PL/pgSQL syntax. BSD licensed.
+Haskell. Mainly targets the PostgreSQL dialect of SQL and PL/pgSQL
+syntax.
 
-Install with:
-cabal update
-cabal install hssqlppp
+Pre alpha: works well and is stable for a subset of SQL, but there are
+lots of unfinished areas and the api is likely to change a lot from
+release to release at this time.
 
 Website, with some docs and examples:
-http://jakewheat.github.com/hssqlppp/
+http://jakewheat.github.com/hssqlppp/latest
 
 Hackage: http://hackage.haskell.org/package/hssqlppp
 
diff --git a/THANKS b/THANKS
deleted file mode 100644
--- a/THANKS
+++ /dev/null
@@ -1,3 +0,0 @@
-Christoph Bauer for bug reports, testing and feedback on the API
-Hideki Kariya for bug reports and patches
-Ilya Portnov for bug reports and suggestions
diff --git a/hssqlppp.cabal b/hssqlppp.cabal
--- a/hssqlppp.cabal
+++ b/hssqlppp.cabal
@@ -1,20 +1,23 @@
 Name:                hssqlppp
-Version:             0.4.2
+Version:             0.6.0
 Synopsis:            SQL parser and type checker
 License:             BSD3
 License-file:        LICENSE
-Author:              Jake Wheat
+Author:              Jake Wheat, SQream
 Maintainer:          jakewheatmail@gmail.com
 Build-Type:          Simple
 Cabal-Version:       >=1.10
-copyright:           Copyright 2009-2014 Jake Wheat
-stability:           pre-alpha
+copyright:           Copyright 2009-2015 Jake Wheat, Copyright 2011-2015 SQream
 homepage:            http://jakewheat.github.com/hssqlppp/
 bug-reports:         https://github.com/JakeWheat/hssqlppp/issues
 category:            Database,Language
 Description:
     SQL parser and type checker, targets PostgreSQL SQL and PL/pgSQL.
     .
+    Pre alpha: works well and is stable for a subset of SQL, but there
+    are lots of unfinished areas and the api is likely to change a lot
+    from release to release at this time.
+    .
     Documentation, examples on the homepage:
     <http://jakewheat.github.com/hssqlppp/>.
     .
@@ -22,8 +25,6 @@
 
 extra-source-files:  README
                      LICENSE
-                     THANKS
-                     --find src/ -iname '*.ag' -o -iname '.sql' -o -iname '*.txt' -o -iname '*.hs' -o -iname '*.lhs'
 
 source-repository head
   type:     git
@@ -31,112 +32,165 @@
 
 Library
   Build-Depends:     base >= 4 && < 5,
-                     mtl >= 2.2 && < 2.3,
                      containers >= 0.3.0.0 && < 0.6,
-                     parsec >= 3.1 && < 3.2,
-                     pretty >= 1.1 && < 1.2,
-                     syb >= 0.4 && < 0.5,
+                     mtl >= 2.0.1.0 && < 2.3,
+                     parsec >= 3.1.2 && < 3.2,
+                     pretty >= 1.0 && < 1.2,
+                     syb >= 0.1.0.2 && < 0.7,
+                     text >= 0.11.1.13 && < 1.3,
                      uniplate >= 1.6 && < 1.7,
-                     transformers >= 0.4 && < 0.5,
-                     template-haskell
+                     transformers >= 0.3 && < 0.6,
+                     pretty-show >= 1.6 && < 1.7
 
-  default-language:  Haskell2010
   hs-source-dirs:    src
-  Exposed-modules:   Database.HsSqlPpp.Ast
-                     Database.HsSqlPpp.Annotation
+  Exposed-modules:   Database.HsSqlPpp.Annotation
                      Database.HsSqlPpp.Catalog
-                     Database.HsSqlPpp.Parser
+                     Database.HsSqlPpp.Dialect
+                     Database.HsSqlPpp.Lex
+                     Database.HsSqlPpp.Parse
                      Database.HsSqlPpp.Pretty
+                     Database.HsSqlPpp.Syntax
                      Database.HsSqlPpp.Types
-                     Database.HsSqlPpp.TypeChecker
-                     Database.HsSqlPpp.Quote
+                     Database.HsSqlPpp.TypeCheck
+                     Database.HsSqlPpp.Utility
 
-                     -- find src/lib -iname '*hs' | sed -e "s@src/@@" | sed -e "s@/@.@g" |sed -e "s/.lhs//" |sed -e "s/.hs//"
-  Other-Modules:     Database.HsSqlPpp.Utils.Utils
-                     Database.HsSqlPpp.Parsing.ParseErrors
-                     Database.HsSqlPpp.Parsing.Lexer
-                     Database.HsSqlPpp.Parsing.ParserInternal
-                     Database.HsSqlPpp.Internals.Catalog.CatalogInternal
-                     Database.HsSqlPpp.Internals.Catalog.DefaultTemplate1Catalog
-                     Database.HsSqlPpp.Internals.TypeChecking.TypeConversion
-                     Database.HsSqlPpp.Internals.TypeChecking.ErrorUtils
-                     Database.HsSqlPpp.Internals.TypeChecking.LocalBindings
-                     Database.HsSqlPpp.Internals.TypeChecking.Utils
-                     Database.HsSqlPpp.Internals.TypeChecking.IDEnv
-                     Database.HsSqlPpp.Internals.TypeChecking.LocalBindingsInternal
-                     Database.HsSqlPpp.Internals.AstAnnotation
-                     Database.HsSqlPpp.Internals.AnnotationUtils
-                     Database.HsSqlPpp.Internals.AstInternal
-                     Database.HsSqlPpp.Internals.TypeType
+                     -- find src -iname '*hs' | sed -e "s@src/@@" | sed -e "s@/@.@g" |sed -e "s/.lhs//" |sed -e "s/.hs//"
+  Other-Modules:    Database.HsSqlPpp.Internals.TypeChecking.OldTediousTypeUtils
+                    Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.TypeConversion2
+                    Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.OldTypeConversion
+                    Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.TypeConversion
+                    Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.SqlTypeConversion
+                    Database.HsSqlPpp.Internals.TypeChecking.Environment
+                    Database.HsSqlPpp.Internals.LexInternal
+                    Database.HsSqlPpp.Internals.Dialect
+                    Database.HsSqlPpp.Internals.ParseInternal
+                    Database.HsSqlPpp.Internals.PrettyInternal
+                    Database.HsSqlPpp.Internals.Catalog.CatalogUtils
+                    Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+                    Database.HsSqlPpp.Internals.Catalog.CatalogBuilder
+                    Database.HsSqlPpp.Internals.Catalog.CatalogInternal
+                    Database.HsSqlPpp.Internals.Catalog.CatalogNew
+                    Database.HsSqlPpp.Internals.AstInternal
+                    Database.HsSqlPpp.Internals.TypesInternal
+                    Database.HsSqlPpp.Internals.ParseErrors
+                    Database.HsSqlPpp.Internals.Utils
+                    Database.HsSqlPpp.Dialects.SqlServer
+                    Database.HsSqlPpp.Dialects.GeneratedPostgres
+                    Database.HsSqlPpp.Dialects.Postgres
+                    Database.HsSqlPpp.Dialects.Oracle
+                    Database.HsSqlPpp.Dialects.OdbcCatalog
+                    Database.HsSqlPpp.Dialects.BaseCatalog
+                    Database.HsSqlPpp.Dialects.Ansi
 
+  default-language:    Haskell2010
+  ghc-options:         -Wall
+
 Test-Suite Tests
-  type:                exitcode-stdio-1.0
-  main-is:             Tests.lhs
-  hs-source-dirs:      src,
-                       src-extra/tests,
-                       src-extra/util
-  Build-Depends:       base >=4.6 && <4.8,
-                       mtl >= 2.2 && < 2.3,
+    type:       exitcode-stdio-1.0
+    main-is:    Tests.lhs
+    hs-source-dirs:    src,tests
+    Build-Depends:     base >= 4 && < 5,
                        containers >= 0.3.0.0 && < 0.6,
+                       haskell-src-exts >= 1.13 && < 1.18,
+                       mtl >= 2.1 && < 2.3,
                        parsec >= 3.1 && < 3.2,
-                       pretty >= 1.1 && < 1.2,
-                       syb >= 0.4 && < 0.5,
-                       uniplate >= 1.6 && < 1.7,
-                       transformers >= 0.4 && < 0.5,
+                       pretty >= 1.0 && < 1.2,
+                       syb >= 0.1.0.2 && < 0.7,
                        template-haskell,
-                       HUnit >= 1.2 && < 1.3,
-                       test-framework >= 0.8 && < 0.9,
-                       test-framework-hunit >= 0.3 && < 0.4,
-                       groom >= 0.1 && < 0.2
-  Other-Modules:       Database.HsSqlPpp.Tests.TypeChecking.Insert
-                       Database.HsSqlPpp.Tests.TypeChecking.Misc
-                       Database.HsSqlPpp.Tests.TypeChecking.Into
-                       Database.HsSqlPpp.Tests.TypeChecking.Literals
-                       Database.HsSqlPpp.Tests.TypeChecking.RowCtors
-                       Database.HsSqlPpp.Tests.TypeChecking.SpecialFunctions
-                       Database.HsSqlPpp.Tests.TypeChecking.Plpgsql
-                       Database.HsSqlPpp.Tests.TypeChecking.SimpleExpressions
-                       Database.HsSqlPpp.Tests.TypeChecking.MiscExpressions
-                       Database.HsSqlPpp.Tests.TypeChecking.Joins
-                       Database.HsSqlPpp.Tests.TypeChecking.Qualification
-                       Database.HsSqlPpp.Tests.TypeChecking.TableRefTests
-                       Database.HsSqlPpp.Tests.TypeChecking.Update
-                       Database.HsSqlPpp.Tests.TypeChecking.CombineSelects
-                       Database.HsSqlPpp.Tests.TypeChecking.MiscSelects
-                       Database.HsSqlPpp.Tests.TypeChecking.Drops
-                       Database.HsSqlPpp.Tests.TypeChecking.CatalogChaining
-                       Database.HsSqlPpp.Tests.TypeChecking.Delete
-                       Database.HsSqlPpp.Tests.TypeChecking.SelectFrom
-                       Database.HsSqlPpp.Tests.TypeChecking.Creates
-                       Database.HsSqlPpp.Tests.TypeChecking.CaseExpressions
-                       Database.HsSqlPpp.Tests.TypeChecking.TypeCheckTests
-                       Database.HsSqlPpp.Tests.TypeChecking.Utils
-                       Database.HsSqlPpp.Tests.TypeChecking.TypeInferenceTests
-                       Database.HsSqlPpp.Tests.TypeChecking.SimpleSelects
-                       Database.HsSqlPpp.Tests.TypeChecking.TpchTests
-                       Database.HsSqlPpp.Tests.TypeChecking.Triggers
-                       Database.HsSqlPpp.Tests.FixTree.FixUpIdentifiersTests
-                       Database.HsSqlPpp.Tests.FixTree.ExplicitCasts
-                       Database.HsSqlPpp.Tests.Tests
-                       Database.HsSqlPpp.Tests.TestUtils
-                       Database.HsSqlPpp.Tests.QuasiQuoteTests
-                       Database.HsSqlPpp.Tests.Parsing.Dml
-                       Database.HsSqlPpp.Tests.Parsing.Misc
-                       Database.HsSqlPpp.Tests.Parsing.Plpgsql
-                       Database.HsSqlPpp.Tests.Parsing.CreateTable
-                       Database.HsSqlPpp.Tests.Parsing.FunctionsDdl
-                       Database.HsSqlPpp.Tests.Parsing.Selects
-                       Database.HsSqlPpp.Tests.Parsing.ParserTests
-                       Database.HsSqlPpp.Tests.Parsing.Expressions
-                       Database.HsSqlPpp.Tests.Parsing.MiscDdl
-                       Database.HsSqlPpp.Tests.Parsing.Utils
-                       Database.HsSqlPpp.Tests.ParameterizedStatementTests
-                       Database.HsSqlPpp.Tests.TpchData
-                       Database.HsSqlPpp.Utils.Here
-                       Database.HsSqlPpp.Utils.PgUtils
-                       Database.HsSqlPpp.Utils.CatalogReader
+                       tasty >= 0.10 && < 0.12,
+                       tasty-hunit >= 0.9 && < 0.10,
+                       text >= 0.11.1.13 && < 1.3,
+                       uniplate >= 1.6 && < 1.7,
+                       transformers >= 0.3 && < 0.6,
+                       pretty-show >= 1.6 && < 1.7
 
+                     -- rough start:
+                     -- find src-extra/tests -iname '*hs' | sed -e "s@src-extra/tests/@@" | sed -e "s@/@.@g" |sed -e "s/.lhs//" |sed -e "s/.hs//"
+  Other-Modules:    Database.HsSqlPpp.Tests.TypeChecking.OdbcTypechecking
+                    Database.HsSqlPpp.Tests.TypeChecking.Aggregates
+                    Database.HsSqlPpp.Tests.TypeChecking.DDL
+                    Database.HsSqlPpp.Tests.TypeChecking.Rewrites
+                    Database.HsSqlPpp.Tests.TypeChecking.TrefIdentifiers
+                    Database.HsSqlPpp.Tests.TypeChecking.ScalarExprs
+                    Database.HsSqlPpp.Tests.TypeChecking.PrecisionAndNullable
+                    Database.HsSqlPpp.Tests.TypeChecking.ImplicitCasts
+                    Database.HsSqlPpp.Tests.TypeChecking.TypeConversion
+                    Database.HsSqlPpp.Tests.TypeChecking.Joins
+                    Database.HsSqlPpp.Tests.TypeChecking.InsertQueryExprs
+                    Database.HsSqlPpp.Tests.TypeChecking.TSQL
+                    Database.HsSqlPpp.Tests.TypeChecking.Tpch
+                    Database.HsSqlPpp.Tests.TypeChecking.CaseExpressions
+                    Database.HsSqlPpp.Tests.TypeChecking.QueryExprs
+                    Database.HsSqlPpp.Tests.TypeChecking.TypeCheckTests
+                    Database.HsSqlPpp.Tests.TypeChecking.SimpleQueryExprs
+                    Database.HsSqlPpp.Tests.TypeChecking.Utils
+                    Database.HsSqlPpp.Tests.TypeChecking.TrefSchemas
+                    Database.HsSqlPpp.Tests.TypeChecking.Issues
+                    Database.HsSqlPpp.Tests.TypeChecking.Updates
+                    Database.HsSqlPpp.Tests.Tests
+                    Database.HsSqlPpp.Tests.TestUtils
+                    Database.HsSqlPpp.Tests.Parsing.Dml
+                    Database.HsSqlPpp.Tests.Parsing.SqlServer
+                    Database.HsSqlPpp.Tests.Parsing.Misc
+                    Database.HsSqlPpp.Tests.Parsing.ScalarExprs
+                    Database.HsSqlPpp.Tests.Parsing.Plpgsql
+                    Database.HsSqlPpp.Tests.Parsing.LexerTests
+                    Database.HsSqlPpp.Tests.Parsing.CreateTable
+                    Database.HsSqlPpp.Tests.Parsing.SelectLists
+                    Database.HsSqlPpp.Tests.Parsing.OdbcParsing
+                    Database.HsSqlPpp.Tests.Parsing.FunctionsDdl
+                    Database.HsSqlPpp.Tests.Parsing.Joins
+                    Database.HsSqlPpp.Tests.Parsing.ParserTests
+                    Database.HsSqlPpp.Tests.Parsing.Oracle
+                    Database.HsSqlPpp.Tests.Parsing.Schemas
+                    Database.HsSqlPpp.Tests.Parsing.MiscQueryExprs
+                    Database.HsSqlPpp.Tests.Parsing.TableRefs
+                    Database.HsSqlPpp.Tests.Parsing.MiscDdl
+                    Database.HsSqlPpp.Tests.Parsing.Utils
+                    Database.HsSqlPpp.Tests.Parsing.CombineQueryExprs
+                    Database.HsSqlPpp.Tests.TestTypes
+                    Database.HsSqlPpp.Tests.TpchData
+                    Database.HsSqlPpp.Utils.Here
+                    Database.HsSqlPpp.Utils.GroomUtils
+                    Database.HsSqlPpp.Tests.TypeChecking.Catalog
 
-  other-extensions:    TupleSections,DeriveDataTypeable
+    Database.HsSqlPpp.Annotation
+    Database.HsSqlPpp.Catalog
+    Database.HsSqlPpp.Dialect
+    Database.HsSqlPpp.Dialects.Ansi
+    Database.HsSqlPpp.Dialects.BaseCatalog
+    Database.HsSqlPpp.Dialects.GeneratedPostgres
+    Database.HsSqlPpp.Dialects.OdbcCatalog
+    Database.HsSqlPpp.Dialects.Oracle
+    Database.HsSqlPpp.Dialects.Postgres
+    Database.HsSqlPpp.Dialects.SqlServer
+    Database.HsSqlPpp.Internals.AstInternal
+    Database.HsSqlPpp.Internals.Catalog.CatalogBuilder
+    Database.HsSqlPpp.Internals.Catalog.CatalogInternal
+    Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+    Database.HsSqlPpp.Internals.Catalog.CatalogUtils
+    Database.HsSqlPpp.Internals.Catalog.CatalogNew
+    Database.HsSqlPpp.Internals.Dialect
+    Database.HsSqlPpp.Internals.LexInternal
+    Database.HsSqlPpp.Internals.ParseErrors
+    Database.HsSqlPpp.Internals.ParseInternal
+    Database.HsSqlPpp.Internals.PrettyInternal
+    Database.HsSqlPpp.Internals.TypeChecking.Environment
+    Database.HsSqlPpp.Internals.TypeChecking.OldTediousTypeUtils
+    Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.OldTypeConversion
+    Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.SqlTypeConversion
+    Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.TypeConversion
+    Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.TypeConversion2
+    Database.HsSqlPpp.Internals.TypesInternal
+    Database.HsSqlPpp.Internals.Utils
+    Database.HsSqlPpp.Lex
+    Database.HsSqlPpp.Parse
+    Database.HsSqlPpp.Pretty
+    Database.HsSqlPpp.Syntax
+    Database.HsSqlPpp.Tests.TypeChecking.AnsiScalarExprs
+    Database.HsSqlPpp.TypeCheck
+    Database.HsSqlPpp.Types
+    Database.HsSqlPpp.Utility
+
   default-language:    Haskell2010
   ghc-options:         -Wall
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/FixTree/ExplicitCasts.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/FixTree/ExplicitCasts.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/FixTree/ExplicitCasts.lhs
+++ /dev/null
@@ -1,85 +0,0 @@
-
-Tests using the tpch queries. Just tests the result type at the
-moment.
-
-> module Database.HsSqlPpp.Tests.FixTree.ExplicitCasts
->     (explicitCastTests) where
->
-> import Test.HUnit
-> import Test.Framework
-> import Test.Framework.Providers.HUnit
-> --import Data.List
-> import Control.Monad
->
-> --import Database.HsSqlPpp.Utils.Here
-> import Database.HsSqlPpp.Parser
-> import Database.HsSqlPpp.TypeChecker
-> --import Database.HsSqlPpp.Annotation
-> import Database.HsSqlPpp.Catalog
-> import Database.HsSqlPpp.Types
-> --import Database.HsSqlPpp.Utils.PPExpr
-> --import Database.HsSqlPpp.Tests.TestUtils
-> import Database.HsSqlPpp.Pretty
-> --import Database.HsSqlPpp.Tests.TpchData
-> import Text.Groom
-> import Database.HsSqlPpp.Tests.TestUtils
-
-
-> --import Data.Data
-> --import Data.Generics.Uniplate.Data
-> --import Database.HsSqlPpp.Ast
-
->
-> data Item = Group String [Item]
->           | Query String String
->
-> explicitCastTests :: Test.Framework.Test
-> explicitCastTests = itemToTft explicitCastTestData
->
-> explicitCastTestData :: Item
-> explicitCastTestData =
->   Group "explicitcasts" [
->     Query "select a+b from t;" "select (a::float8) + (b::float8) from t;"
->    ,Query "select case true when true then 1::int else 1::float4 end;"
->           "select case true when true then (1::int)::float4 else 1::float4 end;"
->    ,Query "select case when true then 1::int else 1::float4 end;"
->           "select case when true then (1::int)::float4 else 1::float4 end;"
->    ,Query "select 3::int between 1::float8 and 4::numeric;"
->           "select (3::int)::float8 between 1::float8 and (4::numeric)::float8;"
->    ,Query "select a from t where c between 1.0 and 1.2"
->           "select a from t where c between 1.0::numeric and 1.2::numeric"
->    ,Query "select a from t where d in ('a', 'bc')"
->           "select a from t where d in ('a'::char, 'bc'::char)"
->   ]
-
-> itemToTft :: Item -> Test.Framework.Test
-> itemToTft (Group s is) = testGroup s $ map itemToTft is
-> itemToTft (Query sql sql1) = testCase ("ec " ++ sql) $ do
->   --putStrLn $ ppExpr $ ptc sql
->   let ast = {-resetAnnotations $-} addExplicitCasts $ ptc sql
->       ast1 = {-resetAnnotations $-} canonicalizeTypeNames $ ptc sql1
->   when (resetAnnotations ast /= resetAnnotations ast1)
->     $ putStrLn $ printQueryExpr ast
->        ++ "\n" ++ printQueryExpr ast1
->        ++ "\n\n" ++ groom ast
->        ++ "\n\n" ++ groom ast1
->        ++ "\n\n"
->   assertEqual "" (resetAnnotations ast) (resetAnnotations ast1)
->   where
->     ptc s = typeCheckQueryExpr cat
->             $  case parseQueryExpr "" s of
->                  Left e -> error $ show e
->                  Right l -> l
-
-> cat :: Catalog
-> cat = case updateCatalog defaultTemplate1Catalog testCatalog of
->         Left x -> error $ show x
->         Right e -> e
-
-
-
-> testCatalog :: [CatalogUpdate]
-> testCatalog = [CatCreateTable "t" [("a", typeFloat4)
->                                   ,("b", typeInt)
->                                   ,("c", typeNumeric)
->                                   ,("d", typeChar)] []]
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/FixTree/FixUpIdentifiersTests.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/FixTree/FixUpIdentifiersTests.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/FixTree/FixUpIdentifiersTests.lhs
+++ /dev/null
@@ -1,229 +0,0 @@
-
-cd /home/jake/wd/hssqlppp/trunk/src/lib/Database/HsSqlPpp/Internals && uuagc --genlinepragmas -dcfwsp AstInternal.ag && cd /home/jake/wd/hssqlppp/trunk/ && cabal build
-
-> module Database.HsSqlPpp.Tests.FixTree.FixUpIdentifiersTests
->     (fixUpIdentifiersTests) where
->
-> import Test.HUnit
-> import Test.Framework
-> import Test.Framework.Providers.HUnit
-> --import Data.Generics.Uniplate.Data
-> import Control.Monad
-
-> import Database.HsSqlPpp.Parser
-> import Database.HsSqlPpp.TypeChecker
-> import Database.HsSqlPpp.Ast
-> --import Database.HsSqlPpp.Annotation
-> import Database.HsSqlPpp.Catalog
-> import Database.HsSqlPpp.Types
-> --import Database.HsSqlPpp.Utils.PPExpr
-> --import Database.HsSqlPpp.Tests.TestUtils
-> import Database.HsSqlPpp.Pretty
-> --import Database.HsSqlPpp.Tests.TpchData
-> --import Database.HsSqlPpp.Utils.Here
-> import Database.HsSqlPpp.Tests.TestUtils
-
-> data Item = Group String [Item]
->           | Item [CatalogUpdate] String String
->           | SItem [CatalogUpdate] String String
->
-> fixUpIdentifiersTests :: Test.Framework.Test
-> fixUpIdentifiersTests = itemToTft fixUpIdentifiersTestsData
->
-> fixUpIdentifiersTestsData :: Item
-> fixUpIdentifiersTestsData = Group "cantests"
->   [Group "select lists"
->     [Item db1 "select a,b from t;" "select t.a as a, t.b as b from t as t(a,b);"
->     ,Item db1 "select * from t;" "select t.a as a, t.b as b from t as t(a,b);"
->     ,Item db1 "select * from (select a from t) t;"
->               "select t.a as a from (select t.a as a from t as t(a,b)) as t(a);"
->     ,Item db1 "select * from generate_series(1,5);"
->               "select generate_series.generate_series as generate_series\n\
->               \from generate_series(1,5) as generate_series(generate_series);"
->     ,Item db1 "select a,c from t,u;"
->               "select t.a as a, u.c as c from t as t(a,b),u as u(c,d);"
->     ,Item db1 "select * from t,u;"
->               "select t.a as a,t.b as b,u.c as c,u.d as d \n\
->               \from t as t(a,b),u as u(c,d);"
->     ,Item db1 "select t.* from t,u;"
->               "select t.a as a, t.b as b from t as t(a,b),u as u(c,d);"
->     ,Item db1 "select u.* from t,u;"
->               "select u.c as c,u.d as d from t as t(a,b),u as u(c,d);"
->     ,Item db1 "select t.*,u.*,* from t,u;"
->               "select t.a as a, t.b as b,\n\
->               \       u.c as c, u.d as d,\n\
->               \       t.a as a, t.b as b, u.c as c, u.d as d\n\
->               \  from t as t(a,b),u as u(c,d);"
->     ,Item db1 "select v from v;" "select v.v as v from v as v(v);"
->     ,Item db1 "select count(*) from t;"
->               "select count(true) as count from t as t(a,b);"
->     ]
->   ,Group "trefs"
->     [Item db1 "select * from generate_series(1,5) g;"
->               "select g.g as g\n\
->               \from generate_series(1,5) as g(g);"
->     ,Item db1 "select a from t as x;"
->               "select x.a as a from t as x(a,b);"
->     ,Item db1 "select * from t as x(f,g);"
->               "select x.f as f ,x.g as g from t as x(f,g);"
->     ]
->   ,Group "where"
->     [Item db1 "select a,b from t where a > b;"
->               "select t.a as a, t.b as b from t as t(a,b) where t.a > t.b;"
->     ,Item db1 "select a,c from t,u where b = d;"
->               "select t.a as a,u.c as c\n\
->               \  from t as t(a,b),u as u(c,d)\n\
->               \  where t.b = u.d;"
->     ]
->   ,Group "groupby"
->     [Item db1 "select a,sum(b) from t group by a;"
->               "select t.a as a,sum(t.b) as sum\n\
->               \from t as t(a,b) group by t.a;"
->     ]
->   ,Group "having"
->     [Item db1 "select a,sum(b) from t group by a having a > b;"
->               "select t.a as a,sum(t.b) as sum from t as t(a,b)\n\
->               \group by t.a having t.a > t.b;"
->     ]
->   ,Group "orderby"
->     [Item db1 "select a from t order by b;"
->               "select t.a as a from t as t(a,b) order by t.b;"
->     ]
->    -- fixme: needs some work before these pass
->   {-,Group "ctes"
->     [Item []   "with ta as (select 1 as a, 2 as b)\n\
->                 \select * from ta;"
->
->                 "with ta(a,b) as (select 1 as a, 2 as b)\n\
->                 \select ta.a as a, ta.b as b from ta as ta(a,b);"
->     ,Item db1   "/*66642*/with ta as (select 1 as a, 2 as b),\n\
->                 \     tb as (select * from t)\n\
->                 \select * from ta\n\
->                 \union select * from tb;"
->
->                 "with ta(a,b) as (select 1 as a, 2 as b),\n\
->                 \     tb(a,b) as (select t.a as a, t.b as b from t as t(a,b))\n\
->                 \select ta.a as a, ta.b as b from ta as ta(a,b)\n\
->                 \union select tb.a as a, tb.b as tb from tb as tb(a,b);"
-
->     ]-}
->   ,Group "correlated subqueries"
->     [Item db1
->           "select a,b,c,d from t,u where a = c and d =\n\
->           \           (select min(d) from u where a = c);"
->           "select t.a as a,t.b as b,\n\
->           \       u.c as c, u.d as d\n\
->           \   from t as t(a,b),u as u(c,d)\n\
->           \   where t.a = u.c and u.d =\n\
->           \           (select min(u.d) as min from u as u(c,d) where t.a = u.c);"
-
->     ]
->   ,Group "funtrefs"
->     [Item [] "select * from generate_series(1,7) g\n\
->              \where g not in (select * from generate_series(3,5));"
->              "select g.g as g from generate_series(1,7) g(g)\n\
->              \where g.g not in (select generate_series.generate_series as generate_series\n\
->              \                  from generate_series(3,5) as generate_series(generate_series));"
->     ,Item [] "select g from generate_series(1,7) g\n\
->              \where g not in (select * from generate_series(3,5));"
->              "select g.g as g from generate_series(1,7) g(g)\n\
->              \where g.g not in (select generate_series.generate_series as generate_series\n\
->              \                  from generate_series(3,5) as generate_series(generate_series));"
->     ,Item [] "select g.* from generate_series(1,7) g\n\
->              \where g not in (select * from generate_series(3,5));"
->              "select g.g as g from generate_series(1,7) g(g)\n\
->              \where g.g not in (select generate_series.generate_series as generate_series\n\
->              \                  from generate_series(3,5) as generate_series(generate_series));"
-
->     ]
->   ,Group "select lists"
->     [Item db1 "select a,b,f(a),a::int,a+b,row_number() over (order by a), a as c from t;"
->               "select t.a as a,t.b as b,f(t.a) as f,t.a::int as \"int\",t.a+t.b as \"?column?\",row_number() over (order by t.a) as row_number, t.a as c from t as t(a,b);"
->     ]
->   ,Group "joins"
->     [Item db1 "select * from t natural inner join t1;"
->               "select t.a as a,t.b as b,t1.c as c \
->               \from t as t(a,b) natural inner join t1 as t1(a,c);"
->     ,Item db1 "select * from t inner join t1 using (a);"
->               "select t.a as a,t.b as b,t1.c as c \
->               \from t as t(a,b) inner join t1 as t1(a,c) using (a);"
->     ,Item db1 "select * from t cross join t1;"
->               "select t.a as a,t.b as b,t1.a as a,t1.c as c \
->               \from t as t(a,b) cross join t1 as t1(a,c);"
->     ,Item db1 "select t.* from t natural inner join t1;"
->               "select t.a as a,t.b as b \
->               \from t as t(a,b) natural inner join t1 as t1(a,c);"
->     ,Item db1 "select t1.* from t natural inner join t1;"
->               "select t1.a as a,t1.c as c \
->               \from t as t(a,b) natural inner join t1 as t1(a,c);"
->     ]
->   ,Group "dml"
->     [SItem db1 "update t set a = b where a = 5;"
->               "update t set a = t.b where t.a = 5;"
->     ,SItem db1 "delete from t where a = 0;"
->               "delete from t where t.a = 0;"]
->   ,Group "returning"
->     [SItem db1 "update t set a = 1 returning a;"
->                "update t set a = 1 returning t.a as a;"
->     ,SItem db1 "insert into t (a,b) values (1,2) returning a,b;"
->                "insert into t (a,b) values (1,2) returning t.a as a,t.b as b;"
->     ,SItem db1 "delete from t returning a;"
->                "delete from t returning t.a as a;"]
->   ]
-
-qualifier and column name the same
-
-
-> db1 :: [CatalogUpdate]
-> db1 = [CatCreateTable "t" [("a",typeInt)
->                           ,("b", typeInt)] []
->       ,CatCreateTable "u" [("c",typeInt)
->                           ,("d", typeInt)] []
->       ,CatCreateTable "v" [("v",typeInt)] []
->       ,CatCreateTable "t1" [("a",typeInt)
->                            ,("c", typeInt)] []
->       ]
-
-
-------------------------
-
-> itemToTft :: Item -> Test.Framework.Test
-> itemToTft (Group s is) = testGroup s $ map itemToTft is
-> itemToTft (Item eu sql esql) =
->   itemToTft' parseStatement eu sql esql
-> --itemToTft (MSItem eu sql esql) = itemToTft' parseSqlServerQueryExpr eu sql esql
-> itemToTft (SItem eu sql esql) = itemToTft' parseStatement eu sql esql
-
-> parseStatement :: String -> String -> Either ParseErrorExtra Statement
-> parseStatement f s =
->   let p = parseStatements f s
->   in case p of
->        Left e -> Left e
->        Right [a] -> Right a
->        Right _ -> error "wrong number of statements parsed"
-
-> type P = String -> String -> Either ParseErrorExtra Statement
-
-> itemToTft' :: P -> [CatalogUpdate] -> String -> String -> Test.Framework.Test
-> itemToTft' p eu sql esql = testCase sql $ do
->   let eAst = [case p "" esql of
->                              Left e -> error $ show e
->                              Right l -> resetAnnotations l]
->       ast = [case p "" sql of
->                            Left e -> error $ show e
->                            Right l -> resetAnnotations l]
->       cAst = fixUpIdentifiers makeCat ast
->       c2Ast = fixUpIdentifiers makeCat cAst
->   --putStrLn $ printStatements cAst ++ "\n" ++ printStatements c2Ast
->   when (eAst /= cAst) $ do
->     putStrLn $ "\nExpected:\n\n" ++ printStatements eAst
->     putStrLn $ "\nGot:\n\n" ++ printStatements cAst ++ "\n\n"
->   when (cAst /= c2Ast) $ do
->     putStrLn $ "\nREDO, Expected:\n\n" ++ printStatements cAst
->     putStrLn $ "\nGot:\n\n" ++ printStatements c2Ast ++ "\n\n"
->   assertEqual "" eAst cAst
->   assertEqual "redo" cAst c2Ast
->   where
->     makeCat = case updateCatalog defaultTemplate1Catalog eu of
->                         Left x -> error $ show x
->                         Right e -> e
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/ParameterizedStatementTests.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/ParameterizedStatementTests.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/ParameterizedStatementTests.lhs
+++ /dev/null
@@ -1,153 +0,0 @@
-
-Tests for the infrastructure to create type safe access to databases -
-the information needed is gathered during typechecking and exposed in
-the StatementType annotation, so these are really just a subset of the
-type checking tests.
-
-> module Database.HsSqlPpp.Tests.ParameterizedStatementTests (parameterizedStatementTests) where
->
-> import Test.HUnit
-> import Test.Framework
-> import Test.Framework.Providers.HUnit
-> --import Debug.Trace
-> import Data.Generics
-> import Data.Generics.Uniplate.Data
->
->
-> import Database.HsSqlPpp.Types
-> import Database.HsSqlPpp.Annotation
-> import Database.HsSqlPpp.Parser
-> import Database.HsSqlPpp.TypeChecker
-> import Database.HsSqlPpp.Catalog
->
-> data Item = Group String [Item]
->           | Statements [(String, [CatalogUpdate], Maybe ParameterizedStatementType)]
->
-> parameterizedStatementTests :: Test.Framework.Test
-> parameterizedStatementTests =
->   testGroup "parameterized statement tests" $ itemToTft testData
->
-> testData :: Item
-> testData =
->   Group "parameterized statement tests" [
->     Group "simple selects" [ Statements [
->        ("select test();"
->        ,[CatCreateFunction FunName "test" [] (Pseudo Void) False]
->        ,Just ([],[]))
->       ,("select adnum,adbin from pg_attrdef;"
->        ,[]
->        ,Just ([],[("adnum", ScalarType "int2")
->                  ,("adbin", ScalarType "pg_node_tree")]))
->       ,("select adnum,adbin from pg_attrdef where adnum= ?;"
->        ,[]
->        ,Just ([ScalarType "int2"],[("adnum", ScalarType "int2")
->                                   ,("adbin", ScalarType "pg_node_tree")]))
->       ,("select count(1) from pg_attrdef;"
->        ,[]
->        ,Just ([],[("count", ScalarType "int8")]))
->        {-,("select test($1);"
->        ,[CatCreateFunction FunName "test" [ScalarType "int4"] (ScalarType "text") False]
->        ,StatementType [ScalarType "int4"] [("test",ScalarType "text")])
->       ,-}
->       ,("select test(?);"
->        ,[CatCreateFunction FunName "test" [ScalarType "int4"] (ScalarType "text") False]
->        ,Just ([ScalarType "int4"],[("test",ScalarType "text")]))
->        ]
->     ]
->    ,Group "simple dml" [ Statements [
->        ("insert into testt values (1, 'test');"
->        ,[CatCreateTable "testt" [("c1", typeInt)
->                                 ,("c2", ScalarType "text")] []]
->        ,Just ([],[]))
->       ,("insert into testt (c1,c2) values (?, ?);"
->        ,[CatCreateTable "testt" [("c1", typeInt)
->                                 ,("c2", ScalarType "text")] []]
->        ,Just ([typeInt, ScalarType "text"],[]))
->       ,("insert into testt (c1,c2) values (1, 'test') returning c1;"
->        ,[CatCreateTable "testt" [("c1", typeInt)
->                                 ,("c2", ScalarType "text")] []]
->        ,Just ([],[("c1",typeInt)]))
->       ,("insert into testt (c1,c2) values (?, ?) returning c1 as d1, c2;"
->        ,[CatCreateTable "testt" [("c1", typeInt)
->                                 ,("c2", ScalarType "text")] []]
->        ,Just ([typeInt, ScalarType "text"],[("d1", typeInt)
->                                       ,("c2", ScalarType "text")]))
->       {-,("insert into testt (c1,c2) values (?, ?) returning *;"
->        ,[CatCreateTable "testt" [("c1", typeInt)
->                                 ,("c2", ScalarType "text")] []]
->        ,StatementType [typeInt, ScalarType "text"] [("c1", typeInt)
->                                                    ,("c2", ScalarType "text")])-}
->       ,("update testt set c1= ?,c2= ? where c1= ? returning c2;"
->        ,[CatCreateTable "testt" [("c1", typeInt)
->                                 ,("c2", ScalarType "text")] []]
->        ,Just ([typeInt, ScalarType "text", typeInt],[("c2", ScalarType "text")]))
->       ,("update testt set (c1,c2) = (?,?);"
->        ,[CatCreateTable "testt" [("c1", typeInt)
->                                 ,("c2", ScalarType "text")] []]
->        ,Just ([typeInt, ScalarType "text"],[]))
->       ,("delete from blah where c1= ? returning c2;"
->        ,[CatCreateTable "blah" [("c1", typeInt)
->                                 ,("c2", ScalarType "text")] []]
->        ,Just ([typeInt],[("c2", ScalarType "text")]))
->       ]
->     ]
->    ]
-
-~~~~
-
-select a,b from c where d=e group by f having  g=h orderby i limit j offset k;
-select function(a,b);
-insert into a (b,c) values (d,e) returning f,g
-update a set b=c,d=e where f=g returning h,i
-delete from t where a=b returning c,d
-
-rough list of grammar elements to possibly add inference support to:
-
-where top level - >maybeboolexpr
-having
-limit, offset
-values for table literal or insert
-set clause
-rowsetclause
-onexpr, joinon?
-windowfn
-liftoperator
-selectitem?
-castexpression
-caseexpression
-funcall
-inpredicate
-
-  TODO: add support in each of these places for position args only when
-        doing typecheckPS
-        do typecheck error if come across ? when not doing typecheckPS
-        make sure ? fails type check if not in a valid place in the ast
-~~~~
-
--------------------------------------------------------------------------------
-
-> testStatementType :: String -> [CatalogUpdate] -> Maybe ParameterizedStatementType -> Test.Framework.Test
-> testStatementType src eu st = testCase ("typecheck " ++ src) $
->   let ast = case parseStatements "" src of
->                                         Left e -> error $ show e
->                                         Right l -> l
->   in case typeCheckParameterizedStatement makeCat (head ast) of
->        Left e -> error $ show e
->        Right aast -> --trace (ppShow aast) $
->                      let is = getTopLevelInfo aast
->                          er = getTypeErrors aast
->                      in case is of
->                                 _ | not (null er) -> assertFailure $ show er
->                                 is1 -> assertEqual ("typecheck " ++ src) st is1
->                                 -- _ -> assertFailure ("expected onne statementinfo, got " ++ show is)
->   where
->     getTypeErrors :: Data a => a -> [TypeError]
->     getTypeErrors = universeBi
->     getTopLevelInfo a = stType $ getAnnotation a
->     makeCat = case updateCatalog defaultTemplate1Catalog eu of
->                         Left x -> error $ show x
->                         Right e -> e
->
-> itemToTft :: Item -> [Test.Framework.Test]
-> itemToTft (Statements es) = map (\(a,b,c) -> testStatementType a b c) es
-> itemToTft (Group s is) = [testGroup s $ concatMap itemToTft is]
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/CreateTable.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/CreateTable.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/CreateTable.lhs
+++ /dev/null
@@ -1,223 +0,0 @@
-
-> {-# LANGUAGE OverloadedStrings #-}
-> module Database.HsSqlPpp.Tests.Parsing.CreateTable (createTableParsingTestData) where
->
-> import Database.HsSqlPpp.Ast
-
-> import Database.HsSqlPpp.Tests.Parsing.Utils
-
-> createTableParsingTestData:: Item
-> createTableParsingTestData =
->   Group "create table" [
->      Group "simple tables" [
->       s "create table test (\n\
->         \  fielda text,\n\
->         \  fieldb int\n\
->         \);"
->       [CreateTable ea
->        (dqi "test")
->        [att "fielda" "text"
->        ,att "fieldb" "int"
->        ]
->        []]
->      ,s "create table tbl (\n\
->         \  fld boolean default false);"
->       [CreateTable ea (dqi "tbl")
->        [AttributeDef ea (Nmc "fld") (SimpleTypeName ea "boolean")
->                          (Just $ BooleanLit ea False) []][]]
->
->      ,s "create table tbl as select 1;"
->       [CreateTableAs ea (dqi "tbl")
->        (selectE (SelectList ea [SelExp ea (NumberLit ea "1")]))]
->
->      ,s "alter table a alter column b set default 1;"
->       [AlterTable ea (dqi "a") [AlterColumnDefault ea (Nmc "b") (NumberLit ea "1")]]
->
->      ,s "alter table a add constraint unique(b);"
->       [AlterTable ea (dqi "a") [AddConstraint ea (UniqueConstraint ea "" [Nmc "b"])]]
->      ]
->     ,Group "constraints" [
->       Group "nulls" [
->       s "create table t1 (\n\
->         \ a text null\n\
->         \);"
->         [CreateTable ea (dqi "t1") [AttributeDef ea (Nmc "a") (SimpleTypeName ea "text")
->                            Nothing [NullConstraint ea ""]]
->          []]
->      ,s "create table t1 (\n\
->         \ a text not null\n\
->         \);"
->         [CreateTable ea (dqi "t1") [AttributeDef ea (Nmc "a") (SimpleTypeName ea "text")
->                                                  Nothing [NotNullConstraint ea ""]]
->          []]
->      ]
->
->      ,Group "unique" [
->       s "create table t1 (\n\
->         \ x int,\n\
->         \ y int,\n\
->         \ unique (x,y)\n\
->         \);"
->         [CreateTable ea (dqi "t1") [att "x" "int"
->                                    ,att "y" "int"]
->          [UniqueConstraint ea "" [Nmc "x",Nmc "y"]]]
-
-test arbitrary ordering
-
->      ,s "create table t1 (\n\
->         \ x int,\n\
->         \ unique (x),\n\
->         \ y int\n\
->         \);"
->         [CreateTable ea (dqi "t1") [att "x" "int"
->                           ,att "y" "int"]
->          [UniqueConstraint ea "" [Nmc "x"]]]
-
-unique row
-
->      ,s "create table t1 (\n\
->         \ x int unique\n\
->         \);"
->         [CreateTable ea (dqi "t1")
->          [AttributeDef ea (Nmc "x") (SimpleTypeName ea "int") Nothing
->           [RowUniqueConstraint ea ""]][]]
->
->      ,s "create table t1 (\n\
->         \ x int unique not null\n\
->         \);"
->         [CreateTable ea (dqi "t1") [AttributeDef ea (Nmc "x") (SimpleTypeName ea "int") Nothing
->                            [RowUniqueConstraint ea ""
->                            ,NotNullConstraint ea ""]][]]
-
-quick sanity check
-
->      ,s "create table t1 (\n\
->         \ x int not null unique\n\
->         \);"
->         [CreateTable ea (dqi "t1") [AttributeDef ea (Nmc "x") (SimpleTypeName ea "int") Nothing
->                            [NotNullConstraint ea ""
->                            ,RowUniqueConstraint ea ""]][]]
->      ]
->
->      ,Group "primary key" [
->       s "create table t1 (\n\
->         \ x int primary key\n\
->         \);"
->         [CreateTable ea (dqi "t1") [AttributeDef ea (Nmc "x") (SimpleTypeName ea "int") Nothing
->                            [RowPrimaryKeyConstraint ea ""]][]]
->
->      ,s "create table t1 (\n\
->         \ x int,\n\
->         \ y int,\n\
->         \ primary key (x,y)\n\
->         \);"
->         [CreateTable ea (dqi "t1") [att "x" "int"
->                           ,att "y" "int"]
->          [PrimaryKeyConstraint ea "" [Nmc "x", Nmc "y"]]]
->      ]
->
->      ,Group "check" [
->       s "create table t (\n\
->         \f text check (f in('a', 'b'))\n\
->         \);"
->         [CreateTable ea (dqi "t")
->          [AttributeDef ea (Nmc "f") (SimpleTypeName ea "text") Nothing
->           [RowCheckConstraint ea "" (InPredicate ea
->                                   (Identifier ea "f") True
->                                   (InList ea [stringQ "a", stringQ "b"]))]] []]
->
->      ,s "create table t1 (\n\
->         \ x int,\n\
->         \ y int,\n\
->         \ check (x>y)\n\
->         \);"
->         [CreateTable ea (dqi "t1") [att "x" "int"
->                           ,att "y" "int"]
->          [CheckConstraint ea "" (FunCall ea (name ">") [Identifier ea "x", Identifier ea "y"])]]
->      ]
->
->      ,Group "misc" [
->       s "create table t (\n\
->         \f text not null unique check (f in('a', 'b'))\n\
->         \);"
->         [CreateTable ea (dqi "t")
->          [AttributeDef ea (Nmc "f") (SimpleTypeName ea "text") Nothing
->           [NotNullConstraint ea ""
->            ,RowUniqueConstraint ea ""
->            ,RowCheckConstraint ea "" (InPredicate ea
->                                    (Identifier ea "f") True
->                                    (InList ea [stringQ "a"
->                                               ,stringQ "b"]))]] []]
->      ]
-
->      ,Group "references" [
->       s "create table t1 (\n\
->         \ x int references t2\n\
->         \);"
->         [CreateTable ea (dqi "t1") [AttributeDef ea (Nmc "x") (SimpleTypeName ea "int") Nothing
->                            [RowReferenceConstraint ea "" (dqi "t2") Nothing
->                             Restrict Restrict]][]]
->
->      ,s "create table t1 (\n\
->         \ x int references t2(y)\n\
->         \);"
->         [CreateTable ea (dqi "t1") [AttributeDef ea (Nmc "x") (SimpleTypeName ea "int") Nothing
->                            [RowReferenceConstraint ea "" (dqi "t2") (Just $ Nmc "y")
->                             Restrict Restrict]][]]
->      ,s "create table t1 (\n\
->         \ x int,\n\
->         \ y int,\n\
->         \ foreign key (x,y) references t2\n\
->         \);"
->         [CreateTable ea (dqi "t1") [att "x" "int"
->                                    ,att "y" "int"]
->          [ReferenceConstraint ea "" [Nmc "x", Nmc "y"] (dqi "t2") []
->           Restrict Restrict]]
->
->      ,s "create table t1 (\n\
->         \ x int,\n\
->         \ y int,\n\
->         \ foreign key (x,y) references t2(z,w)\n\
->         \);"
->         [CreateTable ea (dqi "t1") [att "x" "int"
->                           ,att "y" "int"]
->          [ReferenceConstraint ea "" [Nmc "x", Nmc "y"] (dqi "t2") [Nmc "z", Nmc "w"]
->           Restrict Restrict]]
->
->      ,s "create table t1 (\n\
->         \ x int references t2 on delete cascade\n\
->         \);"
->         [CreateTable ea (dqi "t1") [AttributeDef ea (Nmc "x") (SimpleTypeName ea "int") Nothing
->                            [RowReferenceConstraint ea "" (dqi "t2") Nothing
->                             Cascade Restrict]][]]
->
->      ,s "create table t1 (\n\
->         \ x int references t2 on update cascade\n\
->         \);"
->         [CreateTable ea (dqi "t1") [AttributeDef ea (Nmc "x") (SimpleTypeName ea "int") Nothing
->                            [RowReferenceConstraint ea "" (dqi "t2") Nothing
->                             Restrict Cascade]][]]
->
->      ,s "create table t1 (\n\
->         \ x int references t2 on delete cascade on update cascade\n\
->         \);"
->         [CreateTable ea (dqi "t1") [AttributeDef ea (Nmc "x") (SimpleTypeName ea "int") Nothing
->                            [RowReferenceConstraint ea "" (dqi "t2") Nothing
->                             Cascade Cascade]][]]
->
->      ,s "create table t1 (\n\
->         \ x int,\n\
->         \ y int,\n\
->         \ foreign key (x,y) references t2 on update cascade on delete cascade\n\
->         \);"
->         [CreateTable ea (dqi "t1") [att "x" "int"
->                                    ,att "y" "int"]
->          [ReferenceConstraint ea "" [Nmc "x", Nmc "y"] (dqi "t2") []
->           Cascade Cascade]]
->
->      ]
->      ]
->      ]
-
->  where
->    s = Stmt
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Dml.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Dml.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Dml.lhs
+++ /dev/null
@@ -1,126 +0,0 @@
-
-> {-# LANGUAGE OverloadedStrings #-}
-> module Database.HsSqlPpp.Tests.Parsing.Dml (dmlParsingTestData) where
->
-> import Database.HsSqlPpp.Ast
-
-> import Database.HsSqlPpp.Tests.Parsing.Utils
-
-TODO:
-
-from in update, using in delete (+ type check these)
-
-> dmlParsingTestData:: Item
-> dmlParsingTestData =
->    Group "dml" [
->      Group "insert" [
->       s "insert into testtable\n\
->         \(columna,columnb)\n\
->         \values (1,2);\n"
->        [Insert ea
->         (dqi "testtable")
->         [Nmc "columna", Nmc "columnb"]
->         (Values ea [[NumberLit ea "1", NumberLit ea "2"]])
->         Nothing]
-
-multi row insert, test the stand alone values statement first, maybe
-that should be in the select section?
-
->      ,s "values (1,2), (3,4);"
->      [QueryStatement ea $ Values ea [[NumberLit ea "1", NumberLit ea "2"]
->              ,[NumberLit ea "3", NumberLit ea "4"]]]
->
->      ,s "insert into testtable\n\
->         \(columna,columnb)\n\
->         \values (1,2), (3,4);\n"
->       [Insert ea
->         (dqi "testtable")
->         [Nmc "columna", Nmc "columnb"]
->         (Values ea [[NumberLit ea "1", NumberLit ea "2"]
->                 ,[NumberLit ea "3", NumberLit ea "4"]])
->         Nothing]
-
-insert from select
-
->      ,s "insert into a\n\
->          \    select b from c;"
->       [Insert ea (dqi "a") []
->        (selectFrom [selI "b"] (Tref ea (i "c") (NoAlias ea)))
->        Nothing]
->
->      ,s "insert into testtable\n\
->         \(columna,columnb)\n\
->         \values (1,2) returning id;\n"
->       [Insert ea
->         (dqi "testtable")
->         [Nmc "columna", Nmc "columnb"]
->         (Values ea [[NumberLit ea "1", NumberLit ea "2"]])
->         (Just $ sl [selI "id"])]
->      ]
->
->     ,Group "update" [
->       s "update tb\n\
->         \  set x = 1, y = 2;"
->       [Update ea (dqi "tb") [SetClause ea (Nmc "x") $ NumberLit ea "1"
->                             ,SetClause ea (Nmc "y") $ NumberLit ea "2"]
->        [] Nothing Nothing]
->      ,s "update tb\n\
->         \  set x = 1, y = 2 where z = true;"
->       [Update ea (dqi "tb") [SetClause ea (Nmc "x") $ NumberLit ea "1"
->                             ,SetClause ea (Nmc "y") $ NumberLit ea "2"]
->        []
->        (Just $ FunCall ea (name "=")
->         [Identifier ea "z", BooleanLit ea True])
->        Nothing]
->      ,s "update tb\n\
->         \  set x = 1, y = 2 returning id;"
->       [Update ea (dqi "tb") [SetClause ea (Nmc "x") $ NumberLit ea "1"
->                             ,SetClause ea (Nmc "y") $ NumberLit ea "2"]
->        [] Nothing (Just $ sl [selI "id"])]
->      ,s "update tb\n\
->         \  set (x,y) = (1,2);"
->       [Update ea (dqi "tb")
->        [MultiSetClause ea [Nmc "x",Nmc "y"]
->         $ FunCall ea (name "!rowctor") [NumberLit ea "1"
->                                        ,NumberLit ea "2"]]
->        []
->        Nothing Nothing]
->      ]
-
-FunCall ea "=" [FunCall ea "!rowctor" [Identifier ea "x",Identifier ea "y"],FunCall ea "!rowctor" [NumberLit ea "1",NumberLit ea "2"]])
-
-
->
->     ,Group "delete" [
->       s "delete from tbl1 where x = true;"
->       [Delete ea (dqi "tbl1") [] (Just $ FunCall ea (name "=")
->                                [Identifier ea "x", BooleanLit ea True])
->        Nothing]
->      ,s "delete from tbl1 where x = true returning id;"
->       [Delete ea (dqi "tbl1") [] (Just $ FunCall ea (name "=")
->                                [Identifier ea "x", BooleanLit ea True])
->        (Just $ sl [selI "id"])]
->      ]
->
->     ,Group "truncate" [
->       s "truncate test;"
->        [Truncate ea [dqi "test"] ContinueIdentity Restrict]
->
->      ,s "truncate table test, test2 restart identity cascade;"
->        [Truncate ea [dqi "test",dqi "test2"] RestartIdentity Cascade]
->      ]
-
-copy, bit crap at the moment
-
->     ,Group "copy" [
->       s "copy tbl(a,b) from stdin;\n\
->         \bat\tt\n\
->         \bear\tf\n\
->         \\\.\n"
->       [Copy ea (dqi "tbl") [Nmc "a", Nmc "b"] Stdin
->        ,CopyData ea "\
->         \bat\tt\n\
->         \bear\tf\n"]
->      ]]
->  where
->    s = Stmt
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Expressions.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Expressions.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Expressions.lhs
+++ /dev/null
@@ -1,224 +0,0 @@
-
-> {-# LANGUAGE QuasiQuotes,OverloadedStrings #-}
->
-> module Database.HsSqlPpp.Tests.Parsing.Expressions (expressionParsingTestData) where
->
-> import Database.HsSqlPpp.Utils.Here
->
-> import Database.HsSqlPpp.Ast
-
-> import Database.HsSqlPpp.Tests.Parsing.Utils
-
-> expressionParsingTestData:: Item
-> expressionParsingTestData =
->    Group "parse expressions" [
->     Group "numbers" [
->       e "42" (num "42")
->      ,e "3.5" (num "3.5")
->      ,e "4." (num "4.")
->      ,e ".001" (num ".001")
->      ,e "5e2" (num "5e2")
->      ,e "1.925e-3" (num "1.925e-3")
-
->      ]
->    ,Group "basic expressions" [
->       e "1" (num "1")
->      ,e "-1" (funCall "u-" [num "1"])
->      ,e "1.1" (num "1.1")
->      ,e "-1.1" (funCall "u-" [num "1.1"])
->      ,e " 1 + 1 " (funCall "+" [num "1"
->                                ,num "1"])
->      ,e "1+1+1" (funCall "+" [funCall "+" [num "1"
->                                           ,num "1"]
->                              ,num "1"])
->      ]
->    ,Group "parens" [
-
-check some basic parens use wrt naked values and row constructors
-these tests reflect how pg seems to interpret the variants.
-
->       e "(1)" (num "1")
->      ,e "row ()" (funCall "!rowctor" [])
->      ,e "row (1)" (funCall "!rowctor" [num "1"])
->      ,e "row (1,2)" (funCall "!rowctor" [num "1",num "2"])
->      ,e "(1,2)" (funCall "!rowctor" [num "1",num "2"])
->      ]
->    ,Group "more basic expressions" [
-
-test some more really basic expressions
-
->       e "'test'" (stringQ "test")
->      ,e "''" (stringQ "")
->      ,e "hello" (ei "hello")
->      ,e "helloTest" (ei "helloTest")
->      ,e "hello_test" (ei "hello_test")
->      ,e "\"this is an identifier\""
->             (Identifier ea (QNmc "this is an identifier"))
->      ,e "hello1234" (ei "hello1234")
->      ,e "true" lTrue
->      ,e "false" lFalse
->      ,e "null" lNull
->      ]
->    ,Group "array ctor and selector" [
->       e "array[1,2]" (funCall "!arrayctor" [num "1", num "2"])
->      ,e "a[1]" (funCall "!arraysub" [ei "a", num "1"])
->      ]
->    ,Group "simple operators" [
->       e "1 + tst1" (funCall "+" [num "1"
->                                 ,ei "tst1"])
->      ,e "tst1 + 1" (funCall "+" [ei "tst1"
->                                 ,num "1"])
->      ,e "tst + tst1" (funCall "+" [ei "tst"
->                                   ,ei "tst1"])
->      ,e "'a' || 'b'" (funCall "||" [stringQ "a"
->                                    ,stringQ "b"])
->      ,e "'stuff'::text"
->       (Cast ea (stringQ "stuff") (SimpleTypeName ea "text"))
->      ,e "245::float(24)" (Cast ea (num "245") (PrecTypeName ea "float" 24))
->      ,e "245.1::numeric(5,3)"
->       (Cast ea (num "245.1") (Prec2TypeName ea "numeric" 5 3))
->      ,e "245::double precision"
->       (Cast ea (num "245") (SimpleTypeName ea "double precision"))
->      ,e "date '1998-12-01'"
->       (TypedStringLit ea (SimpleTypeName ea "date") "1998-12-01")
->      ,e "interval '63' day" (Interval ea "63" IntervalDay Nothing)
->      ,e "interval '63' day (3)" (Interval ea "63" IntervalDay $ Just 3)
->      ,e "extract(year from a)" (Extract ea ExtractYear $ ei "a")
->      ,e "a between 1 and 3"
->         (funCall "!between" [ei "a", num "1", num "3"])
->      ,e "a between 7 - 1 and 7 + 1"
->         (funCall "!between" [ei "a"
->                             ,funCall "-" [num "7"
->                                          ,num "1"]
->                             ,funCall "+" [num "7"
->                                          ,num "1"]])
->      ,e "cast(a as text)"
->         (Cast ea (ei "a") (SimpleTypeName ea "text"))
->      ,e "@ a"
->         (funCall "@" [ei "a"])
->      ,e "substring(a from 0 for 3)"
->         (funCall "!substring" [ei "a", num "0", num "3"])
->      ,e "substring(a from 0 for (5 - 3))"
->         (funCall "!substring" [ei "a"
->                               ,num "0"
->                               ,funCall "-" [num "5",num "3"]])
->      ,e "substring(a,b,c)"
->         (funCall "substring" [ei "a"
->                              ,ei "b"
->                              ,ei "c"])
->      ,e "a like b"
->         (funCall "!like" [ei "a", ei "b"])
->      ,e "a not like b"
->         (funCall "!notlike" [ei "a", ei "b"])
->      , e "a and b and c and d"
->         (funCall "!and"
->          [funCall "!and"
->           [funCall "!and" [ei "a"
->                           ,ei "b"]
->           ,ei "c"]
->          ,ei "d"])
->      ]
->    ,Group "function calls" [
->       e "fn()" (funCall "fn" [])
->      ,e "fn(1)" (funCall "fn" [num "1"])
->      ,e "fn('test')" (funCall "fn" [stringQ "test"])
->      ,e "fn(1,'test')" (funCall "fn" [num "1", stringQ "test"])
->      ,e "fn('test')" (funCall "fn" [stringQ "test"])
->      ]
->    ,Group "simple whitespace sanity checks" [
->       e "fn (1)" (funCall "fn" [num "1"])
->      ,e "fn( 1)" (funCall "fn" [num "1"])
->      ,e "fn(1 )" (funCall "fn" [num "1"])
->      ,e "fn(1) " (funCall "fn" [num "1"])
->      ]
->    ,Group "null stuff" [
->       e "not null" (funCall "!not" [lNull])
->      ,e "a is null" (funCall "!isnull" [ei "a"])
->      ,e "a is not null" (funCall "!isnotnull" [ei "a"])
->      ,e "not not true" (funCall "!not"
->                          [funCall "!not"
->                           [lTrue]])
->      ]
-
->    ,Group "case expressions" [
->       e [here|
->          case when a,b then 3
->               when c then 4
->               else 5
->          end
->          |]
->         (Case ea [([ei "a", ei "b"], num "3")
->                  ,([ei "c"], num "4")]
->          (Just $ num "5"))
->      ,e  "case 1 when 2 then 3 else 4 end"
->         (CaseSimple ea (num "1")
->          [([num "2"], num "3")]
->          (Just $ num "4"))
->      ]
->    ,Group "positional args" [
->       e "$1" (PositionalArg ea 1)
->      ,e "?" (Placeholder ea)
->      ,e "a = ?" (funCall "=" [ei "a",Placeholder ea])
->      ]
->    ,Group "exists" [
->       e "exists (select 1 from a)"
->       (Exists ea (selectFrom [SelExp ea (num "1")]
->                   (Tref ea (i "a") (NoAlias ea))))
->      ]
->    ,Group "in variants" [
->       e "t in (1,2)"
->       (InPredicate ea (ei "t") True (InList ea [num "1",num "2"]))
->      ,e "t not in (1,2)"
->       (InPredicate ea (ei "t") False (InList ea [num "1",num "2"]))
->      ,e "(t,u) in (1,2)"
->       (InPredicate ea (funCall "!rowctor" [ei "t",ei "u"]) True
->        (InList ea [num "1",num "2"]))
->      ,e "3 = any (array[1,2])"
->       (LiftOperator ea "=" LiftAny [num "3"
->                                    ,funCall "!arrayctor" [num "1"
->                                                          ,num "2"]])
->      ,e "3 = all (array[1,2,4])"
->       (LiftOperator ea "=" LiftAll [num "3"
->                                    ,funCall "!arrayctor" [num "1"
->                                                          ,num "2"
->                                                          ,num "4"]])
->      ]
->    ,Group "comparison operators" [
->       e "a < b"
->       (funCall "<" [ei "a", ei "b"])
->      ,e "a <> b"
->       (funCall "<>" [ei "a", ei "b"])
->      ,e "a != b"
->       (funCall "<>" [ei "a", ei "b"])
->      ]
-
-test some string parsing, want to check single quote behaviour,
-and dollar quoting, including nesting.
-
->    ,Group "string parsing" [
->       e "''" (stringQ "")
->      ,e "''''" (stringQ "'")
->      ,e "'test'''" (stringQ "test'")
->      ,e "'''test'" (stringQ "'test")
->      ,e "'te''st'" (stringQ "te'st")
->      ,e "$$test$$" (StringLit ea "test")
->      ,e "$$te'st$$" (StringLit ea "te'st")
->      ,e "$st$test$st$" (StringLit ea "test")
->      ,e "$outer$te$$yup$$st$outer$" (StringLit ea "te$$yup$$st")
->      ,e "'spl$$it'" (stringQ "spl$$it")
->      ]
->    ,Group "bracketed things" [
->       e "(p).x" (eqi "p" "x")
->      ,e "(select f(((a).x, y)::z))"
->         (ScalarSubQuery ea
->          (selectE (sl
->                    [SelExp ea
->                     (funCall "f" [Cast ea
->                                   (funCall "!rowctor"
->                                    [eqi "a" "x"
->                                    ,ei "y"])
->                                   (SimpleTypeName ea "z")])])))
->      ]
->      ]
->  where
->    e = Expr
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/FunctionsDdl.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/FunctionsDdl.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/FunctionsDdl.lhs
+++ /dev/null
@@ -1,146 +0,0 @@
-
-
-> {-# LANGUAGE OverloadedStrings #-}
-> module Database.HsSqlPpp.Tests.Parsing.FunctionsDdl (functionsDdlParsingTestData) where
->
-> import Database.HsSqlPpp.Ast
-
-> import Database.HsSqlPpp.Tests.Parsing.Utils
-
-> functionsDdlParsingTestData:: Item
-> functionsDdlParsingTestData =
->    Group "functionsddl" [
->      Group "basics" [
->       s "create function t1(text) returns text as $$\n\
->         \select a from t1 where b = $1;\n\
->         \$$ language sql stable;"
->       [CreateFunction ea (dqi "t1") [ParamDefTp ea $ SimpleTypeName ea "text"]
->        (SimpleTypeName ea "text") NoReplace Sql
->        (SqlFnBody ea
->         [QueryStatement ea $ selectFromWhere [SelExp ea (Identifier ea "a")] (Tref ea (i "t1") (NoAlias ea))
->          (FunCall ea (name "=")
->           [Identifier ea "b", PositionalArg ea 1])])
->        Stable]
->      ,s "create function fn() returns void as $$\n\
->         \declare\n\
->         \  a int;\n\
->         \  b text;\n\
->         \begin\n\
->         \  null;\n\
->         \end;\n\
->         \$$ language plpgsql volatile;"
->       [CreateFunction ea (dqi "fn") [] (SimpleTypeName ea "void") NoReplace Plpgsql
->        (PlpgsqlFnBody ea (Block ea Nothing [VarDef ea (Nmc "a") (SimpleTypeName ea "int") Nothing
->                                            ,VarDef ea (Nmc "b") (SimpleTypeName ea "text") Nothing]
->                           [NullStatement ea]))
->        Volatile]
->      ,s "create function fn() returns void as $$\n\
->         \declare\n\
->         \  a int;\n\
->         \  b text;\n\
->         \begin\n\
->         \  null;\n\
->         \end;\n\
->         \$$ language plpgsql volatile;"
->       [CreateFunction ea (dqi "fn") [] (SimpleTypeName ea "void") NoReplace Plpgsql
->        (PlpgsqlFnBody ea
->         (Block ea Nothing [VarDef ea (Nmc "a") (SimpleTypeName ea "int") Nothing
->                           ,VarDef ea (Nmc "b") (SimpleTypeName ea "text") Nothing]
->         [NullStatement ea]))
->        Volatile]
->      ,s "create function fn(a text[]) returns int[] as $$\n\
->         \declare\n\
->         \  b xtype[] := '{}';\n\
->         \begin\n\
->         \  null;\n\
->         \end;\n\
->         \$$ language plpgsql immutable;"
->       [CreateFunction ea (dqi "fn")
->        [ParamDef ea (Nmc "a") $ ArrayTypeName ea $ SimpleTypeName ea "text"]
->        (ArrayTypeName ea $ SimpleTypeName ea "int") NoReplace Plpgsql
->        (PlpgsqlFnBody ea
->         (Block ea Nothing
->          [VarDef ea (Nmc "b") (ArrayTypeName ea $ SimpleTypeName ea "xtype") (Just $ stringQ "{}")]
->          [NullStatement ea]))
->        Immutable]
->      ,s "create function fn() returns void as '\n\
->         \declare\n\
->         \  a int := 3;\n\
->         \begin\n\
->         \  null;\n\
->         \end;\n\
->         \' language plpgsql stable;"
->       [CreateFunction ea (dqi "fn") [] (SimpleTypeName ea "void") NoReplace Plpgsql
->        (PlpgsqlFnBody ea
->         (Block ea Nothing
->          [VarDef ea (Nmc "a") (SimpleTypeName ea "int") (Just $ NumberLit ea "3")]
->          [NullStatement ea]))
->        Stable]
->      ,s "create function fn(int) returns void as '\n\
->         \declare\n\
->         \  a alias for $1;\n\
->         \begin\n\
->         \  null;\n\
->         \end;\n\
->         \' language plpgsql stable;"
->       [CreateFunction ea (dqi "fn")
->        [ParamDefTp ea $ SimpleTypeName ea "int"]
->        (SimpleTypeName ea "void") NoReplace Plpgsql
->        (PlpgsqlFnBody ea
->         (Block ea Nothing
->          [ParamAlias ea (Nmc "a") 1]
->          [NullStatement ea]))
->        Stable]
->      ,s "create function fn(b int) returns void as '\n\
->         \declare\n\
->         \  a alias for b;\n\
->         \begin\n\
->         \  null;\n\
->         \end;\n\
->         \' language plpgsql stable;"
->       [CreateFunction ea (dqi "fn")
->        [ParamDef ea (Nmc "b") $ SimpleTypeName ea "int"]
->        (SimpleTypeName ea "void") NoReplace Plpgsql
->        (PlpgsqlFnBody ea
->         (Block ea Nothing
->          [VarAlias ea (Nmc "a") (dqi "b")]
->          [NullStatement ea]))
->        Stable]
->      ,s "create function fn() returns setof int as $$\n\
->         \begin\n\
->         \  null;\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->       [CreateFunction ea (dqi "fn") []
->        (SetOfTypeName ea $ SimpleTypeName ea "int") NoReplace Plpgsql
->        (PlpgsqlFnBody ea (Block ea Nothing [] [NullStatement ea]))
->        Stable]
->      ,s "create function fn() returns void as $$\n\
->         \begin\n\
->         \  null;\n\
->         \end\n\
->         \$$ language plpgsql stable;"
->       [CreateFunction ea (dqi "fn") []
->        (SimpleTypeName ea "void") NoReplace Plpgsql
->        (PlpgsqlFnBody ea (Block ea Nothing [] [NullStatement ea]))
->        Stable]
->      ,s "create or replace function fn() returns void as $$\n\
->         \begin\n\
->         \  null;\n\
->         \end\n\
->         \$$ language plpgsql stable;"
->       [CreateFunction ea (dqi "fn") []
->        (SimpleTypeName ea "void") Replace Plpgsql
->        (PlpgsqlFnBody ea (Block ea Nothing [] [NullStatement ea]))
->        Stable]
->      ,s "drop function test(text);"
->       [DropFunction ea Require [(dqi "test",[SimpleTypeName ea "text"])] Restrict]
->      ,s "drop function test(int,int);"
->       [DropFunction ea Require [(dqi "test",[SimpleTypeName ea "int"
->                                             ,SimpleTypeName ea "int"])] Restrict]
->      ,s "drop function if exists a(),test(text) cascade;"
->       [DropFunction ea IfExists [(dqi "a",[])
->                                 ,(dqi "test",[SimpleTypeName ea "text"])] Cascade]
->     ]]
->  where
->    s = Stmt
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Misc.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Misc.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Misc.lhs
+++ /dev/null
@@ -1,63 +0,0 @@
-
-The automated tests, uses hunit to check a bunch of text expressions
-and sql statements parse to the correct tree, and then checks pretty
-printing and then reparsing gives the same tree. The code was mostly
-written almost in tdd style, which the order/ coverage of these tests
-reflects.
-
-There are no tests for invalid syntax at the moment.
-
-> module Database.HsSqlPpp.Tests.Parsing.Misc (miscParserTestData) where
->
-> import Database.HsSqlPpp.Ast
-
-> import Database.HsSqlPpp.Tests.Parsing.Utils
->
-> miscParserTestData :: Item
-> miscParserTestData =
->   Group "miscParserTests" [
-
->     Group "multiple statements" [
->       s "select 1;\nselect 2;" [QueryStatement ea $ selectE $ sl [SelExp ea (NumberLit ea "1")]
->                                ,QueryStatement ea $ selectE $ sl [SelExp ea (NumberLit ea "2")]]
->      ]
->    ,Group "comments" [
->       s "" []
->      ,s "-- this is a test" []
->      ,s "/* this is\n\
->         \a test*/" []
->      ,s "select 1;\n\
->         \-- this is a test\n\
->         \select -- this is a test\n\
->         \2;" [QueryStatement ea $ selectE $ sl [SelExp ea (NumberLit ea "1")]
->              ,QueryStatement ea $ selectE $ sl [SelExp ea (NumberLit ea "2")]
->              ]
->      ,s "select 1;\n\
->         \/* this is\n\
->         \a test*/\n\
->         \select /* this is a test*/2;"
->                     [QueryStatement ea $ selectE $ sl [SelExp ea (NumberLit ea "1")]
->                     ,QueryStatement ea $ selectE $ sl [SelExp ea (NumberLit ea "2")]
->                     ]
->      ]
-
---------------------------------------------------------------------------------
-
-ddl statements
-
-
->    ,Group "misc" [
->       s "SET search_path TO my_schema, public;"
->         [Set ea "search_path" [SetId ea "my_schema"
->                               ,SetId ea "public"]]
->      ,s "SET t1 = 3;"
->         [Set ea "t1" [SetNum ea 3]]
->      ,s "SET t1 = 'stuff';"
->         [Set ea "t1" [SetStr ea "stuff"]]
->      ,s "create language plpgsql;"
->         [CreateLanguage ea "plpgsql"]
->
->     ]
->     ]
->  where
->    s = Stmt
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/MiscDdl.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/MiscDdl.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/MiscDdl.lhs
+++ /dev/null
@@ -1,63 +0,0 @@
-
-> {-# LANGUAGE OverloadedStrings #-}
-> module Database.HsSqlPpp.Tests.Parsing.MiscDdl (miscDdlParsingTestData) where
->
-> import Database.HsSqlPpp.Ast
-
-> import Database.HsSqlPpp.Tests.Parsing.Utils
-
-> miscDdlParsingTestData:: Item
-> miscDdlParsingTestData =
->   Group "misc ddl" [
->     Group "misc create" [
->       s "create view v1 as\n\
->         \select a,b from t;"
->       [CreateView ea
->        (dqi "v1") Nothing
->        (selectFrom [selI "a", selI "b"] (Tref ea (i "t") (NoAlias ea)))]
->      ,s "create view v1(c,d) as\n\
->         \select a,b from t;"
->       [CreateView ea
->        (dqi "v1") (Just [Nmc "c",Nmc "d"])
->        (selectFrom [selI "a", selI "b"] (Tref ea (i "t") (NoAlias ea)))]
->      ,s "create domain td as text check (value in ('t1', 't2'));"
->       [CreateDomain ea (dqi "td") (SimpleTypeName ea "text") ""
->        (Just (InPredicate ea (Identifier ea "value") True
->               (InList ea [stringQ "t1" ,stringQ "t2"])))]
->      ,s "create type tp1 as (\n\
->         \  f1 text,\n\
->         \  f2 text\n\
->         \);"
->       [CreateType ea (dqi "tp1") [TypeAttDef ea (Nmc "f1") (SimpleTypeName ea "text")
->                                  ,TypeAttDef ea (Nmc "f2") (SimpleTypeName ea "text")]]
->
->      ,s "create sequence s start with 5 increment by 4 no maxvalue no minvalue cache 1;"
->         [CreateSequence ea (dqi "s") 4 1 ((2::Integer) ^ (63::Integer) - 1) 5 1]
->
->      ,s "alter sequence s owned by a.b;"
->         [AlterSequence ea (dqi "s") $ qi "a" "b"]
->
->      ,s "create trigger tr\n\
->          \after insert or delete on tb\n\
->          \for each statement\n\
->          \execute procedure fb();"
->         [CreateTrigger ea (Nmc "tr") TriggerAfter [TInsert,TDelete] (dqi "tb") EachStatement (dqi "fb") []]
->      ]
->
->     ,Group "drops" [
->       s "drop domain t;"
->       [DropSomething ea Domain Require [dqi "t"] Restrict]
->      ,s "drop domain if exists t,u cascade;"
->       [DropSomething ea Domain IfExists [dqi "t", dqi "u"] Cascade]
->      ,s "drop domain t restrict;"
->       [DropSomething ea Domain Require [dqi "t"] Restrict]
->
->      ,s "drop type t;"
->       [DropSomething ea Type Require [dqi "t"] Restrict]
->      ,s "drop table t;"
->       [DropSomething ea Table Require [dqi "t"] Restrict]
->      ,s "drop view t;"
->       [DropSomething ea View Require [dqi "t"] Restrict]
->      ]]
->  where
->    s = Stmt
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/ParserTests.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/ParserTests.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/ParserTests.lhs
+++ /dev/null
@@ -1,112 +0,0 @@
-
-The automated tests, uses hunit to check a bunch of text expressions
-and sql statements parse to the correct tree, and then checks pretty
-printing and then reparsing gives the same tree. The code was mostly
-written almost in tdd style, which the order/ coverage of these tests
-reflects.
-
-There are no tests for invalid syntax at the moment.
-
-> module Database.HsSqlPpp.Tests.Parsing.ParserTests
->     (parserTests
->     ,parserTestData
->     ,Item(..)
->     ) where
->
-> import Test.HUnit
-> import Test.Framework
-> import Test.Framework.Providers.HUnit
-> import Data.Generics
->
-> import Database.HsSqlPpp.Ast
-> --import Database.HsSqlPpp.Annotation
-> import Database.HsSqlPpp.Parser
-> import Database.HsSqlPpp.Pretty
->
-
-> import Database.HsSqlPpp.Tests.Parsing.Utils
-> import Database.HsSqlPpp.Tests.Parsing.Expressions
-> import Database.HsSqlPpp.Tests.Parsing.Selects
-> import Database.HsSqlPpp.Tests.Parsing.Dml
-> import Database.HsSqlPpp.Tests.Parsing.CreateTable
-> import Database.HsSqlPpp.Tests.Parsing.MiscDdl
-> import Database.HsSqlPpp.Tests.Parsing.FunctionsDdl
-> import Database.HsSqlPpp.Tests.Parsing.Plpgsql
-> import Database.HsSqlPpp.Tests.Parsing.Misc
-
-> import Database.HsSqlPpp.Tests.TestUtils
-
-> parserTests :: Test.Framework.Test
-> parserTests = itemToTft parserTestData
->
-> parserTestData :: Item
-> parserTestData =
->   Group "parserTests" [
->              expressionParsingTestData
->             ,selectParsingTestData
->             ,dmlParsingTestData
->             ,Group "ddl" [createTableParsingTestData
->                          ,miscDdlParsingTestData
->                          ,functionsDdlParsingTestData]
->             ,pgplsqlParsingTestData
->             ,miscParserTestData
->             ]
-
---------------------------------------------------------------------------------
-
-Unit test helpers
-
-> itemToTft :: Item -> Test.Framework.Test
-> itemToTft (Expr a b) = testParseScalarExpr a b
-> itemToTft (PgSqlStmt a b) = testParsePlpgsqlStatements a b
-> itemToTft (Stmt a b) = testParseStatements a b
-> --itemToTft (MSStmt a b) = testParseStatements a b
-> itemToTft (Group s is) = testGroup s $ map itemToTft is
->
-> testParseScalarExpr :: String -> ScalarExpr -> Test.Framework.Test
-> testParseScalarExpr src ast =
->   parseUtil src ast (parseScalarExpr "") (parseScalarExpr "") printScalarExpr
->
-> testParseStatements :: String -> [Statement] -> Test.Framework.Test
-> testParseStatements src ast =
->   parseUtil src ast (parseStatements "") (parseStatements "") printStatements
->
-> {-testParseMSStatements :: String -> [Statement] -> Test.Framework.Test
-> testParseMSStatements src ast =
->   parseUtil src ast parseMsQuery (parseStatements "") printStatements
->   where
->     parseMsQuery :: String -> Either ParseErrorExtra [Statement]
->     parseMsQuery s =
->       (\p' -> [QueryStatement ea p'])
->       `fmap` parseSqlServerQueryExpr "" s-}
-
->
-> testParsePlpgsqlStatements :: String -> [Statement] -> Test.Framework.Test
-> testParsePlpgsqlStatements src ast =
->   parseUtil src ast (parsePlpgsql "") (parsePlpgsql "") printStatements
->
-> parseUtil :: (Show t, Eq b, Show b, Data b) =>
->              String
->           -> b
->           -> (String -> Either t b)
->           -> (String -> Either t b)
->           -> (b -> String)
->           -> Test.Framework.Test
-> parseUtil src ast parser reparser printer = testCase ("parse " ++ src) $
->   case parser src of
->     Left er -> assertFailure $ show er
->     Right ast' -> do
->       assertEqual ("parse " ++ src) ast $ resetAnnotations ast'
->       case reparser (printer ast) of
->         Left er -> assertFailure $ "reparse\n" ++ show er ++ "\n" -- ++ pp ++ "\n"
->         Right ast'' -> assertEqual ("reparse " ++ printer ast) ast $ resetAnnotations ast''
-
-~~~~
-TODO
-new idea for testing:
-parsesql -> ast1
-parse, pretty print, parse -> ast2
-load into pg, pg_dump, parse -> ast3
-parse, pretty print, load into pg, pg_dump, parse -> ast4
-check all these asts are the same
-~~~~
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Plpgsql.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Plpgsql.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Plpgsql.lhs
+++ /dev/null
@@ -1,152 +0,0 @@
-
-
-> {-# LANGUAGE OverloadedStrings #-}
-> module Database.HsSqlPpp.Tests.Parsing.Plpgsql (pgplsqlParsingTestData) where
->
-> import Database.HsSqlPpp.Ast
-
-> import Database.HsSqlPpp.Tests.Parsing.Utils
-
-> pgplsqlParsingTestData:: Item
-> pgplsqlParsingTestData =
->   Group "plpgsql" [
->     Group "simple plpgsql statements" [
->       f "success := true;"
->       [Assignment ea (Name ea ["success"]) (BooleanLit ea True)]
->      ,f "success = true;"
->       [Assignment ea (Name ea ["success"]) (BooleanLit ea True)]
->      ,f "return true;"
->       [Return ea $ Just (BooleanLit ea True)]
->      ,f "return;"
->       [Return ea Nothing]
->      ,f "return next 1;"
->       [ReturnNext ea $ NumberLit ea "1"]
->      ,f "return query select a from b;"
->       [ReturnQuery ea $ selectFrom [selI "a"] (Tref ea (i "b") (NoAlias ea))]
->      ,f "raise notice 'stuff %', 1;"
->       [Raise ea RNotice "stuff %" [NumberLit ea "1"]]
->      ,f "perform test();"
->       [Perform ea $ FunCall ea (name "test") []]
->      ,f "perform test(a,b);"
->       [Perform ea $ FunCall ea (name "test") [Identifier ea "a", Identifier ea "b"]]
->      ,f "perform test(r.relvar_name || '_and_stuff');"
->       [Perform ea $ FunCall ea (name "test") [
->                     FunCall ea (name "||") [eqi "r" "relvar_name"
->                                     ,stringQ "_and_stuff"]]]
->      ,f "select into a,b c,d from e;"
->       [Into ea False [name "a", name "b"]
->        $ QueryStatement ea $ Select ea Dupes (SelectList ea [selI "c", selI "d"])
->              [Tref ea (i "e") (NoAlias ea)] Nothing [] Nothing [] Nothing Nothing]
->      ,f "select c,d into a,b from e;"
->       [Into ea False [name "a", name "b"]
->        $ QueryStatement ea $ Select ea Dupes (SelectList ea [selI "c", selI "d"])
->          [Tref ea (i "e") (NoAlias ea)] Nothing [] Nothing [] Nothing Nothing]
->      ,f "delete from pieces where x = 1 and y = 1 returning tag into r.tag;"
->       [Into ea False [Name ea [Nmc "r",Nmc "tag"]]
->        $ Delete ea (dqi "pieces") []
->          (Just $ funCall "!and" [funCall "=" [ei "x",num "1"]
->                                 ,funCall "=" [ei "y",num "1"]])
->          (Just $ sl [selI "tag"])]
->      ,f "update pieces\n\
->         \set a=b returning tag into r.tag;"
->       [Into ea False [Name ea [Nmc "r",Nmc "tag"]]
->          $ Update ea (dqi "pieces")
->              [SetClause ea (Nmc "a") $ Identifier ea "b"]
->            []
->            Nothing (Just (SelectList ea
->                           [SelExp ea (Identifier ea "tag")]))]
->      ,f "insert into t(a) values (1) returning id into x;"
->       [Into ea False [Name ea [Nmc "x"]]
->        $ Insert ea
->         (dqi "t")
->         [Nmc "a"]
->         (Values ea [[NumberLit ea "1"]])
->         (Just $ sl [selI "id"])]
-
->      ,f "update t\n\
->         \  set x = 1 returning id into z;"
->       [Into ea False [Name ea [Nmc "z"]]
->       $ Update ea (dqi "t") [SetClause ea (Nmc "x") $ NumberLit ea "1"]
->         [] Nothing (Just $ sl [selI "id"])]
-
->      ,f "execute s;"
->       [Execute ea (Identifier ea "s")]
->      ,f "execute s into r;"
->       [Into ea False [Name ea [Nmc "r"]] (Execute ea (Identifier ea "s"))]
->     ,f "continue;" [ContinueStatement ea Nothing]
->     ]
->
->     ,Group "other plpgsql statements" [
->       f "for r in select a from tbl loop\n\
->         \null;\n\
->         \end loop;"
->       [ForQueryStatement ea Nothing (Nmc "r") (selectFrom  [selI "a"] (Tref ea (i "tbl") (NoAlias ea)))
->        [NullStatement ea]]
->      ,f "for r in select a from tbl where true loop\n\
->         \null;\n\
->         \end loop;"
->       [ForQueryStatement ea Nothing (Nmc "r")
->        (selectFromWhere [selI "a"] (Tref ea (i "tbl") (NoAlias ea)) (BooleanLit ea True))
->        [NullStatement ea]]
->      ,f "for r in 1 .. 10 loop\n\
->         \null;\n\
->         \end loop;"
->       [ForIntegerStatement ea Nothing (Nmc "r")
->        (NumberLit ea "1") (NumberLit ea "10")
->        [NullStatement ea]]
->       -- catch a bug in lexing where 1..10 is parsed as
->       -- num "1.", num ".10", instead of num 1, symbol "..", num 10
->      ,f "for r in 1..10 loop\n\
->         \null;\n\
->         \end loop;"
->       [ForIntegerStatement ea Nothing (Nmc "r")
->        (NumberLit ea "1") (NumberLit ea "10")
->        [NullStatement ea]]
->
->      ,f "if a=b then\n\
->         \  update c set d = e;\n\
->         \end if;"
->       [If ea [(FunCall ea (name "=") [ei "a", ei "b"]
->               ,[Update ea (dqi "c") [SetClause ea (Nmc "d")
->                                     $ ei "e"] [] Nothing Nothing])]
->        []]
->      ,f "if true then\n\
->         \  null;\n\
->         \else\n\
->         \  null;\n\
->         \end if;"
->       [If ea [(BooleanLit ea True,[NullStatement ea])]
->        [NullStatement ea]]
->      ,f "if true then\n\
->         \  null;\n\
->         \elseif false then\n\
->         \  return;\n\
->         \end if;"
->       [If ea [(BooleanLit ea True, [NullStatement ea])
->              ,(BooleanLit ea False, [Return ea Nothing])]
->        []]
->      ,f "if true then\n\
->         \  null;\n\
->         \elseif false then\n\
->         \  return;\n\
->         \elsif false then\n\
->         \  return;\n\
->         \else\n\
->         \  return;\n\
->         \end if;"
->       [If ea [(BooleanLit ea True, [NullStatement ea])
->              ,(BooleanLit ea False, [Return ea Nothing])
->              ,(BooleanLit ea False, [Return ea Nothing])]
->        [Return ea Nothing]]
->      ,f "case a\n\
->         \  when b then null;\n\
->         \  when c,d then null;\n\
->         \  else null;\n\
->         \end case;"
->      [CaseStatementSimple ea (Identifier ea "a")
->       [([Identifier ea "b"], [NullStatement ea])
->       ,([Identifier ea "c", Identifier ea "d"], [NullStatement ea])]
->       [NullStatement ea]]
->     ]]
->  where
->    f = PgSqlStmt
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Selects.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Selects.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Selects.lhs
+++ /dev/null
@@ -1,434 +0,0 @@
-
-> {-# LANGUAGE QuasiQuotes,OverloadedStrings #-}
->
-> module Database.HsSqlPpp.Tests.Parsing.Selects (selectParsingTestData) where
->
-> import Database.HsSqlPpp.Utils.Here
->
-> import Database.HsSqlPpp.Ast
-
-> import Database.HsSqlPpp.Tests.Parsing.Utils
-
-> selectParsingTestData:: Item
-> selectParsingTestData =
->    Group "parse selects" [
->    Group "simple select statements" [
->     Group "select no table" [
->       s "select 1;" [QueryStatement ea $ selectE (SelectList ea [SelExp ea (NumberLit ea "1")])]
->      ]
->    ,Group "select from table" [
->       s "select * from tbl;"
->       [QueryStatement ea $ selectFrom (selEL [Star ea]) (Tref ea (i "tbl") (NoAlias ea))]
->      ,s "select a,b from tbl;"
->       [QueryStatement ea $ selectFrom (selIL ["a", "b"]) (Tref ea (i "tbl") (NoAlias ea))]
->      ,s "select a,b from inf.tbl;"
->       [QueryStatement ea $ selectFrom (selIL ["a", "b"]) (Tref ea (qi "inf" "tbl") (NoAlias ea))]
->      ,s "select distinct * from tbl;"
->       [QueryStatement ea $ Select ea Distinct (SelectList ea (selEL [Star ea])) [Tref ea (i "tbl") (NoAlias ea)]
->        Nothing [] Nothing [] Nothing Nothing]
->      ,s "select a from tbl where b=2;"
->       [QueryStatement ea $ selectFromWhere
->         (selIL ["a"])
->         (Tref ea (i "tbl") (NoAlias ea))
->         (FunCall ea (name "=")
->          [Identifier ea "b", NumberLit ea "2"])]
->      ,s "select a from tbl where b=2 and c=3;"
->       [QueryStatement ea $ selectFromWhere
->         (selIL ["a"])
->         (Tref ea (i "tbl") (NoAlias ea))
->         (FunCall ea (name "!and")
->          [FunCall ea (name "=")  [Identifier ea "b", NumberLit ea "2"]
->          ,FunCall ea (name "=") [Identifier ea "c", NumberLit ea "3"]])]
->      {-,MSStmt "select a from t;\ngo"
->          [QueryStatement ea $ selectFrom (selIL ["a"]) (Tref ea (i "t") (NoAlias ea))]
->      ,MSStmt "select a from t;\nset rowcount -1\ngo"
->          [QueryStatement ea $ selectFrom (selIL ["a"]) (Tref ea (i "t") (NoAlias ea))]
->      ,MSStmt "select a from t;\nset rowcount 10\ngo"
->       [QueryStatement ea $ Select ea Dupes
->        (sl (selIL ["a"]))
->        [Tref ea (i "t") (NoAlias ea)]
->        Nothing [] Nothing [] (Just (NumberLit ea "10")) Nothing]-}
->      ,s "SELECT T.A::INT FROM TABLE AS T;"
->         [QueryStatement ea
->          (Select ea Dupes
->           (SelectList ea
->            [SelExp ea (Cast ea (QIdentifier ea [Nmc "T",Nmc "A"])
->                        (SimpleTypeName ea "int"))])
->           [Tref ea (Name ea [Nmc "TABLE"]) (TableAlias ea (Nmc "T"))]
->           Nothing [] Nothing [] Nothing Nothing)]
->      ]
->
-
->    ,Group "more select statements" [
->       s "select a from tbl\n\
->         \except\n\
->         \select a from tbl1;"
->       [QueryStatement ea $ CombineQueryExpr ea Except
->        (selectFrom (selIL ["a"]) (Tref ea (i "tbl") (NoAlias ea)))
->        (selectFrom (selIL ["a"]) (Tref ea (i "tbl1") (NoAlias ea)))]
->      ,s "select a from tbl where true\n\
->         \except\n\
->         \select a from tbl1 where true;"
->       [QueryStatement ea $ CombineQueryExpr ea Except
->        (selectFromWhere (selIL ["a"]) (Tref ea (i "tbl") (NoAlias ea)) (BooleanLit ea True))
->        (selectFromWhere (selIL ["a"]) (Tref ea (i "tbl1") (NoAlias ea)) (BooleanLit ea True))]
->      ,s "select a from tbl\n\
->         \union\n\
->         \select a from tbl1;"
->       [QueryStatement ea $ CombineQueryExpr ea Union
->        (selectFrom (selIL ["a"]) (Tref ea (i "tbl") (NoAlias ea)))
->        (selectFrom (selIL ["a"]) (Tref ea (i "tbl1") (NoAlias ea)))]
->      ,s "select a from tbl\n\
->         \union all\n\
->         \select a from tbl1;"
->       [QueryStatement ea $ CombineQueryExpr ea UnionAll
->        (selectFrom (selIL ["a"]) (Tref ea (i "tbl") (NoAlias ea)))
->        (selectFrom (selIL ["a"]) (Tref ea (i "tbl1") (NoAlias ea)))]
->      ,s "(select 1 union select 2) union select 3;"
->       [QueryStatement ea
->        (CombineQueryExpr ea Union
->         (CombineQueryExpr ea Union
->          (selectE (SelectList ea [SelExp ea (NumberLit ea "1")]))
->          (selectE (SelectList ea [SelExp ea (NumberLit ea "2")])))
->         (selectE (SelectList ea [SelExp ea (NumberLit ea "3")])))]
->      ,s "select 1 union (select 2 union select 3);"
->       [QueryStatement ea
->        (CombineQueryExpr ea Union
->         (selectE (SelectList ea [SelExp ea (NumberLit ea "1")]))
->         (CombineQueryExpr ea Union
->          (selectE (SelectList ea [SelExp ea (NumberLit ea "2")]))
->          (selectE (SelectList ea [SelExp ea (NumberLit ea "3")]))))]
->      ,s [here|
->          with a as (select 1 as a1),
->               b as (select * from a)
->               select * from b; |]
->          [QueryStatement ea
->           (WithQueryExpr ea
->            [WithQuery ea (Nmc "a") Nothing (selectE $ SelectList ea
->                                             [SelectItem ea (NumberLit ea "1") (Nmc "a1")])
->            ,WithQuery ea (Nmc "b") Nothing (selectFrom (selEL [Star ea]) (Tref ea (i "a") (NoAlias ea)))]
->            (selectFrom (selEL [Star ea]) (Tref ea (i "b") (NoAlias ea))))]
->      ,s [here|
->          with a as (select 1 as a1),
->               b as (select * from a)
->               select * from a
->               union select * from b; |]
->          [QueryStatement ea
->           (WithQueryExpr ea
->            [WithQuery ea (Nmc "a") Nothing (selectE $ SelectList ea
->                                             [SelectItem ea (NumberLit ea "1") (Nmc "a1")])
->            ,WithQuery ea (Nmc "b") Nothing (selectFrom (selEL [Star ea]) (Tref ea (i "a") (NoAlias ea)))]
->            (CombineQueryExpr ea Union
->              (selectFrom (selEL [Star ea]) (Tref ea (i "a") (NoAlias ea)))
->              (selectFrom (selEL [Star ea]) (Tref ea (i "b") (NoAlias ea)))))]
->      ,s "select a as b from tbl;"
->       [QueryStatement ea $ selectFrom [SelectItem ea (Identifier ea "a") (Nmc "b")] (Tref ea (i "tbl") (NoAlias ea))]
->      ,s "select a + b as b from tbl;"
->       [QueryStatement ea $ selectFrom
->        [SelectItem ea
->         (FunCall ea (name "+")
->          [Identifier ea "a", Identifier ea "b"]) (Nmc "b")]
->        (Tref ea (i "tbl") (NoAlias ea))]
->      ,s "select a.* from tbl a;"
->       [QueryStatement ea $ selectFrom (selEL [QStar ea (Nmc "a")]) (Tref ea (i "tbl") (TableAlias ea (Nmc "a")))]
->      ,s "select a.* from tbl a(b,c);"
->       [QueryStatement ea $ selectFrom (selEL [QStar ea (Nmc "a")]) (Tref ea (i "tbl") (FullAlias ea (Nmc "a") [Nmc "b",Nmc "c"]))]
-
->      ,s "select * from t1 a, t2 b;"
->             [QueryStatement ea
->              (Select ea Dupes
->               (SelectList ea
->                [SelExp ea (Star ea)])
->               [Tref ea (i "t1") (TableAlias ea (Nmc "a")),Tref ea (i "t2") (TableAlias ea (Nmc "b"))]
->               Nothing [] Nothing [] Nothing Nothing)]
->      ,s "select a from b inner join c on b.a=c.a;"
->       [QueryStatement ea $ selectFrom
->        (selIL ["a"])
->        (JoinTref ea (Tref ea (i "b") (NoAlias ea)) Unnatural Inner (Tref ea (i "c") (NoAlias ea))
->           (Just (JoinOn ea
->            (FunCall ea (name "=") [eqi "b" "a", eqi "c" "a"]))) (NoAlias ea))]
->      ,s "select a from b inner join c as d on b.a=d.a;"
->       [QueryStatement ea $ selectFrom
->        (selIL ["a"])
->        (JoinTref ea (Tref ea (i "b") (NoAlias ea)) Unnatural Inner (Tref ea (i "c") (TableAlias ea (Nmc "d")))
->           (Just (JoinOn ea
->            (FunCall ea (name "=") [eqi "b" "a", eqi "d" "a"]))) (NoAlias ea))]
->      ,s "select a from b inner join c using(d,e);"
->       [QueryStatement ea $ selectFrom
->        (selIL ["a"])
->        (JoinTref ea (Tref ea (i "b") (NoAlias ea)) Unnatural Inner (Tref ea (i "c") (NoAlias ea))
->           (Just (JoinUsing ea [Nmc "d",Nmc "e"])) (NoAlias ea))]
->      ,s "select a from b natural inner join c;"
->       [QueryStatement ea $ selectFrom
->        (selIL ["a"])
->        (JoinTref ea (Tref ea (i "b") (NoAlias ea)) Natural Inner (Tref ea (i "c") (NoAlias ea)) Nothing (NoAlias ea))]
->      ,s "select a from b left outer join c;"
->       [QueryStatement ea $ selectFrom
->        (selIL ["a"])
->        (JoinTref ea (Tref ea (i "b") (NoAlias ea)) Unnatural LeftOuter (Tref ea (i "c") (NoAlias ea)) Nothing (NoAlias ea))]
->      ,s "select a from b full outer join c;"
->       [QueryStatement ea $ selectFrom
->        (selIL ["a"])
->        (JoinTref ea (Tref ea (i "b") (NoAlias ea)) Unnatural FullOuter (Tref ea (i "c") (NoAlias ea)) Nothing (NoAlias ea))]
->      ,s "select a from b right outer join c;"
->       [QueryStatement ea $ selectFrom
->        (selIL ["a"])
->        (JoinTref ea (Tref ea (i "b") (NoAlias ea)) Unnatural RightOuter (Tref ea (i "c") (NoAlias ea)) Nothing (NoAlias ea))]
->      ,s "select a from b cross join c;"
->       [QueryStatement ea $ selectFrom
->        (selIL ["a"])
->        (JoinTref ea (Tref ea (i "b") (NoAlias ea)) Unnatural Cross (Tref ea (i "c") (NoAlias ea)) Nothing (NoAlias ea))]
->      ,s "select a from (b natural join c);"
->       [QueryStatement ea $ selectFrom
->        (selIL ["a"])
->        (JoinTref ea (Tref ea (i "b") (NoAlias ea)) Natural Inner (Tref ea (i "c") (NoAlias ea)) Nothing (NoAlias ea))]
->      ,s "select x from a cross join b cross join c;"
->        [QueryStatement ea
->         (selectFrom (selIL ["x"])
->          (JoinTref ea
->          (JoinTref ea
->           (Tref ea (i "a") (NoAlias ea))
->            Unnatural Cross
->           (Tref ea (i "b") (NoAlias ea))
->           Nothing (NoAlias ea))
->          Unnatural Cross
->          (Tref ea (i "c") (NoAlias ea))
->          Nothing (NoAlias ea)))]
->      ,s "select x from ((a cross join b) cross join c);"
->        [QueryStatement ea
->         (selectFrom (selIL ["x"])
->          (JoinTref ea
->          (JoinTref ea
->           (Tref ea (i "a") (NoAlias ea))
->            Unnatural Cross
->           (Tref ea (i "b") (NoAlias ea))
->           Nothing (NoAlias ea))
->          Unnatural Cross
->          (Tref ea (i "c") (NoAlias ea))
->          Nothing (NoAlias ea)))]
->      ,s "select x from (a cross join (b cross join c));"
->        [QueryStatement ea
->         (selectFrom (selIL ["x"])
->          (JoinTref ea
->           (Tref ea (i "a") (NoAlias ea))
->           Unnatural Cross
->           (JoinTref ea
->            (Tref ea (i "b") (NoAlias ea))
->            Unnatural Cross
->            (Tref ea (i "c") (NoAlias ea))
->            Nothing (NoAlias ea))
->           Nothing (NoAlias ea)))]
-
->      ,s "select x from ((a cross join b) cross join c);"
->        [QueryStatement ea
->         (selectFrom (selIL ["x"])
->          (JoinTref ea
->          (JoinTref ea
->           (Tref ea (i "a") (NoAlias ea))
->            Unnatural Cross
->           (Tref ea (i "b") (NoAlias ea))
->           Nothing (NoAlias ea))
->          Unnatural Cross
->          (Tref ea (i "c") (NoAlias ea))
->          Nothing (NoAlias ea)))]
->      ,s "select x from (a cross join b) cross join c;"
->        [QueryStatement ea
->         (selectFrom (selIL ["x"])
->          (JoinTref ea
->          (JoinTref ea
->           (Tref ea (i "a") (NoAlias ea))
->            Unnatural Cross
->           (Tref ea (i "b") (NoAlias ea))
->           Nothing (NoAlias ea))
->          Unnatural Cross
->          (Tref ea (i "c") (NoAlias ea))
->          Nothing (NoAlias ea)))]
->      ,s "select x from ((a cross join b) cross join c) cross join d;"
->        [QueryStatement ea
->         (selectFrom (selIL ["x"])
->          (JoinTref ea
->           (JoinTref ea
->            (JoinTref ea
->             (Tref ea (i "a") (NoAlias ea))
->             Unnatural Cross
->             (Tref ea (i "b") (NoAlias ea))
->             Nothing (NoAlias ea))
->            Unnatural Cross
->            (Tref ea (i "c") (NoAlias ea))
->            Nothing (NoAlias ea))
->           Unnatural Cross
->           (Tref ea (i "d") (NoAlias ea))
->           Nothing (NoAlias ea)))]
->      ,s "select a from b\n\
->         \    inner join c\n\
->         \      on true\n\
->         \    inner join d\n\
->         \      on 1=1;"
->       [QueryStatement ea $ selectFrom
->        [SelExp ea (Identifier ea "a")]
->        (JoinTref ea
->         (JoinTref ea (Tref ea (i "b") (NoAlias ea)) Unnatural Inner (Tref ea (i "c") (NoAlias ea))
->          (Just $ JoinOn ea (BooleanLit ea True)) (NoAlias ea))
->         Unnatural Inner (Tref ea (i "d") (NoAlias ea))
->         (Just $ JoinOn ea (FunCall ea (name "=")
->                [NumberLit ea "1", NumberLit ea "1"])) (NoAlias ea))]
-
->      ,s "select row_number() over(order by a) as place from tbl;"
->       [QueryStatement ea $ selectFrom [SelectItem ea
->                    (WindowFn ea
->                     (FunCall ea (name "row_number") [])
->                     []
->                     [(Identifier ea "a", Asc)] FrameUnboundedPreceding)
->                    (Nmc "place")]
->        (Tref ea (i "tbl") (NoAlias ea))]
->      ,s "select row_number() over(order by a asc) as place from tbl;"
->       [QueryStatement ea $ selectFrom [SelectItem ea
->                    (WindowFn ea
->                     (FunCall ea (name "row_number") [])
->                     []
->                     [(Identifier ea "a",Asc)] FrameUnboundedPreceding)
->                    (Nmc "place")]
->        (Tref ea (i "tbl") (NoAlias ea))]
->      ,s "select row_number() over(order by a desc) as place from tbl;"
->       [QueryStatement ea $ selectFrom [SelectItem ea
->                    (WindowFn ea
->                     (FunCall ea (name "row_number") [])
->                     []
->                     [(Identifier ea "a", Desc)] FrameUnboundedPreceding)
->                    (Nmc "place")]
->        (Tref ea (i "tbl") (NoAlias ea))]
->      ,s "select row_number()\n\
->         \over(partition by (a,b) order by c) as place\n\
->         \from tbl;"
->       [QueryStatement ea $ selectFrom [SelectItem ea
->                    (WindowFn ea
->                     (FunCall ea (name "row_number") [])
->                     [FunCall ea (name "!rowctor") [Identifier ea "a",Identifier ea "b"]]
->                     [(Identifier ea "c", Asc)] FrameUnboundedPreceding)
->                    (Nmc "place")]
->        (Tref ea (i "tbl") (NoAlias ea))]
->      ,s "select * from a natural inner join (select * from b) as a;"
->       [QueryStatement ea $ selectFrom
->        (selEL [Star ea])
->        (JoinTref ea (Tref ea (i "a") (NoAlias ea)) Natural
->         Inner (SubTref ea (selectFrom
->                         (selEL [Star ea])
->                         (Tref ea (i "b") (NoAlias ea))) (TableAlias ea $ Nmc "a"))
->         Nothing (NoAlias ea))]
->      ,s "select * from a order by c;"
->       [QueryStatement ea $ Select ea  Dupes
->        (sl (selEL [Star ea]))
->        [Tref ea (i "a") (NoAlias ea)]
->        Nothing [] Nothing [(Identifier ea "c",Asc)] Nothing Nothing]
->      ,s "select *\n\
->            \from Adventure\n\
->            \order by Clicks desc, AdventureID;"
->       [QueryStatement ea $ Select ea Dupes
->        (sl (selEL [Star ea]))
->        [Tref ea (i "Adventure") (NoAlias ea)]
->        Nothing [] Nothing [(Identifier ea "Clicks",Desc)
->                           ,(Identifier ea "AdventureID",Asc)] Nothing Nothing]
->      ,s "select * from a order by c,d asc;"
->       [QueryStatement ea $ Select ea Dupes
->        (sl (selEL [Star ea]))
->        [Tref ea (i "a") (NoAlias ea)]
->        Nothing [] Nothing [(Identifier ea "c", Asc)
->                           ,(Identifier ea "d", Asc)] Nothing Nothing]
->      ,s "select * from a order by c,d desc;"
->       [QueryStatement ea $ Select ea Dupes
->        (sl (selEL [Star ea]))
->        [Tref ea (i "a") (NoAlias ea)]
->        Nothing [] Nothing [(Identifier ea "c", Asc)
->                           ,(Identifier ea "d", Desc)] Nothing Nothing]
->      ,s "select * from a order by c limit 1;"
->       [QueryStatement ea $ Select ea Dupes
->        (sl (selEL [Star ea]))
->        [Tref ea (i "a") (NoAlias ea)]
->        Nothing [] Nothing [(Identifier ea "c",Asc)] (Just (NumberLit ea "1")) Nothing]
->      ,s "select top 3 * from a order by c;"
->       [QueryStatement ea $ Select ea Dupes
->        (sl (selEL [Star ea]))
->        [Tref ea (i "a") (NoAlias ea)]
->        Nothing [] Nothing [(Identifier ea "c",Asc)] (Just (NumberLit ea "3")) Nothing]
->      ,s "select * from a order by c offset 3;"
->       [QueryStatement ea $ Select ea Dupes
->        (sl (selEL [Star ea]))
->        [Tref ea (i "a") (NoAlias ea)]
->        Nothing [] Nothing [(Identifier ea "c",Asc)] Nothing (Just $ NumberLit ea "3")]
->      ,s "select a from (select b from c) as d;"
->         [QueryStatement ea $ selectFrom
->          (selIL ["a"])
->          (SubTref ea (selectFrom
->                    (selIL ["b"])
->                    (Tref ea (i "c") (NoAlias ea)))
->           (TableAlias ea $ Nmc "d"))]
->      ,s "select * from gen();"
->         [QueryStatement ea $ selectFrom (selEL [Star ea]) (FunTref ea (FunCall ea (name "gen") []) (NoAlias ea))]
->      ,s "select * from gen() as t;"
->       [QueryStatement ea $ selectFrom
->        (selEL [Star ea])
->        (FunTref ea (FunCall ea (name "gen") [])(TableAlias ea $ Nmc "t"))]
->      ,s "select count(distinct b) from c;"
->         [QueryStatement ea $ Select ea Dupes
->          (sl [SelExp ea (AggregateFn ea Distinct
->                          (FunCall ea (name "count") [Identifier ea "b"])
->                          [])])
->          [Tref ea (i "c") (NoAlias ea)] Nothing []
->          Nothing [] Nothing Nothing]
->      ,s "select count(all b) from c;"
->         [QueryStatement ea $ Select ea Dupes
->          (sl [SelExp ea (AggregateFn ea Dupes
->                          (FunCall ea (name "count") [Identifier ea "b"])
->                          [])])
->          [Tref ea (i "c") (NoAlias ea)] Nothing []
->          Nothing [] Nothing Nothing]
->      ,s "select string_agg(distinct relname,',' order by relname1) from pg_class;"
->         [QueryStatement ea $ Select ea Dupes
->          (sl [SelExp ea (AggregateFn ea Distinct
->                          (FunCall ea (name "string_agg") [Identifier ea "relname"
->                                                   ,StringLit ea ","])
->                          [(Identifier ea "relname1", Asc)])])
->          [Tref ea (i "pg_class") (NoAlias ea)] Nothing []
->          Nothing [] Nothing Nothing]
->      ,s "select a, count(b) from c group by a;"
->         [QueryStatement ea $ Select ea Dupes
->          (sl [selI "a", SelExp ea (FunCall ea (name "count") [Identifier ea "b"])])
->          [Tref ea (i "c") (NoAlias ea)] Nothing [Identifier ea "a"]
->          Nothing [] Nothing Nothing]
->      ,s "select a, count(b) as cnt from c group by a having cnt > 4;"
->         [QueryStatement ea $ Select ea Dupes
->          (sl [selI "a", SelectItem ea (FunCall ea (name "count") [Identifier ea "b"]) $ Nmc "cnt"])
->          [Tref ea (i "c") (NoAlias ea)] Nothing [Identifier ea "a"]
->          (Just $ FunCall ea (name ">") [Identifier ea "cnt", NumberLit ea "4"])
->          [] Nothing Nothing]
->      ,s "select a from (select 1 as a, 2 as b) x;"
->         [QueryStatement ea $ selectFrom
->          [selI "a"]
->          (SubTref ea (selectE $ SelectList ea
->                                [SelectItem ea (NumberLit ea "1") $ Nmc "a"
->                                ,SelectItem ea (NumberLit ea "2") $ Nmc "b"])
->                   (TableAlias ea $ Nmc "x"))]
->      ]
->      ]
->    ,Group "some misc stuff" [
->       s "select (p).x, (p).y from pos;"
->         [QueryStatement ea $ selectFrom (selEL [eqi "p" "x"
->                                                ,eqi "p" "y"])
->                                          (Tref ea (i "pos") (NoAlias ea))]
->      ,s "select ($1).x, ($1).y from pos;"
->         [QueryStatement ea $ selectFrom
->          (selEL [member (PositionalArg ea 1) (Identifier ea "x")
->                 ,member (PositionalArg ea 1) (Identifier ea "y")])
->          (Tref ea (i "pos") (NoAlias ea))]
->      ,s "select row_number() over(), x from tb;"
->       [QueryStatement ea $ selectFrom
->        [SelExp ea
->                     (WindowFn ea
->                     (FunCall ea (name "row_number") [])
->                     []
->                     [] FrameUnboundedPreceding)
->        , selI "x"]
->        (Tref ea (i "tb") (NoAlias ea))]
->      ]]
->  where
->    s = Stmt
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Utils.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Utils.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/Parsing/Utils.lhs
+++ /dev/null
@@ -1,90 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.Parsing.Utils where
-
-> import Database.HsSqlPpp.Ast
-> import Database.HsSqlPpp.Annotation
-> import GHC.Exts (IsString(..))
-
-> data Item = Expr String ScalarExpr
->           | Stmt String [Statement]
->           | PgSqlStmt String [Statement]
->           | Group String [Item]
-
--------------------------------------------------------------------------------
-
-shortcuts for constructing test data and asts
-
-> stringQ :: String -> ScalarExpr
-> stringQ = StringLit ea
->
-> selectFrom :: SelectItemList
->            -> TableRef
->            -> QueryExpr
-> selectFrom selList frm = Select ea Dupes (SelectList ea selList)
->                            [frm] Nothing [] Nothing [] Nothing Nothing
->
-> selectE :: SelectList -> QueryExpr
-> selectE selList = Select ea Dupes selList
->                     [] Nothing [] Nothing [] Nothing Nothing
->
-> selIL :: [String] -> [SelectItem]
-> selIL = map selI
-> selEL :: [ScalarExpr] -> [SelectItem]
-> selEL = map (SelExp ea)
->
-> i :: String -> Name
-> i x = Name ea [Nmc x]
-
-> dqi :: String -> Name
-> dqi x = Name ea [Nmc x]
-
-> eqi :: String -> String -> ScalarExpr
-> eqi c x = QIdentifier ea [Nmc c, Nmc x]
-
-> ei :: String -> ScalarExpr
-> ei = Identifier ea . Nmc
->
-> qi :: String -> String -> Name
-> qi c n = Name ea [Nmc c, Nmc n]
->
-> selI :: String -> SelectItem
-> selI = SelExp ea . Identifier ea . Nmc
->
-> sl :: SelectItemList -> SelectList
-> sl = SelectList ea
->
-> selectFromWhere :: SelectItemList
->                 -> TableRef
->                 -> ScalarExpr
->                 -> QueryExpr
-> selectFromWhere selList frm whr =
->     Select ea Dupes (SelectList ea selList)
->                [frm] (Just whr) [] Nothing [] Nothing Nothing
->
-> att :: String -> String -> AttributeDef
-> att n t = AttributeDef ea (Nmc n) (SimpleTypeName ea t) Nothing []
-
-> ea :: Annotation
-> ea = emptyAnnotation
-
-> name :: String -> Name
-> name n = Name ea [Nmc n]
-
-> instance IsString NameComponent where
->     fromString = Nmc
-
-> member :: ScalarExpr -> ScalarExpr -> ScalarExpr
-> member a b = FunCall ea (name ".") [a,b]
-
-
-
-> num :: String -> ScalarExpr
-> num n = NumberLit ea n
-
-> funCall :: String -> [ScalarExpr] -> ScalarExpr
-> funCall n as = FunCall ea (name n) as
-
-> lTrue,lFalse,lNull :: ScalarExpr
-> lTrue = BooleanLit ea True
-> lFalse = BooleanLit ea False
-> lNull = NullLit ea
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/QuasiQuoteTests.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/QuasiQuoteTests.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/QuasiQuoteTests.lhs
+++ /dev/null
@@ -1,180 +0,0 @@
-
-Tests mainly for antiquotation, plus examples of where antiquotes work.
-
-> {-# LANGUAGE QuasiQuotes,ScopedTypeVariables #-}
->
-> module Database.HsSqlPpp.Tests.QuasiQuoteTests (quasiQuoteTests, quasiQuoteTestData, Item(..)) where
->
-> import Test.HUnit
-> import Test.Framework
-> import Test.Framework.Providers.HUnit
-> import Data.Data
->
-> import Database.HsSqlPpp.Ast
-> import Database.HsSqlPpp.Annotation
-> import Database.HsSqlPpp.Pretty
-> import Database.HsSqlPpp.Quote
-> import Database.HsSqlPpp.Tests.TestUtils
->
-> data Item = Expr ScalarExpr ScalarExpr
->           | Stmts [Statement] [Statement]
->           | PgSqlStmts [Statement] [Statement]
->           | Stmt Statement Statement
->           | PgSqlStmt Statement Statement
->           | Group String [Item]
-> quasiQuoteTests :: Test.Framework.Test
-> quasiQuoteTests = itemToTft quasiQuoteTestData
->
-> quasiQuoteTestData :: Item
-> quasiQuoteTestData =
->   Group "quasiQuoteTests" [
-
---------------------------------------------------------------------------------
-
-expressions
-
->    Group "stuff" [
->      let tablename = "my_table"
->          varname = "my_field"
->          typename = "text"
->      in Stmt [sqlStmt|
->
->      create table $(tablename) (
->        $(varname) $(typename)
->      );
->
->      |]
->      [sqlStmt|
->      create table my_table (
->        my_field text
->      );
->      |]
->
->     ,let fnname = "my_function"
->          tablename = "my_table"
->          typename = "int"
->      in Stmt [sqlStmt|
->
->   create function $(fnname)() returns $(typename) as $a$
->     select * from $(tablename);
->   $a$ language sql stable;
->
->      |]
->      [sqlStmt|
->   create function my_function() returns int as $a$
->     select * from my_table;
->   $a$ language sql stable;
->      |]
->
->     ,let fnname = "my_function"
->      in Stmt [sqlStmt| drop function $(fnname)();|]
->              [sqlStmt| drop function my_function();|]
->
->     ,let expr = StringLit ea "testing"
->      in PgSqlStmt [pgsqlStmt| return $(expr); |]
->                   [pgsqlStmt| return 'testing'; |]
->
->     ,let expr = (FunCall ea (Name ea [Nmc "+"]) [NumberLit ea "3",NumberLit ea "4"])
->      in PgSqlStmt [pgsqlStmt| return $(expr); |]
->                   [pgsqlStmt| return 3 + 4; |]
->
->     ,let errMsg = "this splice is slighty dodgy"
->      in PgSqlStmt [pgsqlStmt|
->      if true then
->        raise exception '$(errMsg)';
->      end if;|]
->      [pgsqlStmt|
->      if true then
->        raise exception 'this splice is slighty dodgy';
->      end if;|]
->
->     ,let triggername = "my_trigger"
->          tablename = "my_table"
->          opname = "my_function"
->      in Stmt [sqlStmt|
->   create trigger $(triggername)
->     after insert or update or delete on $(tablename)
->     for each statement
->     execute procedure $(opname)();
->             |]
->              [sqlStmt|
->   create trigger my_trigger
->     after insert or update or delete on my_table
->     for each statement
->     execute procedure my_function();
->             |]
->     ,let tablename = "lotsastuff"
->      in Expr [sqlExpr|(select count(*) from $(tablename))|]
->              [sqlExpr|(select count(*) from lotsastuff)|]
->
->     ,let trigname = "tbl_trig1"
->          tablename = "tbl"
->          tevent = TUpdate
->          fn = "checkit"
->      in Stmt [sqlStmt|
->      create trigger $(trigname)
->         after $(tevent) on $(tablename)
->         for each row
->         execute procedure $(fn)();
->             |] [sqlStmt|
->      create trigger tbl_trig1
->         after update on tbl
->         for each row
->         execute procedure checkit();
->             |]
->     ,let x = "fnname"
->      in Expr [sqlExpr| $(x)('a') |]
->              [sqlExpr| fnname('a') |]
->     ,let x = "splicedstring"
->      in Expr [sqlExpr| $s(x) |]
->              (StringLit ea "splicedstring")
->     ,let x = "splicedIdentifier"
->      in Expr [sqlExpr| $i(x) |]
->              (Identifier ea $ Nmc "splicedIdentifier")
->     ,let errMsg = "this splice isn't too dodgy"
->      in PgSqlStmt [pgsqlStmt| raise exception $s(errMsg); |]
->                   [pgsqlStmt| raise exception 'this splice isn''t too dodgy'; |]
-
->     {-,let s1 = [sqlStmts| select * from tbl; |]
->      in Stmts [sqlStmts|
->      select 1;
->      $(s1);
->      select 2;|]
->        [sqlStmts|
->      select 1;
->      select * from tbl;
->      select 2;|]
-
->     ,let s1 = [sqlStmt| select * from tbl; |]
->          s2 = [s1,s2]
->      in Stmts [sqlStmts|
->      select 1;
->      $(s2);
->      select 2;|]
->        [sqlStmts|
->      select 1;
->      select * from tbl;
->      select * from tbl;
->      select 2;|]-}
-
-
->   ]]
-
-
-================================================================================
-
-Unit test helpers
-
-> itemToTft :: Item -> Test.Framework.Test
-> itemToTft (Expr a b) = testCase (printScalarExpr b) $ stripEqual a b
-> itemToTft (PgSqlStmt a b) = testCase (printStatements [b]) $ stripEqual a b
-> itemToTft (Stmt a b) = testCase (printStatements [b]) $  stripEqual a b
-> itemToTft (PgSqlStmts a b) = testCase (printStatements b) $ stripEqual a b
-> itemToTft (Stmts a b) = testCase (printStatements b) $ stripEqual a b
-> itemToTft (Group s is) = testGroup s $ map itemToTft is
-> stripEqual :: (Data a, Eq a, Show a) =>
->               a -> a -> Assertion
-> stripEqual a b = assertEqual "" (resetAnnotations a) (resetAnnotations b)
-
-> ea :: Annotation
-> ea = emptyAnnotation
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TestUtils.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TestUtils.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TestUtils.lhs
+++ /dev/null
@@ -1,30 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TestUtils
->     (assertTrace,resetAnnotations) where
->
-> import Test.HUnit
-> --import Test.Framework
-> --import Test.Framework.Providers.HUnit
-> --import Data.List
-> import Data.Generics.Uniplate.Data
-> import Data.Data
-
-> import Debug.Trace
-> import Control.Monad
-
-> --import Database.HsSqlPpp.Utils.Here
-> --import Database.HsSqlPpp.Parser
-> --import Database.HsSqlPpp.TypeChecker
-> import Database.HsSqlPpp.Annotation
-> --import Database.HsSqlPpp.Catalog
-> --import Database.HsSqlPpp.SqlTypes
-> --import Database.HsSqlPpp.Utils.PPExpr
-
-
-> assertTrace :: (Show a,Eq a) => String -> String -> a -> a -> IO ()
-> assertTrace nem s a1 a2 = do
->     when (a1 /= a2) $ trace nem $ return ()
->     assertEqual s a1 a2
-
-> resetAnnotations :: Data a => a -> a
-> resetAnnotations = transformBi (const emptyAnnotation)
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/Tests.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/Tests.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/Tests.lhs
+++ /dev/null
@@ -1,28 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.Tests (allTests) where
->
-> import Test.Framework
->
-> import Database.HsSqlPpp.Tests.Parsing.ParserTests
-
-> import Database.HsSqlPpp.Tests.FixTree.FixUpIdentifiersTests
-> import Database.HsSqlPpp.Tests.FixTree.ExplicitCasts
-
-> import Database.HsSqlPpp.Tests.TypeChecking.TypeCheckTests
-
-> import Database.HsSqlPpp.Tests.QuasiQuoteTests
-
-> --import Database.HsSqlPpp.Tests.ExtensionTests
-> import Database.HsSqlPpp.Tests.ParameterizedStatementTests
->
-> allTests :: [Test]
-> allTests =
->     parserTests
->     : fixUpIdentifiersTests
->     : explicitCastTests
->     : quasiQuoteTests
->     : typeCheckTests
->     : parameterizedStatementTests
->     -- : extensionTests
->     : []
-
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TpchData.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TpchData.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TpchData.lhs
+++ /dev/null
@@ -1,974 +0,0 @@
-
-> {-# LANGUAGE QuasiQuotes #-}
-> module Database.HsSqlPpp.Tests.TpchData
->     (tpchQueries
->     ,tpchCatalog) where
->
-
-> import Database.HsSqlPpp.Utils.Here
-> import Database.HsSqlPpp.Catalog
-> import Database.HsSqlPpp.Types
-
-> tpchQueries :: [(String,String)]
-> tpchQueries =
->   [("Q1",[here|
-\begin{code}
-select
-        l_returnflag,
-        l_linestatus,
-        sum(l_quantity) as sum_qty,
-        sum(l_extendedprice) as sum_base_price,
-        sum(l_extendedprice * (1 - l_discount)) as sum_disc_price,
-        sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge,
-        avg(l_quantity) as avg_qty,
-        avg(l_extendedprice) as avg_price,
-        avg(l_discount) as avg_disc,
-        count(*) as count_order
-from
-        lineitem
-where
-        l_shipdate <= date '1998-12-01' - interval '63' day (3)
-group by
-        l_returnflag,
-        l_linestatus
-order by
-        l_returnflag,
-        l_linestatus;
---set rowcount -1
---go
-\end{code}
->                                     |])
->   ,("Q2",[here|
-\begin{code}
-
-select
-        s_acctbal,
-        s_name,
-        n_name,
-        p_partkey,
-        p_mfgr,
-        s_address,
-        s_phone,
-        s_comment
-from
-        part,
-        supplier,
-        partsupp,
-        nation,
-        region
-where
-        p_partkey = ps_partkey
-        and s_suppkey = ps_suppkey
-        and p_size = 15
-        and p_type like '%BRASS'
-        and s_nationkey = n_nationkey
-        and n_regionkey = r_regionkey
-        and r_name = 'EUROPE'
-        and ps_supplycost = (
-                select
-                        min(ps_supplycost)
-                from
-                        partsupp,
-                        supplier,
-                        nation,
-                        region
-                where
-                        p_partkey = ps_partkey
-                        and s_suppkey = ps_suppkey
-                        and s_nationkey = n_nationkey
-                        and n_regionkey = r_regionkey
-                        and r_name = 'EUROPE'
-        )
-order by
-        s_acctbal desc,
-        n_name,
-        s_name,
-        p_partkey;
---set rowcount 100
---go
-\end{code}
->                                     |])
->   ,("Q3",[here|
-\begin{code}
-select
-        l_orderkey,
-        sum(l_extendedprice * (1 - l_discount)) as revenue,
-        o_orderdate,
-        o_shippriority
-from
-        customer,
-        orders,
-        lineitem
-where
-        c_mktsegment = 'MACHINERY'
-        and c_custkey = o_custkey
-        and l_orderkey = o_orderkey
-        and o_orderdate < date '1995-03-21'
-        and l_shipdate > date '1995-03-21'
-group by
-        l_orderkey,
-        o_orderdate,
-        o_shippriority
-order by
-        revenue desc,
-        o_orderdate;
---set rowcount 10
---go
-\end{code}
->                                     |])
->   ,("Q4",[here|
-\begin{code}
-select
-        o_orderpriority,
-        count(*) as order_count
-from
-        orders
-where
-        o_orderdate >= date '1996-03-01'
-        and o_orderdate < date '1996-03-01' + interval '3' month
-        and exists (
-                select
-                        *
-                from
-                        lineitem
-                where
-                        l_orderkey = o_orderkey
-                        and l_commitdate < l_receiptdate
-        )
-group by
-        o_orderpriority
-order by
-        o_orderpriority;
---set rowcount -1
---go
-\end{code}
->                                     |])
->   ,("Q5",[here|
-\begin{code}
-select
-        n_name,
-        sum(l_extendedprice * (1 - l_discount)) as revenue
-from
-        customer,
-        orders,
-        lineitem,
-        supplier,
-        nation,
-        region
-where
-        c_custkey = o_custkey
-        and l_orderkey = o_orderkey
-        and l_suppkey = s_suppkey
-        and c_nationkey = s_nationkey
-        and s_nationkey = n_nationkey
-        and n_regionkey = r_regionkey
-        and r_name = 'EUROPE'
-        and o_orderdate >= date '1997-01-01'
-        and o_orderdate < date '1997-01-01' + interval '1' year
-group by
-        n_name
-order by
-        revenue desc;
---set rowcount -1
---go
-\end{code}
->                                     |])
->   ,("Q6",[here|
-\begin{code}
-select
-        sum(l_extendedprice * l_discount) as revenue
-from
-        lineitem
-where
-        l_shipdate >= date '1997-01-01'
-        and l_shipdate < date '1997-01-01' + interval '1' year
-        and l_discount between 0.07 - 0.01 and 0.07 + 0.01
-        and l_quantity < 24;
---set rowcount -1
---go
-\end{code}
->                                     |])
->   ,("Q7",[here|
-\begin{code}
-select
-        supp_nation,
-        cust_nation,
-        l_year,
-        sum(volume) as revenue
-from
-        (
-                select
-                        n1.n_name as supp_nation,
-                        n2.n_name as cust_nation,
-                        extract(year from l_shipdate) as l_year,
-                        l_extendedprice * (1 - l_discount) as volume
-                from
-                        supplier,
-                        lineitem,
-                        orders,
-                        customer,
-                        nation n1,
-                        nation n2
-                where
-                        s_suppkey = l_suppkey
-                        and o_orderkey = l_orderkey
-                        and c_custkey = o_custkey
-                        and s_nationkey = n1.n_nationkey
-                        and c_nationkey = n2.n_nationkey
-                        and (
-                                (n1.n_name = 'PERU' and n2.n_name = 'IRAQ')
-                                or (n1.n_name = 'IRAQ' and n2.n_name = 'PERU')
-                        )
-                        and l_shipdate between date '1995-01-01' and date '1996-12-31'
-        ) as shipping
-group by
-        supp_nation,
-        cust_nation,
-        l_year
-order by
-        supp_nation,
-        cust_nation,
-        l_year;
---set rowcount -1
---go
-\end{code}
->                                     |])
->   ,("Q8",[here|
-\begin{code}
-select
-        o_year,
-        sum(case
-                when nation = 'IRAQ' then volume
-                else 0
-        end) / sum(volume) as mkt_share
-from
-        (
-                select
-                        extract(year from o_orderdate) as o_year,
-                        l_extendedprice * (1 - l_discount) as volume,
-                        n2.n_name as nation
-                from
-                        part,
-                        supplier,
-                        lineitem,
-                        orders,
-                        customer,
-                        nation n1,
-                        nation n2,
-                        region
-                where
-                        p_partkey = l_partkey
-                        and s_suppkey = l_suppkey
-                        and l_orderkey = o_orderkey
-                        and o_custkey = c_custkey
-                        and c_nationkey = n1.n_nationkey
-                        and n1.n_regionkey = r_regionkey
-                        and r_name = 'MIDDLE EAST'
-                        and s_nationkey = n2.n_nationkey
-                        and o_orderdate between date '1995-01-01' and date '1996-12-31'
-                        and p_type = 'STANDARD ANODIZED BRASS'
-        ) as all_nations
-group by
-        o_year
-order by
-        o_year;
---set rowcount -1
---go
-
-\end{code}
->                                     |])
->   ,("Q9",[here|
-\begin{code}
-
-
-select
-        nation,
-        o_year,
-        sum(amount) as sum_profit
-from
-        (
-                select
-                        n_name as nation,
-                        extract(year from o_orderdate) as o_year,
-                        l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
-                from
-                        part,
-                        supplier,
-                        lineitem,
-                        partsupp,
-                        orders,
-                        nation
-                where
-                        s_suppkey = l_suppkey
-                        and ps_suppkey = l_suppkey
-                        and ps_partkey = l_partkey
-                        and p_partkey = l_partkey
-                        and o_orderkey = l_orderkey
-                        and s_nationkey = n_nationkey
-                        and p_name like '%antique%'
-        ) as profit
-group by
-        nation,
-        o_year
-order by
-        nation,
-        o_year desc;
---set rowcount -1
---go
-
-\end{code}
->                                     |])
->   ,("Q10",[here|
-\begin{code}
-
-
-select
-        c_custkey,
-        c_name,
-        sum(l_extendedprice * (1 - l_discount)) as revenue,
-        c_acctbal,
-        n_name,
-        c_address,
-        c_phone,
-        c_comment
-from
-        customer,
-        orders,
-        lineitem,
-        nation
-where
-        c_custkey = o_custkey
-        and l_orderkey = o_orderkey
-        and o_orderdate >= date '1993-12-01'
-        and o_orderdate < date '1993-12-01' + interval '3' month
-        and l_returnflag = 'R'
-        and c_nationkey = n_nationkey
-group by
-        c_custkey,
-        c_name,
-        c_acctbal,
-        c_phone,
-        n_name,
-        c_address,
-        c_comment
-order by
-        revenue desc;
---set rowcount 20
---go
-
-\end{code}
->                                     |])
->   ,("Q11",[here|
-\begin{code}
-
-
-select
-        ps_partkey,
-        sum(ps_supplycost * ps_availqty) as value
-from
-        partsupp,
-        supplier,
-        nation
-where
-        ps_suppkey = s_suppkey
-        and s_nationkey = n_nationkey
-        and n_name = 'CHINA'
-group by
-        ps_partkey having
-                sum(ps_supplycost * ps_availqty) > (
-                        select
-                                sum(ps_supplycost * ps_availqty) * 0.0001000000
-                        from
-                                partsupp,
-                                supplier,
-                                nation
-                        where
-                                ps_suppkey = s_suppkey
-                                and s_nationkey = n_nationkey
-                                and n_name = 'CHINA'
-                )
-order by
-        value desc;
---set rowcount -1
---go
-
-\end{code}
->                                     |])
->   ,("Q12",[here|
-\begin{code}
-
-
-select
-        l_shipmode,
-        sum(case
-                when o_orderpriority = '1-URGENT'
-                        or o_orderpriority = '2-HIGH'
-                        then 1
-                else 0
-        end) as high_line_count,
-        sum(case
-                when o_orderpriority <> '1-URGENT'
-                        and o_orderpriority <> '2-HIGH'
-                        then 1
-                else 0
-        end) as low_line_count
-from
-        orders,
-        lineitem
-where
-        o_orderkey = l_orderkey
-        and l_shipmode in ('AIR', 'RAIL')
-        and l_commitdate < l_receiptdate
-        and l_shipdate < l_commitdate
-        and l_receiptdate >= date '1994-01-01'
-        and l_receiptdate < date '1994-01-01' + interval '1' year
-group by
-        l_shipmode
-order by
-        l_shipmode;
---set rowcount -1
---go
-
-\end{code}
->                                     |])
->   ,("Q13",[here|
-\begin{code}
-
-
-select
-        c_count,
-        count(*) as custdist
-from
-        (
-                select
-                        c_custkey,
-                        count(o_orderkey)
-                from
-                        customer left outer join orders on
-                                c_custkey = o_custkey
-                                and o_comment not like '%pending%requests%'
-                group by
-                        c_custkey
-        ) as c_orders (c_custkey, c_count)
-group by
-        c_count
-order by
-        custdist desc,
-        c_count desc;
---set rowcount -1
---go
-
-\end{code}
->                                     |])
->   ,("Q14",[here|
-\begin{code}
-
-select
-        100.00 * sum(case
-                when p_type like 'PROMO%'
-                        then l_extendedprice * (1 - l_discount)
-                else 0
-        end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue
-from
-        lineitem,
-        part
-where
-        l_partkey = p_partkey
-        and l_shipdate >= date '1994-12-01'
-        and l_shipdate < date '1994-12-01' + interval '1' month;
---set rowcount -1
---go
-
-\end{code}
->                                     |])
->   ,("Q15",[here|
-\begin{code}
-
-/*create view revenue0 (supplier_no, total_revenue) as
-        select
-                l_suppkey,
-                sum(l_extendedprice * (1 - l_discount))
-        from
-                lineitem
-        where
-                l_shipdate >= date '1995-06-01'
-                and l_shipdate < date '1995-06-01' + interval '3' month
-        group by
-                l_suppkey;*/
-
-with
-revenue0 as
-        (select
-                l_suppkey as supplier_no,
-                sum(l_extendedprice * (1 - l_discount)) as total_revenue
-        from
-                lineitem
-        where
-                l_shipdate >= date '1995-06-01'
-                and l_shipdate < date '1995-06-01' + interval '3' month
-        group by
-                l_suppkey)
-select
-        s_suppkey,
-        s_name,
-        s_address,
-        s_phone,
-        total_revenue
-from
-        supplier,
-        revenue0
-where
-        s_suppkey = supplier_no
-        and total_revenue = (
-                select
-                        max(total_revenue)
-                from
-                        revenue0
-        )
-order by
-        s_suppkey;
-
---drop view revenue0;
---set rowcount -1
---go
-
-\end{code}
->                                     |])
->   ,("Q16",[here|
-\begin{code}
-
-
-select
-        p_brand,
-        p_type,
-        p_size,
-        count(distinct ps_suppkey) as supplier_cnt
-from
-        partsupp,
-        part
-where
-        p_partkey = ps_partkey
-        and p_brand <> 'Brand#15'
-        and p_type not like 'MEDIUM BURNISHED%'
-        and p_size in (39, 26, 18, 45, 19, 1, 3, 9)
-        and ps_suppkey not in (
-                select
-                        s_suppkey
-                from
-                        supplier
-                where
-                        s_comment like '%Customer%Complaints%'
-        )
-group by
-        p_brand,
-        p_type,
-        p_size
-order by
-        supplier_cnt desc,
-        p_brand,
-        p_type,
-        p_size;
---set rowcount -1
---go
-
-\end{code}
->                                     |])
->   ,("Q17",[here|
-\begin{code}
-
-
-select
-        sum(l_extendedprice) / 7.0 as avg_yearly
-from
-        lineitem,
-        part
-where
-        p_partkey = l_partkey
-        and p_brand = 'Brand#52'
-        and p_container = 'JUMBO CAN'
-        and l_quantity < (
-                select
-                        0.2 * avg(l_quantity)
-                from
-                        lineitem
-                where
-                        l_partkey = p_partkey
-        );
---set rowcount -1
---go
-
-\end{code}
->                                     |])
->   ,("Q18",[here|
-\begin{code}
-
-
-select
-        c_name,
-        c_custkey,
-        o_orderkey,
-        o_orderdate,
-        o_totalprice,
-        sum(l_quantity)
-from
-        customer,
-        orders,
-        lineitem
-where
-        o_orderkey in (
-                select
-                        l_orderkey
-                from
-                        lineitem
-                group by
-                        l_orderkey having
-                                sum(l_quantity) > 313
-        )
-        and c_custkey = o_custkey
-        and o_orderkey = l_orderkey
-group by
-        c_name,
-        c_custkey,
-        o_orderkey,
-        o_orderdate,
-        o_totalprice
-order by
-        o_totalprice desc,
-        o_orderdate;
---set rowcount 100
---go
-
-\end{code}
->                                     |])
->   ,("Q19",[here|
-\begin{code}
-
-
-select
-        sum(l_extendedprice* (1 - l_discount)) as revenue
-from
-        lineitem,
-        part
-where
-        (
-                p_partkey = l_partkey
-                and p_brand = 'Brand#43'
-                and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG')
-                and l_quantity >= 3 and l_quantity <= 3 + 10
-                and p_size between 1 and 5
-                and l_shipmode in ('AIR', 'AIR REG')
-                and l_shipinstruct = 'DELIVER IN PERSON'
-        )
-        or
-        (
-                p_partkey = l_partkey
-                and p_brand = 'Brand#25'
-                and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK')
-                and l_quantity >= 10 and l_quantity <= 10 + 10
-                and p_size between 1 and 10
-                and l_shipmode in ('AIR', 'AIR REG')
-                and l_shipinstruct = 'DELIVER IN PERSON'
-        )
-        or
-        (
-                p_partkey = l_partkey
-                and p_brand = 'Brand#24'
-                and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG')
-                and l_quantity >= 22 and l_quantity <= 22 + 10
-                and p_size between 1 and 15
-                and l_shipmode in ('AIR', 'AIR REG')
-                and l_shipinstruct = 'DELIVER IN PERSON'
-        );
---set rowcount -1
---go
-
-\end{code}
->                                     |])
->   ,("Q20",[here|
-\begin{code}
-
-
-select
-        s_name,
-        s_address
-from
-        supplier,
-        nation
-where
-        s_suppkey in (
-                select
-                        ps_suppkey
-                from
-                        partsupp
-                where
-                        ps_partkey in (
-                                select
-                                        p_partkey
-                                from
-                                        part
-                                where
-                                        p_name like 'lime%'
-                        )
-                        and ps_availqty > (
-                                select
-                                        0.5 * sum(l_quantity)
-                                from
-                                        lineitem
-                                where
-                                        l_partkey = ps_partkey
-                                        and l_suppkey = ps_suppkey
-                                        and l_shipdate >= date '1994-01-01'
-                                        and l_shipdate < date '1994-01-01' + interval '1' year
-                        )
-        )
-        and s_nationkey = n_nationkey
-        and n_name = 'VIETNAM'
-order by
-        s_name;
---set rowcount -1
---go
-
-\end{code}
->                                     |])
->   ,("Q21",[here|
-\begin{code}
-
-
-select
-        s_name,
-        count(*) as numwait
-from
-        supplier,
-        lineitem l1,
-        orders,
-        nation
-where
-        s_suppkey = l1.l_suppkey
-        and o_orderkey = l1.l_orderkey
-        and o_orderstatus = 'F'
-        and l1.l_receiptdate > l1.l_commitdate
-        and exists (
-                select
-                        *
-                from
-                        lineitem l2
-                where
-                        l2.l_orderkey = l1.l_orderkey
-                        and l2.l_suppkey <> l1.l_suppkey
-        )
-        and not exists (
-                select
-                        *
-                from
-                        lineitem l3
-                where
-                        l3.l_orderkey = l1.l_orderkey
-                        and l3.l_suppkey <> l1.l_suppkey
-                        and l3.l_receiptdate > l3.l_commitdate
-        )
-        and s_nationkey = n_nationkey
-        and n_name = 'INDIA'
-group by
-        s_name
-order by
-        numwait desc,
-        s_name;
---set rowcount 100
---go
-
-\end{code}
->                                     |])
->   ,("Q22",[here|
-\begin{code}
-
-
-select
-        cntrycode,
-        count(*) as numcust,
-        sum(c_acctbal) as totacctbal
-from
-        (
-                select
-                        substring(c_phone from 1 for 2) as cntrycode,
-                        c_acctbal
-                from
-                        customer
-                where
-                        substring(c_phone from 1 for 2) in
-                                ('41', '28', '39', '21', '24', '29', '44')
-                        and c_acctbal > (
-                                select
-                                        avg(c_acctbal)
-                                from
-                                        customer
-                                where
-                                        c_acctbal > 0.00
-                                        and substring(c_phone from 1 for 2) in
-                                                ('41', '28', '39', '21', '24', '29', '44')
-                        )
-                        and not exists (
-                                select
-                                        *
-                                from
-                                        orders
-                                where
-                                        o_custkey = c_custkey
-                        )
-        ) as custsale
-group by
-        cntrycode
-order by
-        cntrycode;
---set rowcount -1
---go
-
-\end{code}
->                                     |])
->   ]
-
-
-> tpchCatalog :: [CatalogUpdate]
-> tpchCatalog =
-
-CREATE TABLE NATION  ( N_NATIONKEY  INTEGER NOT NULL,
-                            N_NAME       CHAR(25) NOT NULL,
-                            N_REGIONKEY  INTEGER NOT NULL,
-                            N_COMMENT    VARCHAR(152));
-
->   [CatCreateTable "nation" [("n_nationkey", typeInt)
->                            ,("n_name", typeChar)
->                            ,("n_regionkey", typeInt)
->                            ,("n_comment", typeVarChar)] []
-
-CREATE TABLE REGION  ( R_REGIONKEY  INTEGER NOT NULL,
-                            R_NAME       CHAR(25) NOT NULL,
-                            R_COMMENT    VARCHAR(152));
-
->   ,CatCreateTable "region" [("r_regionkey", typeInt)
->                           ,("r_name", typeChar)
->                           ,("r_comment", typeVarChar)] []
-
-CREATE TABLE PART  ( P_PARTKEY     INTEGER NOT NULL,
-                          P_NAME        VARCHAR(55) NOT NULL,
-                          P_MFGR        CHAR(25) NOT NULL,
-                          P_BRAND       CHAR(10) NOT NULL,
-                          P_TYPE        VARCHAR(25) NOT NULL,
-                          P_SIZE        INTEGER NOT NULL,
-                          P_CONTAINER   CHAR(10) NOT NULL,
-                          P_RETAILPRICE DECIMAL(15,2) NOT NULL,
-                          P_COMMENT     VARCHAR(23) NOT NULL );
-
->   ,CatCreateTable "part" [("p_partkey", typeInt)
->                          ,("p_name", typeVarChar)
->                          ,("p_mfgr", typeChar)
->                          ,("p_brand", typeChar)
->                          ,("p_type", typeVarChar)
->                          ,("p_size", typeInt)
->                          ,("p_container", typeChar)
->                          ,("p_retailprice", typeNumeric)
->                          ,("p_comment", typeVarChar)] []
-
-CREATE TABLE SUPPLIER ( S_SUPPKEY     INTEGER NOT NULL,
-                             S_NAME        CHAR(25) NOT NULL,
-                             S_ADDRESS     VARCHAR(40) NOT NULL,
-                             S_NATIONKEY   INTEGER NOT NULL,
-                             S_PHONE       CHAR(15) NOT NULL,
-                             S_ACCTBAL     DECIMAL(15,2) NOT NULL,
-                             S_COMMENT     VARCHAR(101) NOT NULL);
-
->   ,CatCreateTable "supplier" [("s_suppkey", typeInt)
->                              ,("s_name", typeChar)
->                              ,("s_address", typeVarChar)
->                              ,("s_nationkey", typeInt)
->                              ,("s_phone", typeChar)
->                              ,("s_acctbal", typeNumeric)
->                              ,("s_comment", typeVarChar)] []
-
-
-CREATE TABLE PARTSUPP ( PS_PARTKEY     INTEGER NOT NULL,
-                             PS_SUPPKEY     INTEGER NOT NULL,
-                             PS_AVAILQTY    INTEGER NOT NULL,
-                             PS_SUPPLYCOST  DECIMAL(15,2)  NOT NULL,
-                             PS_COMMENT     VARCHAR(199) NOT NULL );
-
->   ,CatCreateTable "partsupp" [("ps_partkey", typeInt)
->                              ,("ps_suppkey", typeInt)
->                              ,("ps_availqty", typeInt)
->                              ,("ps_supplycost", typeNumeric)
->                              ,("ps_comment", typeVarChar)] []
-
-CREATE TABLE CUSTOMER ( C_CUSTKEY     INTEGER NOT NULL,
-                             C_NAME        VARCHAR(25) NOT NULL,
-                             C_ADDRESS     VARCHAR(40) NOT NULL,
-                             C_NATIONKEY   INTEGER NOT NULL,
-                             C_PHONE       CHAR(15) NOT NULL,
-                             C_ACCTBAL     DECIMAL(15,2)   NOT NULL,
-                             C_MKTSEGMENT  CHAR(10) NOT NULL,
-                             C_COMMENT     VARCHAR(117) NOT NULL);
-
->   ,CatCreateTable "customer" [("c_custkey", typeInt)
->                              ,("c_name", typeChar)
->                              ,("c_address", typeVarChar)
->                              ,("c_nationkey", typeInt)
->                              ,("c_phone", typeChar)
->                              ,("c_acctbal", typeNumeric)
->                              ,("c_mktsegment", typeChar)
->                              ,("c_comment", typeVarChar)] []
-
-
-CREATE TABLE ORDERS  ( O_ORDERKEY       INTEGER NOT NULL,
-                           O_CUSTKEY        INTEGER NOT NULL,
-                           O_ORDERSTATUS    CHAR(1) NOT NULL,
-                           O_TOTALPRICE     DECIMAL(15,2) NOT NULL,
-                           O_ORDERDATE      DATE NOT NULL,
-                           O_ORDERPRIORITY  CHAR(15) NOT NULL,  
-                           O_CLERK          CHAR(15) NOT NULL, 
-                           O_SHIPPRIORITY   INTEGER NOT NULL,
-                           O_COMMENT        VARCHAR(79) NOT NULL);
-
->   ,CatCreateTable "orders" [("o_orderkey", typeInt)
->                            ,("o_custkey", typeInt)
->                            ,("o_orderstatus", typeChar)
->                            ,("o_totalprice", typeNumeric)
->                            ,("o_orderdate", typeDate)
->                            ,("o_orderpriority", typeChar)
->                            ,("o_clerk", typeChar)
->                            ,("o_shippriority", typeInt)
->                            ,("o_comment", typeVarChar)] []
-
-
-CREATE TABLE LINEITEM ( L_ORDERKEY    INTEGER NOT NULL,
-                             L_PARTKEY     INTEGER NOT NULL,
-                             L_SUPPKEY     INTEGER NOT NULL,
-                             L_LINENUMBER  INTEGER NOT NULL,
-                             L_QUANTITY    DECIMAL(15,2) NOT NULL,
-                             L_EXTENDEDPRICE  DECIMAL(15,2) NOT NULL,
-                             L_DISCOUNT    DECIMAL(15,2) NOT NULL,
-                             L_TAX         DECIMAL(15,2) NOT NULL,
-                             L_RETURNFLAG  CHAR(1) NOT NULL,
-                             L_LINESTATUS  CHAR(1) NOT NULL,
-                             L_SHIPDATE    DATE NOT NULL,
-                             L_COMMITDATE  DATE NOT NULL,
-                             L_RECEIPTDATE DATE NOT NULL,
-                             L_SHIPINSTRUCT CHAR(25) NOT NULL,
-                             L_SHIPMODE     CHAR(10) NOT NULL,
-                             L_COMMENT      VARCHAR(44) NOT NULL);
-
->   ,CatCreateTable "lineitem" [("l_orderkey", typeInt)
->                              ,("l_partkey", typeInt)
->                              ,("l_suppkey", typeInt)
->                              ,("l_linenumber", typeInt)
->                              ,("l_quantity", typeNumeric)
->                              ,("l_extendedprice", typeNumeric)
->                              ,("l_discount", typeNumeric)
->                              ,("l_tax", typeNumeric)
->                              ,("l_returnflag", typeChar)
->                              ,("l_linestatus", typeChar)
->                              ,("l_shipdate", typeDate)
->                              ,("l_commitdate", typeDate)
->                              ,("l_receiptdate", typeDate)
->                              ,("l_shipinstruct", typeChar)
->                              ,("l_shipmode", typeChar)
->                              ,("l_comment", typeVarChar)] []
-
->   ]
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/CaseExpressions.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/CaseExpressions.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/CaseExpressions.lhs
+++ /dev/null
@@ -1,56 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.CaseExpressions
->     (caseExpressionsTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
->
->
-> caseExpressionsTestData :: Item
-> caseExpressionsTestData =
->   Group "case expressions" [
->       e "case\n\
->         \ when true then 1\n\
->         \end" $ Right typeInt
->      ,e "case\n\
->         \ when 1=2 then 'stuff'\n\
->         \ when 2=3 then 'blah'\n\
->         \ else 'test'\n\
->         \end" $ Right UnknownType
->      ,e "case\n\
->         \ when 1=2 then 'stuff'\n\
->         \ when 2=3 then 'blah'\n\
->         \ else 'test'::text\n\
->         \end" $ Right $ ScalarType "text"
->      ,e "case\n\
->         \ when 1=2 then 'stuff'\n\
->         \ when true=3 then 'blah'\n\
->         \ else 'test'\n\
->         \end" $ Left [NoMatchingOperator "=" [typeBool,typeInt]]
->      ,e "case\n\
->         \ when 1=2 then true\n\
->         \ when 2=3 then false\n\
->         \ else 1\n\
->         \end" $ Left [IncompatibleTypeSet [typeBool
->                                         ,typeBool
->                                         ,typeInt]]
->      ,e "case\n\
->         \ when 1=2 then false\n\
->         \ when 2=3 then 1\n\
->         \ else true\n\
->         \end" $ Left [IncompatibleTypeSet [typeBool
->                                           ,typeInt
->                                           ,typeBool]]
->      ,e "case 1 when 2 then 3 else 4 end" $ Right typeInt
->      ,e "case 1 when true then 3 else 4 end"
->             $ Left [IncompatibleTypeSet [ScalarType "int4"
->                                          ,ScalarType "bool"]]
->      ,e "case 1 when 2 then true else false end" $ Right typeBool
->      ,e "case 1 when 2 then 3 else false end"
->             $ Left [IncompatibleTypeSet [ScalarType "int4"
->                                          ,ScalarType "bool"]]
->      ]
->  where
->    e = Expr
-
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/CatalogChaining.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/CatalogChaining.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/CatalogChaining.lhs
+++ /dev/null
@@ -1,34 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.CatalogChaining
->     (tcCatalogChainingTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
->
-
-> tcCatalogChainingTestData :: Item
-> tcCatalogChainingTestData =
->   Group "check catalog chaining" [
->
->     -- create function then select
->     -- select then create function
->     -- then in two separate chained asts
->
->       s "create function t1() returns void as $$\n\
->         \begin\n\
->         \  null;\n\
->         \end;\n\
->         \$$ language plpgsql stable;\n\
->         \select t1();"
->         (Right [Nothing,Just ([], [])])
->      ,s "select t1();\n\
->         \create function t1() returns void as $$\n\
->         \begin\n\
->         \  null;\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         (Left [NoMatchingOperator "t1" []])
->   ]
->  where
->    s = StmtType
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/CombineSelects.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/CombineSelects.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/CombineSelects.lhs
+++ /dev/null
@@ -1,42 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.CombineSelects
->     (tcCombineSelectsTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
->
-> tcCombineSelectsTestData :: Item
-> tcCombineSelectsTestData =
->   Group "combine selects" [
->      s "select 1,2  union select '3', '4';" $ Right [Just ([],
->                                      [("?column?", typeInt)
->                                      ,("?column?", typeInt)])]
->      ,s "select 1,2 intersect select 'a', true;" $ Left [IncompatibleTypeSet [typeInt
->                                                         ,typeBool]]
->      ,s "select '3', '4' except select 1,2;" $ Right [Just ([],
->                                      [("?column?", typeInt)
->                                      ,("?column?", typeInt)])]
->      ,s "select 'a', true union select 1,2;"
->                                      $ Left [IncompatibleTypeSet [typeBool
->                                                         ,typeInt]]
->      ,s "select 'a'::text, '2'::int2 intersect select '1','2';" $ Right [Just ([],
->                                      [("text", ScalarType "text")
->                                      ,("int2", typeSmallInt)])]
->      ,s "select 1,2,3 except select 1,2;" $ Left [ValuesListsMustBeSameLength]
->      ,s "select '3' as a, '4' as b except select 1,2;" $ Right [Just ([],
->                                      [("a", typeInt)
->                                      ,("b", typeInt)])]
->      --FIXME: withs not working
->      {-,s [here|
->          with a as (select 1 as a1),
->               b as (select * from a)
->               select * from a
->               union select * from b; |]
->          $ Right [Just $ ([],
->                            [("a1", typeInt)])]-}
->      ]
-
->  where
->    s = StmtType
-
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Creates.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Creates.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Creates.lhs
+++ /dev/null
@@ -1,60 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.Creates
->     (tcCreateTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
->
-> import Database.HsSqlPpp.Catalog
-
-> tcCreateTestData :: Item
-> tcCreateTestData =
->   Group "creates" [
->       d "create table t1 (\n\
->         \   a int,\n\
->         \   b text\n\
->         \);"
->         [CatCreateTable "t1" [("a",ScalarType "int4")
->                               ,("b",ScalarType "text")]
->                               [("tableoid", ScalarType "oid")
->                               ,("cmax", ScalarType "cid")
->                               ,("xmax", ScalarType "xid")
->                               ,("cmin", ScalarType "cid")
->                               ,("xmin", ScalarType "xid")
->                               ,("ctid", ScalarType "tid")]]
->      ,d "create type t1 as (\n\
->         \   a int,\n\
->         \   b text\n\
->         \);"
->         [CatCreateComposite "t1" [("a",ScalarType "int4")
->                                   ,("b",ScalarType "text")]]
->
->      ,d "create domain t1 as text;"
->         [CatCreateDomain (DomainType "t1") (ScalarType "text")]
-
->      --fixme: check in domain constraint
->      {-,d "create domain t1 as text check (value in ('a', 'b'));\n\
->         \select 'text'::t1;"
->         [CatCreateDomain (DomainType "t1") (ScalarType "text")]-}
->
->
->      ,d "create view v1 as select * from pg_attrdef;"
->         [CatCreateView "v1" [("adrelid",ScalarType "oid")
->                              ,("adnum",ScalarType "int2")
->                              ,("adbin",ScalarType "pg_node_tree")
->                              ,("adsrc",ScalarType "text")]]
->
->      ,d "create function t1(text) returns text as $$\n\
->         \null;\n\
->         \$$ language sql stable;"
->         [CatCreateFunction FunName "t1" [ScalarType "text"]
->                             (ScalarType "text") False]
->      ,d "create language plpgsql;"
->         [CatCreateFunction FunName "plpgsql_call_handler" [] (Pseudo LanguageHandler) False
->         ,CatCreateFunction FunName "plpgsql_validator" [ScalarType "oid"] (Pseudo Void) False]
->      ]
->
->  where
->    d = Ddl
-
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Delete.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Delete.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Delete.lhs
+++ /dev/null
@@ -1,23 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.Delete
->     (tcDeleteTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
-
-> tcDeleteTestData :: Item
-> tcDeleteTestData =
->   Group "delete" [
->       s "delete from nope;"
->         $ Left [UnrecognisedRelation "nope"]
->      ,s "delete from pg_attrdef where 1=2;"
->         $ Right [Just ([], [])]
->      ,s "delete from pg_attrdef where 1;"
->         $ Left [ExpressionMustBeBool]
->      ,s "delete from pg_attrdef where adsrc='';"
->         $ Right [Just ([], [])]
->      ]
-
->  where
->    s = StmtType
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Drops.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Drops.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Drops.lhs
+++ /dev/null
@@ -1,39 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.Drops
->     (tcDropsTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
->
-> import Database.HsSqlPpp.Catalog
-
---------------------------------------------------------------------------------
-
-
-> tcDropsTestData :: Item
-> tcDropsTestData =
->   Group "drop stuff" [
->       d "create function test(a int) returns void as $$\n\
->         \begin\n\
->         \  null;\n\
->         \end\n\
->         \$$ language plpgsql;"
->         [CatCreateFunction FunName "test" [typeInt] (Pseudo Void) False]
->      ,d "create function test(a int) returns void as $$\n\
->         \begin\n\
->         \  null;\n\
->         \end\n\
->         \$$ language plpgsql;\n\
->         \drop function test(int);"
->         []
->         -- FIXME: this should fail but doesn't
->      ,d "drop function test(int);"
->         []
->      ,d "drop function if exists test(int);"
->         []
->      ]
-
->  where
->    d = Ddl
-
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Insert.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Insert.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Insert.lhs
+++ /dev/null
@@ -1,34 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.Insert
->     (tcInsertTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
-
-> tcInsertTestData :: Item
-> tcInsertTestData =
->   Group "insert" [
->       s "insert into nope (a,b) values (c,d);"
->         $ Left [UnrecognisedRelation "nope"
->                ,UnrecognisedIdentifier "c"
->                ,UnrecognisedIdentifier "d"]
->      ,s "insert into pg_attrdef (adrelid,adnum,adbin,adsrc)\n\
->         \values (1,2, 'a', 'b');"
->         $ Right [Just ([], [])]
->      ,s "insert into pg_attrdef\n\
->         \values (1,2, 'a', 'c');"
->         $ Right [Just ([], [])]
->      ,s "insert into pg_attrdef (hello,adnum,adbin,adsrc)\n\
->         \values (1,2, 'a', 'b');"
->         $ Left [UnrecognisedIdentifier "hello"]
->      ,s "insert into pg_attrdef (adrelid,adnum,adbin,adsrc)\n\
->         \values (1,true, 'a', 'b');"
->         $ Left [IncompatibleTypes (ScalarType "int2") (ScalarType "bool")]
->      ,s "insert into pg_attrdef (adrelid,adnum,adbin,adsrc)\n\
->         \values (1,true, 'a', 'b','c');"
->         $ Left [WrongNumberOfColumns]
->      ]
-
->  where
->    s = StmtType
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Into.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Into.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Into.lhs
+++ /dev/null
@@ -1,113 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.Into
->     (tcIntoTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
-
---------------------------------------------------------------------------------
-
-
-> tcIntoTestData :: Item
-> tcIntoTestData = --fixme: intos need fixing
->   Group "select into" $ drop 1000 [
->       s "insert into pg_attrdef (adrelid,adnum,adbin,adsrc)\n\
->         \values (1,2, 'a', 'b') returning adnum,adbin;"
->         $ Right [Just ([], [("adnum", ScalarType "int2")
->                            ,("adbin", ScalarType "pg_node_tree")])]
->      ,s "update pg_attrdef set adnum = adnum + 1 returning adnum;"
->         $ Right [Just ([], [("adnum", ScalarType "int2")])]
->      ,s "delete from pg_attrdef returning adnum,adbin;"
->         $ Right [Just ([], [("adnum", ScalarType "int2")
->                            ,("adbin", ScalarType "pg_node_tree")])]
->      ,s "create function t1() returns void as $$\n\
->         \declare\n\
->         \  a int;\n\
->         \  b text;\n\
->         \begin\n\
->         \  select adnum,adbin into a,b from pg_attrdef;\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         $ Right [Nothing]
->      ,s "create function t1() returns void as $$\n\
->         \declare\n\
->         \  a int;\n\
->         \  b text;\n\
->         \begin\n\
->         \  select adnum,adbin into b,a from pg_attrdef;\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         $ Left [IncompatibleTypes (ScalarType "text") (ScalarType "int2")
->                ,IncompatibleTypes (ScalarType "int4") (ScalarType "text")]
->      ,s "create function t1() returns void as $$\n\
->         \declare\n\
->         \  a int;\n\
->         \  b text;\n\
->         \begin\n\
->         \  select adnum,adbin into a,c from pg_attrdef;\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         $ Left [UnrecognisedIdentifier "c"]
->      ,s "create function t1() returns void as $$\n\
->         \declare\n\
->         \  a int;\n\
->         \  b text;\n\
->         \begin\n\
->         \  select adnum,adbin into a from pg_attrdef;\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         $ Left [WrongNumberOfColumns]
->      ,s "create function t1() returns void as $$\n\
->         \declare\n\
->         \  r record;\n\
->         \  a int;\n\
->         \  b text;\n\
->         \begin\n\
->         \  select adnum,adbin into r from pg_attrdef;\n\
->         \  a := r.adnum;\n\
->         \  b := r.adbin;\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         $ Right [Nothing]
->      ,s "create function t1() returns void as $$\n\
->         \declare\n\
->         \  r record;\n\
->         \  a int;\n\
->         \  b text;\n\
->         \begin\n\
->         \  select adnum,adbin into r from pg_attrdef;\n\
->         \  a := r.adnum;\n\
->         \  b := r.adsrc;\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         $ Left [UnrecognisedIdentifier "adsrc"]
->      ,s "create function t1() returns void as $$\n\
->         \declare\n\
->         \  r pg_attrdef;\n\
->         \begin\n\
->         \  select * into r from pg_attrdef;\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         $ Right [Nothing]
->      ,s "create function t1() returns void as $$\n\
->         \declare\n\
->         \  r pg_class;\n\
->         \begin\n\
->         \  select adnum,adbin into r from pg_attrdef;\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         $ Left [IncompatibleTypes (NamedCompositeType "pg_class") (AnonymousRecordType [ScalarType "int2",ScalarType "text"])]
->      ,s "create function t1() returns void as $$\n\
->         \declare\n\
->         \  r record;\n\
->         \begin\n\
->         \  select adnum,adbin into r from pg_attrdef;\n\
->         \  select relname into r from pg_class;\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         $ Right [Nothing]
->      ]
->  where
->    s = StmtType
-
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Joins.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Joins.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Joins.lhs
+++ /dev/null
@@ -1,66 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.Joins
->     (tcJoinsTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
-
-> tcJoinsTestData :: Item
-> tcJoinsTestData =
->     Group "simple join selects" [
->       s "select * from (select 1 as a, 2 as b) a\n\
->         \  cross join (select true as c, 4.5 as d) b;"
->         $ Right [Just ([], [("a", typeInt)
->                            ,("b", typeInt)
->                            ,("c", typeBool)
->                            ,("d", typeNumeric)])]
->      ,s "select * from (select 1 as a, 2 as b) a\n\
->         \  inner join (select true as c, 4.5 as d) b on true;"
->         $ Right [Just ([], [("a", typeInt)
->                            ,("b", typeInt)
->                            ,("c", typeBool)
->                            ,("d", typeNumeric)])]
->      ,s "select * from (select 1 as a, 2 as b) a\n\
->         \  inner join (select 1 as a, 4.5 as d) b using(a);"
->         $ Right [Just ([], [("a", typeInt)
->                            ,("b", typeInt)
->                            ,("d", typeNumeric)])]
->      ,s "select * from (select 1 as a, 2 as b) a\n\
->         \ natural inner join (select 1 as a, 4.5 as d) b;"
->         $ Right [Just ([], [("a", typeInt)
->                            ,("b", typeInt)
->                            ,("d", typeNumeric)])]
->         --check the attribute order
->      ,s "select * from (select 2 as b, 1 as a) a\n\
->         \ natural inner join (select 4.5 as d, 1 as a) b;"
->         $ Right [Just ([], [("a", typeInt)
->                            ,("b", typeInt)
->                            ,("d", typeNumeric)])]
->       --fixme: result set compatilibity check
->      {-,s "select * from (select 1 as a1, 2 as b) a\n\
->         \ natural inner join (select true as a1, 4.5 as d) b;"
->         $ Left [UnrecognisedCorrelationName ""
->                ,IncompatibleTypeSet [ScalarType "int4"
->                                     ,ScalarType "bool"]]-}
->       --fixme: result set compatilibity check
->       {-,s "select * from (select 1 as a1, 2 as b) a\n\
->         \ natural inner join (select true as a1, 4.5 as d) b;"
->         $ Left [UnrecognisedCorrelationName ""
->                ,IncompatibleTypeSet [ScalarType "int4"
->                                     ,ScalarType "bool"]]-}
->        ,s "select * from (select 1 as a1) a, (select 2 as a2) b;"
->         $ Right [Just ([], [("a1", typeInt)
->                                            ,("a2", typeInt)])]
->
->        ,s "select * from (select 1 as a1) a, (select 2 as a1) b;"
->         $ Right [Just ([], [("a1", typeInt)
->                                            ,("a1", typeInt)])]
->        --fixme: error detection (fixupids?)
->        {-,s "select a1 from (select 1 as a1) a,  (select 2 as a1) b;"
->         $ Left [AmbiguousIdentifier "a1"]-}
->      ]
-
->  where
->    s = StmtType
-
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Literals.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Literals.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Literals.lhs
+++ /dev/null
@@ -1,25 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.Literals
->     (tcLiteralTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
->
-> tcLiteralTestData :: Item
-> tcLiteralTestData =
->    Group "basic literal types" [
->       e "1" $ Right typeInt
->      ,e "1.0" $ Right typeNumeric
->      ,e "'test'" $ Right UnknownType
->      ,e "true" $ Right typeBool
->      ,e "array[1,2,3]" $ Right (ArrayType typeInt)
->      ,e "array['a','b']" $ Right (ArrayType UnknownType)
->      ,e "array['a'::text,'b']" $ Right (ArrayType (ScalarType "text"))
->      ,e "array['a','b'::text]" $ Right (ArrayType (ScalarType "text"))
->      ,e "array[1,'b']" $ Right (ArrayType typeInt)
->      ,e "array[1,true]" $ Left [NoMatchingOperator "!arrayctor" [ScalarType "int4",ScalarType "bool"]]
->      ]
->  where
->    e = Expr
-
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Misc.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Misc.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Misc.lhs
+++ /dev/null
@@ -1,62 +0,0 @@
-
-Set of tests to check the type checking code. Includes tests for the
-errors for sql which doesn't type check.
-
-> module Database.HsSqlPpp.Tests.TypeChecking.Misc
->     (tcMiscTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
->
-> --import Database.HsSqlPpp.Catalog
-
---------------------------------------------------------------------------------
-
-
-> tcMiscTestData :: Item
-> tcMiscTestData = --fixme
->   Group "misc" [
->   {-Group "composite elements" [
->       s "create function t1() returns void as $$\n\
->         \declare\n\
->         \  r pg_attrdef;\n\
->         \  a int;\n\
->         \  b text;\n\
->         \begin\n\
->         \  b = r.adsrc;\n\
->         \  r.adnum := a;\n\
->         \  b = r.adsrc;\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         $ Right [Nothing]
->      ]-}
-
->   {-,Group "positional args" [
->       s "create function distance(int, int, int, int) returns float(24) as $$\n\
->         \  select (point($1, $2) <-> point($3, $4))::float(24) as result;\n\
->         \$$ language sql immutable;"
->         $ Right [Nothing]
->      ,s "create function distance(int, int, int, int) returns float(24) as $$\n\
->         \  select (point($1, $2) <-> point($3, $5))::float(24) as result;\n\
->         \$$ language sql immutable;"
->         $ Left [UnrecognisedIdentifier "$5"]
->      ]
-
->   ,-}Group "window fns" [
->       s "select *, row_number() over () from pg_attrdef;"
->         $ Right [Just ([],
->                   [("adrelid",ScalarType "oid")
->                   ,("adnum",ScalarType "int2")
->                   ,("adbin",ScalarType "pg_node_tree")
->                   ,("adsrc",ScalarType "text")
->                   ,("row_number",ScalarType "int8")])]
->      ]
->   ]
-
->  where
->    --e = Expr
->    s = StmtType
->    --c = CatStmtType
->    --d = Ddl
-
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/MiscExpressions.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/MiscExpressions.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/MiscExpressions.lhs
+++ /dev/null
@@ -1,63 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.MiscExpressions
->     (miscExpressionsTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
->
->
-> miscExpressionsTestData :: Item
-> miscExpressionsTestData =
->   Group "misc expressions" [
-
-~~~~
-implicit casting and function/operator choice tests:
-check when multiple implicit and one exact match on num args
-check multiple matches with num args, only one with implicit conversions
-check multiple implicit matches with one preferred
-check multiple implicit matches with one preferred highest count
-check casts from unknown string lits
-~~~~
-
->   Group "some expressions" [
->       e "3 + '4'" $ Right typeInt
->      ,e "3.0 + '4'" $ Right typeNumeric
->      ,e "'3' + '4'" $ Left [NoMatchingOperator "+" [UnknownType
->                                                    ,UnknownType]]
->      ]
->   ,Group "exists expressions" [
->       e "exists (select 1 from pg_type)" $ Right typeBool
->      ,e "exists (select testit from pg_type)"
->        $ Left [UnrecognisedIdentifier "testit"]
->      ]
-
->   ,Group "polymorphic functions" [
->       e "array_append(ARRAY[1,2], 3)"
->         $ Right (ArrayType typeInt)
->      ,e "array_append(ARRAY['a','b'], 'c')"
->         $ Right (ArrayType UnknownType)
->      ,e "array_append(ARRAY['a','b'], 'c'::text)"
->         $ Right (ArrayType $ ScalarType "text")
->      ,e "array_append(ARRAY['a','b'::text], 'c')"
->         $ Right (ArrayType $ ScalarType "text")
->      ,e "array_append(ARRAY['a'::int,'b'], 'c')"
->         $ Right (ArrayType typeInt)
->      ]
-
->   ,Group "cast expressions" [
->       e "cast ('1' as integer)"
->         $ Right typeInt
->      ,e "cast ('1' as baz)"
->         $ Left [UnknownTypeName "baz"]
->      ,e "array[]" -- FIXME: this isn't quite right but not sure how to do it atm
->                   -- no point fixing this case since need a load of other
->                   -- test cases where the behaviour is different
->         $ Right (Pseudo AnyArray) -- Left [TypelessEmptyArray]
->      ,e "array[] :: text[]"
->         $ Right (ArrayType (ScalarType "text"))
->      ]
-
->      ]
->  where
->    e = Expr
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/MiscSelects.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/MiscSelects.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/MiscSelects.lhs
+++ /dev/null
@@ -1,83 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.MiscSelects
->     (tcMiscSelectTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
-> import Database.HsSqlPpp.Catalog
-
-> tcMiscSelectTestData :: Item
-> tcMiscSelectTestData =
->   Group "misc selects" [
->   Group "aggregates" [
->        s "select max(prorettype::int) from pg_proc;"
->         $ Right [Just ([], [("max", typeInt)])]
->      ]
-
->   ,Group "simple wheres" [
->       s "select 1 from pg_type where true;"
->         $ Right [Just ([], [("?column?", typeInt)])]
->      ,s "select 1 from pg_type where 1;"
->         $ Left [ExpressionMustBeBool]
->      ,s "select typname from pg_type where typbyval;"
->         $ Right [Just ([], [("typname", ScalarType "name")])]
->      ,s "select typname from pg_type where typtype = 'b';"
->         $ Right [Just ([], [("typname", ScalarType "name")])]
->      ,s "select typname from pg_type where what = 'b';"
->         $ Left [UnrecognisedIdentifier "what"]
->      ]
-
->   ,Group "unnest" [
->       s "select conname,unnest(conkey) as attnum from pg_constraint;"
->         $ Right [Just ([], [("conname",ScalarType "name")
->                                          ,("attnum",typeSmallInt)])]
->      ]
-
-TODO: check identifier stacking working, then remove the pg_namespace
-qualifier before oid and this should still work
-
->   ,Group "subqueries" [
->       s "select relname as relvar_name\n\
->         \    from pg_class\n\
->         \    where ((relnamespace =\n\
->         \           (select oid\n\
->         \              from pg_namespace\n\
->         \              where (nspname = 'public'))) and (relkind = 'r'));"
->         $ Right [Just ([], [("relvar_name",ScalarType "name")])]
->      ,s "select relname from pg_class where relkind in ('r', 'v');"
->         $ Right [Just ([], [("relname",ScalarType "name")])]
->      ,s "select * from generate_series(1,7) g\n\
->         \where g not in (select * from generate_series(3,5));"
->         $ Right [Just ([], [("g",typeInt)])]
->      ,s "select * from generate_series(3,5);"
->         $ Right [Just ([], [("generate_series",typeInt)])]
->      ,s "select * from generate_series(1,7) g\n\
->         \where g not in (1,2);"
->         $ Right [Just ([], [("g",typeInt)])]
-
->      ,s "select 3 = any(array[1,2,3]);"
->         $ Right [Just ([], [("?column?",typeBool)])]
->      ,c "select b.t,b.u from a,b where a.t = b.t\n\
->         \ and b.u = (select min(b.u) from b where a.t = b.t);"
->         [CatCreateTable "a" [("t", typeInt)] []
->         ,CatCreateTable "b" [("t", typeInt)
->                             ,("u", typeNumeric)] []]
->         $ Right [Just ([], [("t", typeInt)
->                            ,("u", typeNumeric)])]
->      ]
->
->  -- identifiers in select parts
->     ,Group "select part identifiers" [
->       s "select relname as relvar_name,attname as name from pg_class\n\
->         \inner join pg_attribute\n\
->         \on pg_attribute.attrelid = pg_class.oid;"
->         $ Right [Just ([], [("relvar_name",ScalarType "name")
->                            ,("name",ScalarType "name")])]
->      ]
->   ]
-
-
->  where
->    s = StmtType
->    c = CatStmtType
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Plpgsql.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Plpgsql.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Plpgsql.lhs
+++ /dev/null
@@ -1,179 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.Plpgsql
->     (tcPlpgsqlTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
-
---------------------------------------------------------------------------------
-
-~~~~
-check the identifier resolution for functions:
-parameters
-variable declarations
-select expressions inside these:
-refer to param
-refer to variable
-override var with var
-override var with select iden
-todo: override var with param, override select iden with param
-
-check var defs:
-check type exists
-check type of initial values
-
-
-> tcPlpgsqlTestData :: Item
-> tcPlpgsqlTestData = --fixme: plpgsql ids
->   Group "plpgsql" $ drop 1000 [
->   Group "create function param resolution" [
->       s "create function t1(stuff text) returns text as $$\n\
->         \begin\n\
->         \  return stuff || ' and stuff';\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         (Right [Nothing])
->      ,s "create function t1(stuff text) returns text as $$\n\
->         \begin\n\
->         \  return badstuff || ' and stuff';\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         (Left [UnrecognisedIdentifier "badstuff"])
->      ,s "create function t1() returns text as $$\n\
->         \declare\n\
->         \  stuff text;\n\
->         \begin\n\
->         \  return stuff || ' and stuff';\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         (Right [Nothing])
->      ]
-
-
---------------------------------------------------------------------------------
-
->   ,Group "plpgsqlbits" [
->       s "create function t1(stuff text) returns text as $$\n\
->         \begin\n\
->         \  return stuff || ' and stuff';\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         (Right [Nothing])
->      ,s "create function t1(stuff text) returns text as $$\n\
->         \begin\n\
->         \  return badstuff || ' and stuff';\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         (Left [UnrecognisedIdentifier "badstuff"])
->      ,s "create function t1() returns text as $$\n\
->         \declare\n\
->         \  stuff text;\n\
->         \begin\n\
->         \  return stuff || ' and stuff';\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         (Right [Nothing])
->      ,s "create function t1() returns void as $$\n\
->         \declare\n\
->         \  a bool;\n\
->         \begin\n\
->         \  a := 3;\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         (Left [IncompatibleTypes (ScalarType "bool") (ScalarType "int4")])
->      ,s "create function t1() returns void as $$\n\
->         \declare\n\
->         \  a boolean;\n\
->         \begin\n\
->         \  a := true;\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         (Right [Nothing])
->      ]
-
---------------------------------------------------------------------------------
-
->   ,Group "for loops" [
->       s "create function t1() returns void as $$\n\
->         \declare\n\
->         \  r record;\n\
->         \  t int;\n\
->         \begin\n\
->         \  for r in select * from pg_attrdef loop\n\
->         \    t := r.adnum;\n\
->         \  end loop;\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         (Right [Nothing])
->
->
->      {-,s "create function t1() returns void as $$\n\
->         \declare\n\
->         \  r record;\n\
->         \  t int;\n\
->         \begin\n\
->         \  for r in select adnum from pg_attrdef loop\n\
->         \    t := r;\n\
->         \  end loop;\n\
->         \end;\n\
->         \$$ language plpgsql stable;"
->         (Right [Nothing])-}
->
->       -- loop var already declared
->
->      ,s "create function test() returns void as $$\n\
->         \declare\n\
->         \  i int;\n\
->         \  i1 int;\n\
->         \begin\n\
->         \  for i in 0 .. 10 loop\n\
->         \    i1 := i;\n\
->         \  end loop;\n\
->         \end;\n\
->         \$$ language plpgsql volatile;"
->        (Right [Nothing])
->
->        --implicitly created loop var
->
->      ,s "create function test() returns void as $$\n\
->         \declare\n\
->         \  i1 int;\n\
->         \begin\n\
->         \  for i in 0 .. 10 loop\n\
->         \    i1 := i;\n\
->         \  end loop;\n\
->         \end;\n\
->         \$$ language plpgsql volatile;"
->        (Right [Nothing])
->
->        --loop var already declared, wrong type
->
->      ,s "create function test() returns void as $$\n\
->         \declare\n\
->         \  i bool;\n\
->         \begin\n\
->         \  for i in 0 .. 10 loop\n\
->         \    null;\n\
->         \  end loop;\n\
->         \end;\n\
->         \$$ language plpgsql volatile;"
->        (Left [IncompatibleTypes (ScalarType "bool") (ScalarType "int4")])
->
->       --loop var implicit check it's type
->
->      ,s "create function test() returns void as $$\n\
->         \declare\n\
->         \  t bool;\n\
->         \begin\n\
->         \  for i in 0 .. 10 loop\n\
->         \    t := i;\n\
->         \  end loop;\n\
->         \end;\n\
->         \       $$ language plpgsql volatile;"
->         (Left [IncompatibleTypes (ScalarType "bool") (ScalarType "int4")])
->      ]
->      ]
->  where
->    s = StmtType
-
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Qualification.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Qualification.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Qualification.lhs
+++ /dev/null
@@ -1,47 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.Qualification
->     (tcQualificationTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
-
-> tcQualificationTestData :: Item
-> tcQualificationTestData =
->   Group "simple scalar identifier qualification" [
->       s "select a.* from \n\
->         \(select 1 as a, 2 as b) a \n\
->         \cross join (select 3 as c, 4 as d) b;"
->         $ Right [Just ([], [("a", typeInt)
->                            ,("b", typeInt)])]
->      {-,s "select nothere.* from \n\
->         \(select 1 as a, 2 as b) a \n\
->         \cross join (select 3 as c, 4 as d) b;"
->         $ Left [UnrecognisedCorrelationName "nothere"]-}
->      ,s "select a.b,b.c from \n\
->         \(select 1 as a, 2 as b) a \n\
->         \natural inner join (select 3 as a, 4 as c) b;"
->         $ Right [Just ([], [("b", typeInt)
->                            ,("c", typeInt)])]
->        ,s "select a.a,b.a from \n\
->         \(select 1 as a, 2 as b) a \n\
->         \natural inner join (select 3 as a, 4 as c) b;"
->         $ Right [Just ([], [("a", typeInt)
->                            ,("a", typeInt)])]
->      ,s "select pg_attrdef.adsrc from pg_attrdef;"
->         $ Right [Just ([], [("adsrc", ScalarType "text")])]
->
->      ,s "select a.adsrc from pg_attrdef a;"
->         $ Right [Just ([], [("adsrc", ScalarType "text")])]
->
->      ,s "select pg_attrdef.adsrc from pg_attrdef a;"
->         $ Left [UnrecognisedCorrelationName "pg_attrdef"]
->
->      ,s "select a from (select 2 as b, 1 as a) a\n\
->         \natural inner join (select 4.5 as d, 1 as a) b;"
->         $ Right [Just ([], [("a", typeInt)])]
->
->      ]
-
->  where
->    s = StmtType
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/RowCtors.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/RowCtors.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/RowCtors.lhs
+++ /dev/null
@@ -1,52 +0,0 @@
-
-Set of tests to check the type checking code. Includes tests for the
-errors for sql which doesn't type check.
-
-> module Database.HsSqlPpp.Tests.TypeChecking.RowCtors
->     (tcRowCtorsTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
->
->
-> tcRowCtorsTestData :: Item
-> tcRowCtorsTestData =
->   Group "row comparison expressions" [
-
-~~~~
-rows different lengths
-rows match types pairwise, same and different types
-rows implicit cast from unknown
-rows don't match types
-~~~~
-
->       e "row(1)" $ Right (AnonymousRecordType [typeInt])
->      ,e "row(1,2)" $ Right (AnonymousRecordType [typeInt,typeInt])
->      ,e "row('t1','t2')" $ Right (AnonymousRecordType [UnknownType,UnknownType])
->      ,e "row(true,1,'t3')" $ Right (AnonymousRecordType [typeBool, typeInt,UnknownType])
->      ,e "(true,1,'t3',75.3)" $ Right (AnonymousRecordType [typeBool,typeInt
->                                       ,UnknownType,typeNumeric])
->      ,e "row(1) = row(2)" $ Right typeBool
->      ,e "row(1,2) = row(2,1)" $ Right typeBool
->      ,e "(1,2) = (2,1)" $ Right typeBool
->      ,e "(1,2,3) = (2,1)" $ Left [NoMatchingOperator "="
->                                   [AnonymousRecordType [ScalarType "int4"
->                                                        ,ScalarType "int4"
->                                                        ,ScalarType "int4"]
->                                    ,AnonymousRecordType [ScalarType "int4"
->                                                         ,ScalarType "int4"]]]
->      ,e "('1',2) = (2,'1')" $ Right typeBool
->      ,e "(1,true) = (2,1)" $ Left [NoMatchingOperator "="
->                                    [AnonymousRecordType [ScalarType "int4"
->                                                         ,ScalarType "bool"]
->                                    ,AnonymousRecordType [ScalarType "int4"
->                                                         ,ScalarType "int4"]]]
->      ,e "(1,2) <> (2,1)" $ Right typeBool
->      ,e "(1,2) >= (2,1)" $ Right typeBool
->      ,e "(1,2) <= (2,1)" $ Right typeBool
->      ,e "(1,2) > (2,1)" $ Right typeBool
->      ,e "(1,2) < (2,1)" $ Right typeBool
->      ]
->  where
->    e = Expr
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/SelectFrom.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/SelectFrom.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/SelectFrom.lhs
+++ /dev/null
@@ -1,77 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.SelectFrom
->     (tcSelectFromTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
->
-> import Database.HsSqlPpp.Catalog
-
-> tcSelectFromTestData :: Item
-> tcSelectFromTestData =
->   Group "selects from" [
->   Group "simple selects from" [
->       s "select a from (select 1 as a, 2 as b) x;"
->         $ Right [Just ([], [("a", typeInt)])]
->      ,s "select b from (select 1 as a, 2 as b) x;"
->         $ Right [Just ([], [("b", typeInt)])]
->      ,s "select c from (select 1 as a, 2 as b) x;"
->         $ Left [UnrecognisedIdentifier "c"]
->      ,s "select typlen from pg_type;"
->         $ Right [Just ([], [("typlen", typeSmallInt)])]
->      ,s "select oid from pg_type;"
->         $ Right [Just ([], [("oid", ScalarType "oid")])]
->      ,s "select p.oid from pg_type p;"
->         $ Right [Just ([], [("oid", ScalarType "oid")])]
->      ,s "select typlen from nope;"
->         $ Left [UnrecognisedRelation "nope"]
->      ,s "select generate_series from generate_series(1,7);"
->         $ Right [Just ([], [("generate_series", typeInt)])]
->
->      -- check aliasing
->      ,s "select generate_series.generate_series from generate_series(1,7);"
->         $ Right [Just ([], [("generate_series", typeInt)])]
->      ,s "select g from generate_series(1,7) g;"
->         $ Right [Just ([], [("g", typeInt)])]
->      ,s "select g.g from generate_series(1,7) g;"
->         $ Right [Just ([], [("g", typeInt)])]
->      ,s "select generate_series.g from generate_series(1,7) g;"
->         $ Left [UnrecognisedCorrelationName "generate_series"]
->      ,s "select g.generate_series from generate_series(1,7) g;"
->         $ Left [UnrecognisedIdentifier "generate_series"]
->
->      ,s "select * from pg_attrdef;"
->         $ Right [Just ([],
->          [("adrelid",ScalarType "oid")
->          ,("adnum",ScalarType "int2")
->          ,("adbin",ScalarType "pg_node_tree")
->          ,("adsrc",ScalarType "text")])]
->      ,s "select abs from abs(3);"
->         $ Right [Just ([], [("abs", typeInt)])]
->         --todo: these are both valid,
->         --the second one means select 3+generate_series from generate_series(1,7)
->         --  select generate_series(1,7);
->         -- select 3 + generate_series(1,7);
->      ]
-
->   ,Group "simple selects from 2" [
->       -- fixme: needs compfuntref?
->       {-c "select a,b from testfunc();"
->         [CatCreateComposite "testType" [("a", ScalarType "text")
->                                        ,("b", typeInt)
->                                        ,("c", typeInt)]
->         ,CatCreateFunction FunName "testfunc" []
->          (SetOfType $ NamedCompositeType "testType") False]
->         $ Right [Just ([],
->                  [("a",ScalarType "text"),("b",ScalarType "int4")])]
->
->      ,-}c "select testfunc();"
->         [CatCreateFunction FunName "testfunc" [] (Pseudo Void) False]
->         $ Right [Just ([], [])]
->      ]
->   ]
-
->  where
->    s = StmtType
->    c = CatStmtType
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/SimpleExpressions.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/SimpleExpressions.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/SimpleExpressions.lhs
+++ /dev/null
@@ -1,73 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.SimpleExpressions
->     (tcSimpleExpressionTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
->
->
-> tcSimpleExpressionTestData :: Item
-> tcSimpleExpressionTestData =
->    Group "simple expressions" [
->       e "1=1" $ Right typeBool
->      ,e "1=true" $ Left [NoMatchingOperator "=" [typeInt,typeBool]]
->      ,e "substring('aqbc' from 2 for 2)" $ Right (ScalarType "text")
->
->      ,e "substring(3 from 2 for 2)" $ Left
->                                      [NoMatchingOperator "!substring"
->                                       [ScalarType "int4"
->                                       ,ScalarType "int4"
->                                       ,ScalarType "int4"]]
->      ,e "substring('aqbc' from 2 for true)" $ Left
->                     [NoMatchingOperator "!substring"
->                      [UnknownType
->                      ,ScalarType "int4"
->                      ,ScalarType "bool"]]
->
->      ,e "3 between 2 and 4" $ Right typeBool
->      ,e "3 between true and 4" $ Left
->                                [IncompatibleTypeSet [ScalarType "int4"
->                                                     ,ScalarType "bool"
->                                                     ,ScalarType "int4"]]
->
->      ,e "array[1,2,3][2]" $ Right typeInt
->      ,e "array['a','b'][1]" $ Right UnknownType
->      ,e "array['a'::text,'b'][1]" $ Right (ScalarType "text")
->         -- FIXME?
->      {-,p "array['a','b'][true]" (TypeError ("",0,0)
->                                   (WrongType
->                                    typeInt
->                                    UnknownType))-}
->      ,e "not true" $ Right typeBool
->      ,e "not 1" $ Left
->                  [NoMatchingOperator "!not" [typeInt]]
->
->      ,e "@ 3" $ Right typeInt
->      ,e "@ true" $ Left
->                  [NoMatchingOperator "@" [ScalarType "bool"]]
->
->      ,e "-3" $ Right typeInt
->      ,e "-'a'" $ Left
->                  [NoMatchingOperator "-" [UnknownType]]
->
->      ,e "4-3" $ Right typeInt
->
->      ,e "1 is null" $ Right typeBool
->      ,e "1 is not null" $ Right typeBool
->
->      ,e "1+1" $ Right typeInt
->      ,e "1+1" $ Right typeInt
->      ,e "31*511" $ Right typeInt
->      ,e "5/2" $ Right typeInt
->      ,e "2^10" $ Right typeFloat8
->      ,e "17%5" $ Right typeInt
->      ,e "3 and 4" $ Left
->                   [NoMatchingOperator "!and" [typeInt,typeInt]]
->      ,e "True and False" $ Right typeBool
->      ,e "false or true" $ Right typeBool
->      ,e "lower('TEST')" $ Right (ScalarType "text")
->      ,e "lower(1)" $ Left [NoMatchingOperator "lower" [typeInt]]
->      ]
->  where
->    e = Expr
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/SimpleSelects.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/SimpleSelects.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/SimpleSelects.lhs
+++ /dev/null
@@ -1,44 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.SimpleSelects
->     (tcSimpleSelectsTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
->
->
-> tcSimpleSelectsTestData :: Item
-> tcSimpleSelectsTestData =
->   Group "simple selects" [
->       s "select 1;" $ Right [Just ([], [("?column?", typeInt)])]
->      ,s "select 1 as a;" $
->         Right [Just ([], [("a", typeInt)])]
->      ,s "select 1,2;" $
->         Right [Just ([], [("?column?", typeInt)
->                                                 ,("?column?", typeInt)])]
->      ,s "select 1 as a, 2 as b;" $
->         Right [Just ([], [("a", typeInt)
->                                                 ,("b", typeInt)])]
->      ,s "select 1+2 as a, 'a' || 'b';" $
->         Right [Just ([], [("a", typeInt)
->                                        ,("?column?", ScalarType "text")])]
->      ,s "values (1,2);" $ Right [Just ([],
->                                           [("column1", typeInt)
->                                           ,("column2", typeInt)])]
->      ,s "values (1,2),('3', '4');" $ Right [Just ([],
->                                                      [("column1", typeInt)
->                                                      ,("column2", typeInt)])]
->      ,s "values (1,2),('a', true);" $ Left [IncompatibleTypeSet [typeInt
->                                                                 ,typeBool]]
->      ,s "values ('3', '4'),(1,2);" $ Right [Just ([],
->                                                      [("column1", typeInt)
->                                                      ,("column2", typeInt)])]
->      ,s "values ('a', true),(1,2);" $ Left [IncompatibleTypeSet [typeBool
->                                                                 ,typeInt]]
->      ,s "values ('a'::text, '2'::int2),('1','2');" $ Right [Just ([],
->                                      [("column1", ScalarType "text")
->                                      ,("column2", typeSmallInt)])]
->      ,s "values (1,2,3),(1,2);" $ Left [ValuesListsMustBeSameLength]
->      ]
->  where
->    s = StmtType
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/SpecialFunctions.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/SpecialFunctions.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/SpecialFunctions.lhs
+++ /dev/null
@@ -1,32 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.SpecialFunctions
->     (tcSpecialFunctionsTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
->
->
-> tcSpecialFunctionsTestData :: Item
-> tcSpecialFunctionsTestData =
->   Group "special functions" [
->       e "coalesce(null,1,2,null)" $ Right typeInt
->      ,e "coalesce('3',1,2,null)" $ Right typeInt
->      ,e "coalesce('3',1,true,null)"
->             $ Left [NoMatchingOperator "coalesce" [UnknownType
->                                                   ,ScalarType "int4"
->                                                   ,ScalarType "bool"
->                                                   ,UnknownType]]
->      ,e "nullif('hello','hello')" $ Right UnknownType
->      ,e "nullif('hello'::text,'hello')" $ Right (ScalarType "text")
->      ,e "nullif(3,4)" $ Right typeInt
->      ,e "nullif(true,3)"
->             $ Left [NoMatchingOperator "nullif" [ScalarType "bool"
->                                           ,ScalarType "int4"]]
->      ,e "greatest(3,5,6,4,3)" $ Right typeInt
->      ,e "least(3,5,6,4,3)" $ Right typeInt
->      ,e "least(5,true)"
->             $ Left [NoMatchingOperator "least" [ScalarType "int4",ScalarType "bool"]]
->      ]
->  where
->    e = Expr
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/TableRefTests.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/TableRefTests.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/TableRefTests.lhs
+++ /dev/null
@@ -1,136 +0,0 @@
-Test the type checking and errors within tablerefs
-and test the produced simple select lists
-
-> module Database.HsSqlPpp.Tests.TypeChecking.TableRefTests
->     (tableRefTests
->     --,tableRefTestData
->     --,Item(..)
->     ) where
->
-> import Test.HUnit
-> import Test.Framework
-> import Test.Framework.Providers.HUnit
-> --import Data.List
-> import Data.Generics.Uniplate.Data
-> import Control.Monad
-> import Text.Groom
->
-> --import Database.HsSqlPpp.Utils.Here
-> import Database.HsSqlPpp.Parser
-> import Database.HsSqlPpp.TypeChecker
-> import Database.HsSqlPpp.Annotation
-> import Database.HsSqlPpp.Catalog
-> import Database.HsSqlPpp.Types
-> --import Database.HsSqlPpp.Utils.PPExpr
-> --import Database.HsSqlPpp.Tests.TestUtils
-> import Database.HsSqlPpp.Pretty
->
-> data Item = Group String [Item]
->           | Query [CatalogUpdate] String (Either [TypeError] Type)
->
-> tableRefTests :: Test.Framework.Test
-> tableRefTests = itemToTft tableRefTestData
->
-> tableRefTestData :: Item
-> tableRefTestData = Group "tableRefs"
->   [Query db1 "select * from t;"
->      $ Right $ SetOfType $ CompositeType
->         [("a",typeInt)
->         ,("b",typeInt)]
->   ,Query db1 "select a,b from t;"
->      $ Right $ SetOfType $ CompositeType
->         [("a",typeInt)
->         ,("b",typeInt)]
->   ,Query db1 "select t.* from t;"
->      $ Right $ SetOfType $ CompositeType
->         [("a",typeInt)
->         ,("b",typeInt)]
->   {-,Query db1 "select u.* from t;"
->      $ Left [UnrecognisedCorrelationName "u"]-}
->   ,Query db1 "select * from t u;"
->      $ Right $ SetOfType $ CompositeType
->         [("a",typeInt)
->         ,("b",typeInt)]
->   ,Query db1 "select * from t u(c,d);"
->      $ Right $ SetOfType $ CompositeType
->         [("c",typeInt)
->         ,("d",typeInt)]
->   ,Query db1 "select u.* from t u(c,d);"
->      $ Right $ SetOfType $ CompositeType
->         [("c",typeInt)
->         ,("d",typeInt)]
->   ,Query db1 "select c,d from t u(c,d);"
->      $ Right $ SetOfType $ CompositeType
->         [("c",typeInt)
->         ,("d",typeInt)]
->   {-,Query db1 "select t.* from t u;"
->      $ Left [UnrecognisedCorrelationName "t"]-}
->   -- FIXME: disabled because the error comes out twice, and I can't work out why
->   -- this problem occurs in the uuagc code so it is probably the ag code which is wrong
->   {-,Query db1 "select * from t u(a);"
->      $ Left [WrongNumberOfAliasCols 2 1]-}
->   ,Query db1 "select c from t;"
->      $ Left [UnrecognisedIdentifier "c"]
->   ,Query db1 "select a from t u(c,d);"
->      $ Left [UnrecognisedIdentifier "a"]
->   ,Query db1 "select * from non;"
->      $ Left [UnrecognisedRelation "non"]
->   ,Query db1 "select a,b,d from t,u where a=c;"
->      $ Right $ SetOfType $ CompositeType
->         [("a",typeInt)
->         ,("b",typeInt)
->         ,("d",typeInt)]
->   ]
-
-table ref tests:
-
-columns in:
-tref, subtref, funtref
-jointref: aliased, unaliased, 3 way
-
-select lists:
-simple, qualified, *, q.*
-
-
-errors:
-unrecognised id
-ambiguous id
-incompatible join columns
-unrecognised relation
-missing join attribute
-
-
-
-
-> db1 :: [CatalogUpdate]
-> db1 = [CatCreateTable "t" [("a",typeInt)
->                           ,("b", typeInt)] []
->       ,CatCreateTable "u" [("c",typeInt)
->                           ,("d", typeInt)] []
->       ,CatCreateTable "v" [("v",typeInt)] []]
-
-> itemToTft :: Item -> Test.Framework.Test
-> itemToTft (Group s is) = testGroup s $ map itemToTft is
-> itemToTft (Query eu sql t) = testCase ("typecheck " ++ sql) $ do
->   let ast = case parseQueryExpr "" sql of
->               Left e -> error $ show e
->               Right l -> l
->       aast = typeCheckQueryExpr cat ast
->       ty = atype $ getAnnotation aast
->       er :: [TypeError]
->       er = universeBi aast
->       res = if null er
->             then case ty of
->                    Nothing -> Left []
->                    Just ty' -> Right ty'
->             else Left er
->   when (t /= res) $ putStrLn $ "bad sql: " ++ printQueryExpr aast
->        ++ "\n" ++ groom aast
->   assertEqual "" t res
->   where
->     cat = case updateCatalog defaultTemplate1Catalog eu of
->                         Left x -> error $ show x
->                         Right e -> e
-
-
-
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/TpchTests.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/TpchTests.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/TpchTests.lhs
+++ /dev/null
@@ -1,168 +0,0 @@
-
-Tests using the tpch queries. Just tests the result type at the
-moment.
-
-> module Database.HsSqlPpp.Tests.TypeChecking.TpchTests
->     (tpchTests) where
->
-> import Test.HUnit
-> import Test.Framework
-> import Test.Framework.Providers.HUnit
-> --import Data.List
-> import Data.Generics.Uniplate.Data
-> import Control.Monad
-> --import Text.Groom
->
-> --import Database.HsSqlPpp.Utils.Here
-> import Database.HsSqlPpp.Parser
-> import Database.HsSqlPpp.TypeChecker
-> import Database.HsSqlPpp.Annotation
-> import Database.HsSqlPpp.Catalog
-> import Database.HsSqlPpp.Types
-> --import Database.HsSqlPpp.Utils.PPExpr
-> --import Database.HsSqlPpp.Tests.TestUtils
-> import Database.HsSqlPpp.Pretty
-> import Database.HsSqlPpp.Tests.TpchData
->
-> data Item = Group String [Item]
->           | Query String String Type
->
-> tpchTests :: Test.Framework.Test
-> tpchTests = itemToTft tpchTestData
->
-> tpchTestData :: Item
-> tpchTestData =
->   Group "tpch" $
->         -- FIXME: 15 has with expression which doesn't quite work atm
->         -- (todo with fixup identifiers I think
->         let (s,e) = splitAt 14 t
->         in s ++ drop 1 e
->   where
->     t = zipWith (\(n,s) t' ->  Query n s (SetOfType $ CompositeType t'))
->          tpchQueries
->          [-- q1
->           [("l_returnflag", typeChar)
->           ,("l_linestatus", typeChar)
->           ,("sum_qty", typeNumeric)
->           ,("sum_base_price", typeNumeric)
->           ,("sum_disc_price", typeNumeric)
->           ,("sum_charge", typeNumeric)
->           ,("avg_qty", typeNumeric)
->           ,("avg_price", typeNumeric)
->           ,("avg_disc", typeNumeric)
->           ,("count_order", typeBigInt)]
->          ,--q2
->           [("s_acctbal", typeNumeric)
->           ,("s_name", typeChar)
->           ,("n_name", typeChar)
->           ,("p_partkey", typeInt)
->           ,("p_mfgr", typeChar)
->           ,("s_address", typeVarChar)
->           ,("s_phone", typeChar)
->           ,("s_comment", typeVarChar)]
->          ,--q3
->           [("l_orderkey", typeInt)
->           ,("revenue", typeNumeric)
->           ,("o_orderdate", typeDate)
->           ,("o_shippriority", typeInt)]
->          ,--q4
->           [("o_orderpriority", typeChar)
->           ,("order_count", typeBigInt)]
->          ,--q5
->           [("n_name", typeChar)
->           ,("revenue", typeNumeric)]
->          ,--q6
->           [("revenue", typeNumeric)]
->          ,--q7
->           [("supp_nation", typeChar)
->           ,("cust_nation", typeChar)
->           ,("l_year", typeFloat8)
->           ,("revenue", typeNumeric)]
->          ,--q8
->           [("o_year", typeFloat8)
->           ,("mkt_share", typeNumeric)]
->          ,--q9
->           [("nation", typeChar)
->           ,("o_year", typeFloat8)
->           ,("sum_profit", typeNumeric)]
->          ,--q10
->           [("c_custkey",typeInt)
->           ,("c_name", typeChar)
->           ,("revenue", typeNumeric)
->           ,("c_acctbal", typeNumeric)
->           ,("n_name", typeChar)
->           ,("c_address", typeVarChar)
->           ,("c_phone", typeChar)
->           ,("c_comment", typeVarChar)]
->          ,--q11
->           [("ps_partkey", typeInt)
->           ,("value", typeNumeric)]
->          ,--q12
->           [("l_shipmode", typeChar)
->           ,("high_line_count", typeBigInt)
->           ,("low_line_count", typeBigInt)]
->          ,--q13
->           [("c_count", typeBigInt)
->           ,("custdist", typeBigInt)]
->          ,--q14
->           [("promo_revenue", typeNumeric)]
->          ,--q15
->           [("s_suppkey", typeInt)
->           ,("s_name", typeChar)
->           ,("s_address", typeVarChar)
->           ,("s_phone", typeChar)
->           ,("total_revenue", typeNumeric)]
->          ,--q16
->           [("p_brand", typeChar)
->           ,("p_type", typeVarChar)
->           ,("p_size", typeInt)
->           ,("supplier_cnt", typeBigInt)]
->          ,--q17
->           [("avg_yearly", typeNumeric)]
->          ,--q18
->           [("c_name", typeChar)
->           ,("c_custkey", typeInt)
->           ,("o_orderkey", typeInt)
->           ,("o_orderdate", typeDate)
->           ,("o_totalprice", typeNumeric)
->           ,("sum", typeNumeric)]
->          ,--q19
->           [("revenue", typeNumeric)]
->          ,--q20
->           [("s_name", typeChar)
->           ,("s_address", typeVarChar)]
->          ,--q21
->           [("s_name", typeChar)
->           ,("numwait", typeBigInt)]
->          ,--q22
->           [("cntrycode", ScalarType "char")
->           ,("numcust", typeBigInt)
->           ,("totacctbal", typeNumeric)]
->          ]
-
-> itemToTft :: Item -> Test.Framework.Test
-> itemToTft (Group s is) = testGroup s $ map itemToTft is
-> itemToTft (Query n sql t) = testCase ("typecheck tpch " ++ n ++ ":") $ do
->   let ast = case parseQueryExpr "" sql of
->               Left e -> error $ show e
->               Right l -> l
->       aast = typeCheckQueryExpr cat ast
->       ty = atype $ getAnnotation aast
->       er :: [TypeError]
->       er = universeBi aast
->       res = if null er
->             then case ty of
->                    Nothing -> Left []
->                    Just ty' -> Right ty'
->             else Left er
->       ok = Right t == res
->   unless ok $ putStrLn $ "bad sql: " ++ printQueryExpr aast
->        -- ++ "\n" ++ groom aast
->   assertBool "" ok
->   where
->     cat = case updateCatalog defaultTemplate1Catalog tpchCatalog of
->                         Left x -> error $ show x
->                         Right e -> e
-
-
-
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Triggers.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Triggers.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Triggers.lhs
+++ /dev/null
@@ -1,94 +0,0 @@
-
-Set of tests to check the type checking code. Includes tests for the
-errors for sql which doesn't type check.
-
-> module Database.HsSqlPpp.Tests.TypeChecking.Triggers
->     (tcTriggersTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> --import Database.HsSqlPpp.Types
->
-> --import Database.HsSqlPpp.Catalog
-
---------------------------------------------------------------------------------
-
-
-> tcTriggersTestData :: Item
-> tcTriggersTestData = --fixme
->   Group "triggers" [
->       {-d [$here|
->          create table t1 (
->            a int,
->            b int,
->            c text
->          );
->          create table t2 (
->            a int,
->            b int,
->            c int
->          );
->          create function trig_fn() returns trigger as $a$
->          begin
->            if (NEW.a > 100) or (OLD.b < 5) then
->                raise exception 'no good';
->            end if;
->            return NEW;
->          end;
->          $a$ language plpgsql volatile;
->          create trigger trig
->            after update on t1
->            for each row
->            execute procedure check_relvar_update();
->          create trigger trig
->            after update on t2
->            for each row
->            execute procedure check_relvar_update();
->          |]
->       [CatCreateTable "t1" [("a",ScalarType "int4")
->                            ,("b",ScalarType "int4")
->                            ,("c",ScalarType "text")]
->                            [("tableoid",ScalarType "oid")
->                            ,("cmax",ScalarType "cid")
->                            ,("xmax",ScalarType "xid")
->                            ,("cmin",ScalarType "cid")
->                            ,("xmin",ScalarType "xid")
->                            ,("ctid",ScalarType "tid")]
->       ,CatCreateTable "t2" [("a",ScalarType "int4")
->                            ,("b",ScalarType "int4")
->                            ,("c",ScalarType "int4")]
->                            [("tableoid",ScalarType "oid")
->                            ,("cmax",ScalarType "cid")
->                            ,("xmax",ScalarType "xid")
->                            ,("cmin",ScalarType "cid")
->                            ,("xmin",ScalarType "xid")
->                            ,("ctid",ScalarType "tid")]
->       ,CatCreateFunction FunName "trig_fn" [] (Pseudo Trigger) False]-}
->      {-,s [$here|
->          create table t1 (
->            a int,
->            b int,
->            c text
->          );
->          create function trig_fn() returns trigger as $a$
->          begin
->            if NEW.d = 'bad value' then
->              return NEW;
->                raise exception 'no good';
->            end if;
->          end;
->          $a$ language plpgsql volatile;
->          create trigger trig
->            after update on t1
->            for each row
->            execute procedure check_relvar_update();
->          |]
->         $ Left []-}
->      ]
-
->  where
->    --e = Expr
->    --s = StmtType
->    --c = CatStmtType
->    --d = Ddl
-
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/TypeCheckTests.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/TypeCheckTests.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/TypeCheckTests.lhs
+++ /dev/null
@@ -1,115 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.TypeCheckTests
->     (typeCheckTests
->     ,typeCheckTestData
->     ,Item(..)) where
-
-> import Test.Framework
-
-
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Tests.TypeChecking.TableRefTests
-> import Database.HsSqlPpp.Tests.TypeChecking.TpchTests
-> import Database.HsSqlPpp.Tests.TypeChecking.TypeInferenceTests
-> import Database.HsSqlPpp.Tests.TypeChecking.Literals
-> import Database.HsSqlPpp.Tests.TypeChecking.SimpleExpressions
-> import Database.HsSqlPpp.Tests.TypeChecking.SpecialFunctions
-> import Database.HsSqlPpp.Tests.TypeChecking.RowCtors
-> import Database.HsSqlPpp.Tests.TypeChecking.CaseExpressions
-> import Database.HsSqlPpp.Tests.TypeChecking.MiscExpressions
-> import Database.HsSqlPpp.Tests.TypeChecking.SimpleSelects
-> import Database.HsSqlPpp.Tests.TypeChecking.CombineSelects
-> import Database.HsSqlPpp.Tests.TypeChecking.SelectFrom
-> import Database.HsSqlPpp.Tests.TypeChecking.Joins
-> import Database.HsSqlPpp.Tests.TypeChecking.Qualification
-> import Database.HsSqlPpp.Tests.TypeChecking.MiscSelects
-> import Database.HsSqlPpp.Tests.TypeChecking.Insert
-> import Database.HsSqlPpp.Tests.TypeChecking.Update
-> import Database.HsSqlPpp.Tests.TypeChecking.Delete
-> import Database.HsSqlPpp.Tests.TypeChecking.Creates
-> import Database.HsSqlPpp.Tests.TypeChecking.Plpgsql
-> import Database.HsSqlPpp.Tests.TypeChecking.CatalogChaining
-> import Database.HsSqlPpp.Tests.TypeChecking.Into
-> import Database.HsSqlPpp.Tests.TypeChecking.Drops
-> import Database.HsSqlPpp.Tests.TypeChecking.Triggers
-> import Database.HsSqlPpp.Tests.TypeChecking.Misc
-
-> typeCheckTestData :: Item
-> typeCheckTestData = Group "typeCheckTests" typeCheckTestList
-
-> typeCheckTestList :: [Item]
-> typeCheckTestList = [tcLiteralTestData
->                     ,tcSimpleExpressionTestData
->                     ,tcSpecialFunctionsTestData
->                     ,tcRowCtorsTestData
->                     ,caseExpressionsTestData
->                     ,miscExpressionsTestData
->                     ,tcSimpleSelectsTestData
->                     ,tcCombineSelectsTestData
->                     ,tcSelectFromTestData
->                     ,tcJoinsTestData
->                     ,tcQualificationTestData
->                     ,tcMiscSelectTestData
->                     ,tcInsertTestData
->                     ,tcUpdateTestData
->                     ,tcDeleteTestData
->                     ,tcCreateTestData
->                     ,tcPlpgsqlTestData
->                     ,tcCatalogChainingTestData
->                     ,tcIntoTestData
->                     ,tcDropsTestData
->                     ,tcTriggersTestData
->                     ,tcMiscTestData]
-
-todo:
-
---------------------------------------------------------------------------------
-
-~~~~
-test some casts
-assign composite to record
-  then assign record to composite
-assign row to composite
- : check wrong cols, wrong types
-check read and write fields in composite->record
-check read and write fields in composite
-check domain <-> base assigns
-check call function with compatible composite, compatible row ctor
-assign comp to comp
-
-todo for chaos sql
-for loop var = scalar, select = setof composite with one scalar
-
-select into
-composite assignment and equality
-autocast from rowctor to composite when calling function
-assignment to composite fields
-read fields of composite
-
-array_contains -> match anyelement
-createtable as cat update
-window functions
-assign domain <-> base
-sql function not working
-~~~~
-
-
-~~~~
-check insert returning, update returning, delete returning, one check each
-check select into: multiple vars, record (then access fields to check),
-  composite var
-check errors: select into wrong number of vars, wrong types, and into
-  composite wrong number and wrong type
-~~~~
-
-
-
-
-> typeCheckTests :: Test.Framework.Test
-> typeCheckTests =
->   testGroup "typeChecking" $
->                 [tableRefTests
->                 ,tpchTests
->                 ,typeInferenceTests]
->                 ++ map itemToTft typeCheckTestList
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/TypeInferenceTests.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/TypeInferenceTests.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/TypeInferenceTests.lhs
+++ /dev/null
@@ -1,66 +0,0 @@
-
-> {-# LANGUAGE QuasiQuotes #-}
-> module Database.HsSqlPpp.Tests.TypeChecking.TypeInferenceTests (typeInferenceTests) where
-
-> import Test.HUnit
-> import Test.Framework
-> import Test.Framework.Providers.HUnit
-> --import Data.List
-> import Data.Generics.Uniplate.Data
-
-> --import Debug.Trace
->
-> --import Database.HsSqlPpp.Utils.Here
-> --import Database.HsSqlPpp.Parser
-> import Database.HsSqlPpp.TypeChecker
-> import Database.HsSqlPpp.Annotation
-> import Database.HsSqlPpp.Catalog
-> import Database.HsSqlPpp.Types
-> import Database.HsSqlPpp.Quote
-> import Database.HsSqlPpp.Ast
-> import Database.HsSqlPpp.Pretty
-
-> data Item = Expr ScalarExpr [Maybe Type]
->           | Group String [Item]
-
-> typeInferenceTests :: Test.Framework.Test
-> typeInferenceTests = itemToTft typeInferenceTestData
->
-> typeInferenceTestData :: Item
-> typeInferenceTestData =
->   Group "typeInferenceTests" [
->     e [sqlExpr| 1 = '2'|] [Just typeBool
->                           ,Just typeInt
->                           ,Just typeInt]
->    ,e [sqlExpr| (3,4) = ('2','3')|] [Just typeBool
->                                     ,Just $ AnonymousRecordType [typeInt,typeInt]
->                                     ,Just typeInt
->                                     ,Just typeInt
->                                     ,Just $ AnonymousRecordType [typeInt,typeInt]
->                                     ,Just typeInt
->                                     ,Just typeInt]
->    ,e [sqlExpr| ('2','3') = (3,4)|] [Just typeBool
->                                     ,Just $ AnonymousRecordType [typeInt,typeInt]
->                                     ,Just typeInt
->                                     ,Just typeInt
->                                     ,Just $ AnonymousRecordType [typeInt,typeInt]
->                                     ,Just typeInt
->                                     ,Just typeInt]
->    ,e [sqlExpr| ('2',3) = (3,'4')|] [Just typeBool
->                                     ,Just $ AnonymousRecordType [typeInt,typeInt]
->                                     ,Just typeInt
->                                     ,Just typeInt
->                                     ,Just $ AnonymousRecordType [typeInt,typeInt]
->                                     ,Just typeInt
->                                     ,Just typeInt]
->   ]
->   where
->     e = Expr
-
-> itemToTft :: Item -> Test.Framework.Test
-> itemToTft (Group s is) = testGroup s $ map itemToTft is
-
-> itemToTft (Expr e t) = testCase (printScalarExpr e) $
->     let a = typeCheckScalarExpr defaultTemplate1Catalog e
->         t1 = filter (/= Nothing) [infType el | el <- universeBi a]
->     in assertEqual "" t t1
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Update.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Update.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Update.lhs
+++ /dev/null
@@ -1,48 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.Update
->     (tcUpdateTestData) where
->
-> import Database.HsSqlPpp.Tests.TypeChecking.Utils
-
-> import Database.HsSqlPpp.Types
-
-> tcUpdateTestData :: Item
-> tcUpdateTestData =
->   Group "update" [
->       s "update nope set a = 1;"
->         $ Left [UnrecognisedRelation "nope"]
->      ,s "update pg_attrdef set adsrc = '' where 1;"
->         $ Left [ExpressionMustBeBool]
->      ,s "update pg_attrdef set (adbin,adsrc) = ('a','b','c');"
->         $ Left [IncompatibleTypes
->                 (AnonymousRecordType [ScalarType "pg_node_tree"
->                                      ,ScalarType "text"])
->                 (AnonymousRecordType [UnknownType
->                                      ,UnknownType
->                                      ,UnknownType])]
->      ,s "update pg_attrdef set (adrelid,adsrc) = (true,'b');"
->         $ Left [IncompatibleTypes
->                 (AnonymousRecordType [ScalarType "oid"
->                                      ,ScalarType "text"])
->                 (AnonymousRecordType [ScalarType "bool"
->                                      ,UnknownType])]
->      ,s "update pg_attrdef set (shmadrelid,adsrc) = ('a','b');"
->         $ Left [UnrecognisedIdentifier "shmadrelid"]
->      ,s "update pg_attrdef set adsrc='';"
->         $ Right [Just ([], [])]
->      ,s "update pg_attrdef set adsrc='' where 1=2;"
->         $ Right [Just ([], [])]
->           -- FIXME?
->       -- TODO: actually, pg doesn't support this so need to generate error instead
->      {-,s "update pg_attrdef set (adbin,adsrc) = ((select 'a','b'));"
->         $ Right [Just ([], [])]-}
->      --check where ids
->      ,s "update pg_attrdef set adsrc='' where adsrc='';"
->         $ Right [Just ([], [])]
->      ,s "update pg_attrdef set adnum = adnum + 1;"
->         $ Right [Just ([], [])]
->      ]
-
->  where
->    s = StmtType
-
diff --git a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Utils.lhs b/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Utils.lhs
deleted file mode 100644
--- a/src-extra/tests/Database/HsSqlPpp/Tests/TypeChecking/Utils.lhs
+++ /dev/null
@@ -1,94 +0,0 @@
-
-> module Database.HsSqlPpp.Tests.TypeChecking.Utils where
-
-> import Test.Framework
-
-
-> import Test.HUnit
-> import Test.Framework.Providers.HUnit
-> import Data.List
-> import Data.Generics.Uniplate.Data
-> import Database.HsSqlPpp.Parser
-> import Database.HsSqlPpp.TypeChecker
-> import Database.HsSqlPpp.Annotation
-> import Database.HsSqlPpp.Catalog
-> import Database.HsSqlPpp.Types
-> import Database.HsSqlPpp.Pretty
-> --import Text.Groom
-> import Database.HsSqlPpp.Tests.TestUtils
-
-
-> data Item = Group String [Item]
->           | Expr String (Either [TypeError] Type)
->           | StmtType String (Either [TypeError] [Maybe ParameterizedStatementType])
->           | CatStmtType String [CatalogUpdate] (Either [TypeError] [Maybe ParameterizedStatementType])
->           | Ddl String [CatalogUpdate]
-
-
-> testExpressionType :: String -> Either [TypeError] Type -> Test.Framework.Test
-> testExpressionType src et = testCase ("typecheck " ++ src) $
->   let ast = case parseScalarExpr "" src of
->                                      Left e -> error $ show e
->                                      Right l -> l
->       aast = typeCheckScalarExpr defaultTemplate1Catalog ast
->       ty = atype $ getAnnotation aast
->       er :: [TypeError]
->       er = universeBi aast
->   in if null er
->      then assertEqual ("typecheck " ++ src) (Just et) $ fmap Right ty
->      else assertEqual ("typecheck " ++ src) et $ Left er
->
-> testStatementType :: String -> Either [TypeError] [Maybe ParameterizedStatementType] -> Test.Framework.Test
-> testStatementType src sis = testCase ("typecheck " ++ src) $
->   let ast = case parseStatements "" src of
->                               Left e -> error $ show e
->                               Right l -> l
->       aast = snd $ typeCheckStatements defaultTemplate1Catalog ast
->       is = map (stType . getAnnotation) aast
->       er :: [TypeError]
->       er = universeBi aast
->   in case (length er, length is) of
->        (0,0) -> assertFailure "didn't get any infos?"
->        (0,_) -> assertTrace (printStatements aast) ("typecheck " ++ src) sis $ Right is
->        _ -> assertTrace (printStatements aast) ("typecheck " ++ src) sis $ Left er
-
-> testCatUpStatementType :: String
->                        -> [CatalogUpdate]
->                        -> Either [TypeError] [Maybe ParameterizedStatementType]
->                        -> Test.Framework.Test
-> testCatUpStatementType src eu sis = testCase ("typecheck " ++ src) $
->   let ast = case parseStatements "" src of
->                               Left e -> error $ show e
->                               Right l -> l
->       aast = snd $ typeCheckStatements makeCat ast
->       is = map (stType . getAnnotation) aast
->       er :: [TypeError]
->       er = universeBi aast
->   in {-trace (show aast) $-} case (length er, length is) of
->        (0,0) -> assertFailure "didn't get any infos?"
->        (0,_) -> assertTrace (printStatements aast) ("typecheck " ++ src) sis $ Right is
->        _ -> assertTrace (printStatements aast) ("typecheck " ++ src) sis $ Left er
->   where
->     makeCat = case updateCatalog defaultTemplate1Catalog eu of
->                         Left x -> error $ show x
->                         Right e -> e
->
-> testCat :: String -> [CatalogUpdate] -> Test.Framework.Test
-> testCat src eu = testCase ("check catalog: " ++ src) $
->   let ast = case parseStatements "" src of
->                               Left e -> error $ show e
->                               Right l -> l
->       (ncat,aast) = typeCheckStatements defaultTemplate1Catalog ast
->       er :: [TypeError]
->       er = universeBi aast
->       neu = deconstructCatalog ncat \\ deconstructCatalog defaultTemplate1Catalog
->   in if not (null er)
->        then assertFailure $ show er
->        else assertEqual "check eus" eu neu
->
-> itemToTft :: Item -> Test.Framework.Test
-> itemToTft (Expr s r) = testExpressionType s r
-> itemToTft (StmtType s r) = testStatementType s r
-> itemToTft (CatStmtType s c r) = testCatUpStatementType s c r
-> itemToTft (Ddl s c) = testCat s c
-> itemToTft (Group s is) = testGroup s $ map itemToTft is
diff --git a/src-extra/tests/Tests.lhs b/src-extra/tests/Tests.lhs
deleted file mode 100644
--- a/src-extra/tests/Tests.lhs
+++ /dev/null
@@ -1,28 +0,0 @@
-test files todo:
-
-create new test hierarchy, move test code here, add new exe to run
-  them
-
-disable failing tests
-
-get website generating again
-
-start new test pages + renderer
-
-
-extensions tests
-
-local bindings tests
-
-parameterized statement tests
-parsertests
-quasiquote tests
-roundtrip tests
-type check tests
-type inference tests
-
-> import Database.HsSqlPpp.Tests.Tests
-> import Test.Framework
-
-> main :: IO ()
-> main = defaultMain allTests
diff --git a/src-extra/util/Database/HsSqlPpp/Utils/CatalogReader.lhs b/src-extra/util/Database/HsSqlPpp/Utils/CatalogReader.lhs
deleted file mode 100644
--- a/src-extra/util/Database/HsSqlPpp/Utils/CatalogReader.lhs
+++ /dev/null
@@ -1,333 +0,0 @@
-
-This module contains the code to read a set of catalog updates
-from a database.
-
-The code here hasn't been tidied up since the Catalog data type
-was heavily changed so it's a bit messy.
-
-> {-# LANGUAGE QuasiQuotes #-}
->
-> module Database.HsSqlPpp.Utils.CatalogReader
->     (readCatalogFromDatabase) where
->
-> import qualified Data.Map as M
-> import Data.Maybe
-> import Control.Applicative
-> --import Debug.Trace
->
-> --import Database.HsSqlPpp.Internals.TypeType
-> --import Database.HsSqlPpp.Utils.Utils
-> import Database.HsSqlPpp.Utils.Here
-> --import Database.HsSqlPpp.Internals.Catalog.CatalogInternal
-> import Database.HsSqlPpp.Utils.PgUtils
-> import Database.HsSqlPpp.Catalog
-> import Database.HsSqlPpp.Types
->
-> -- | Creates an 'CatalogUpdate' list by reading the database given.
-> -- To create an Catalog value from this, use
-> --
-> -- @
-> -- cat <- readCatalogFromDatabase 'something'
-> -- let newCat = updateCatalog defaultCatalog cat
-> -- @
-> readCatalogFromDatabase :: String -- ^ connection string of the database to read
->                             -> IO [CatalogUpdate]
-> readCatalogFromDatabase cs = withConn cs $ \conn -> do
->    typeInfo <- selectRelation conn [here|
-
-\begin{code}
-
-select t.oid as oid,
-       t.typtype,
-       case nspname
-         when 'public' then t.typname
-         when 'pg_catalog' then t.typname
-         else nspname || '.' || t.typname
-       end as typname,
-       t.typarray,
-       coalesce(e.typtype,'0') as atyptype,
-       e.oid as aoid,
-       e.typname as atypname
-  from pg_catalog.pg_type t
-  left outer join pg_type e
-    on t.typarray = e.oid
-   inner join pg_namespace ns
-      on t.typnamespace = ns.oid
-         and ns.nspname in ('pg_catalog'
-                           ,'public'
-                           ,'information_schema')
-  where /*pg_catalog.pg_type_is_visible(t.oid)
-   and */not exists(select 1 from pg_catalog.pg_type el
-                       where el.typarray = t.oid)
-  order by t.typname;
-
-\end{code}
-
->                |] []
->    let typeStuff = concatMap convTypeInfoRow typeInfo
->        typeAssoc = map (\(a,b,_) -> (a,b)) typeStuff
->        typeMap = M.fromList typeAssoc
->    cts <- map (\(nm:cat:pref:[]) ->
->                CatCreateScalar (ScalarType nm) cat ( read pref :: Bool)) <$>
->           selectRelation conn [here|
-
-\begin{code}
-
-select t.typname,typcategory,typispreferred
-from pg_type t
-   inner join pg_namespace ns
-      on t.typnamespace = ns.oid
-         and ns.nspname in ('pg_catalog', 'public', 'information_schema')
-where t.typarray<>0 and
-    typtype='b' /*and
-    pg_catalog.pg_type_is_visible(t.oid)*/;
-
-\end{code}
-
->                |] []
->    domainDefInfo <- selectRelation conn [here|
-
-\begin{code}
-
-select pg_type.oid, typbasetype
-  from pg_type
-  inner join pg_namespace ns
-      on pg_type.typnamespace = ns.oid
-         and ns.nspname in ('pg_catalog', 'public', 'information_schema')
- where typtype = 'd'
-     /*and  pg_catalog.pg_type_is_visible(oid)*/;
-
-\end{code}
-
->                |] []
->    let jlt k = fromJust $ M.lookup k typeMap
->    let domainDefs = map (\l -> (jlt (l!!0),  jlt (l!!1))) domainDefInfo
->    --let domainCasts = map (\(t,b) ->(t,b,ImplicitCastContext)) domainDefs
->    castInfo <- selectRelation conn
->                  "select castsource,casttarget,castcontext from pg_cast;" []
->    let casts =
->      {- domainCasts ++ -}
->          flip map castInfo
->               (\l -> (jlt (l!!0)
->                      ,jlt (l!!1)
->                      ,case (l!!2) of
->                                   "a" -> AssignmentCastContext
->                                   "i" -> ImplicitCastContext
->                                   "e" -> ExplicitCastContext
->                                   _ -> error $ "internal error: unknown \
->                                                \cast context " ++ (l!!2)))
->    operatorInfo <- selectRelation conn [here|
-
-\begin{code}
-
-select oprname,
-       oprleft,
-       oprright,
-       oprresult
-from pg_operator
-      where not (oprleft <> 0 and oprright <> 0
-         and oprname = '@') --hack for now
-      order by oprname;
-
-\end{code}
-
->                |] []
->    let getOps a b c [] = (a,b,c)
->        getOps pref post bin (l:ls) =
->          let bit = (\a -> (l!!0, a, jlt(l!!3)))
->          in case () of
->                   _ | l!!1 == "0"
->                         -> getOps (bit [jlt (l!!2)]:pref) post bin ls
->                     | l!!2 == "0"
->                         -> getOps pref (bit [jlt (l!!1)]:post) bin ls
->                     | otherwise -> getOps pref post (bit [jlt (l!!1)
->                                                          ,jlt (l!!2)]:bin) ls
->    let (prefixOps, postfixOps, binaryOps) = getOps [] [] [] operatorInfo
->    functionInfo <- selectRelation conn [here|
-
-\begin{code}
-
-select proname,
-       array_to_string(proargtypes,','),
-       proretset,
-       prorettype
-from pg_proc
-where pg_catalog.pg_function_is_visible(pg_proc.oid)
-      and provariadic = 0
-      and not proisagg
-      and not proiswindow
-order by proname,proargtypes;
-\end{code}
-
->                |] []
->    let fnProts = map (convFnRow jlt) functionInfo
->    aggregateInfo <- selectRelation conn [here|
-
-\begin{code}
-
-select proname,
-       array_to_string(proargtypes,','),
-       proretset,
-       prorettype
-from pg_proc
-where pg_catalog.pg_function_is_visible(pg_proc.oid)
-      and provariadic = 0
-      and proisagg
-order by proname,proargtypes;
-\end{code}
-
->                |] []
->    let aggProts = map (convFnRow jlt) aggregateInfo
->    windowInfo <- selectRelation conn [here|
-
-\begin{code}
-
-select proname,
-       array_to_string(proargtypes,','),
-       proretset,
-       prorettype
-from pg_proc
-where pg_catalog.pg_function_is_visible(pg_proc.oid)
-      and provariadic = 0
-      and proiswindow
-order by proname,proargtypes;
-
-\end{code}
-
->                |] []
->    let winProts = map (convFnRow jlt) windowInfo
->    comps <- map (\(kind:nm:atts:sysatts:nsp:[]) ->
->              let nm1 = case nsp of
->                                 "pg_catalog" -> nm
->                                 "public" -> nm
->                                 n -> n ++ "." ++ nm
->              in case kind of
->                     "c" -> CatCreateComposite nm1 (convertAttString jlt atts)
->                     "r" -> CatCreateTable nm1 (convertAttString jlt atts)
->                                               (convertAttString jlt sysatts)
->                     "v" -> CatCreateView nm1 (convertAttString jlt atts)
->                     _ -> error $ "unrecognised relkind: " ++ kind) <$>
->                 selectRelation conn [here|
-
-\begin{code}
-
-with att1 as (
- select
-     attrelid,
-     attname,
-     attnum,
-     atttypid
-   from pg_attribute
-   inner join pg_class cls
-      on cls.oid = attrelid
-   inner join pg_namespace ns
-      on cls.relnamespace = ns.oid
-         and ns.nspname in ('pg_catalog', 'public', 'information_schema')
-   where /*pg_catalog.pg_table_is_visible(cls.oid)
-      and*/ cls.relkind in ('r','v','c')
-      and not attisdropped),
- sysAtt as (
- select attrelid,
-     array_to_string(
-       array_agg(attname || ';' || atttypid)
-         over (partition by attrelid order by attnum
-               range between unbounded preceding
-               and unbounded following)
-       ,',') as sysAtts
-   from att1
-   where attnum < 0),
- att as (
- select attrelid,
-     array_to_string(
-       array_agg(attname || ';' || atttypid)
-          over (partition by attrelid order by attnum
-                range between unbounded preceding
-                and unbounded following)
-       ,',') as atts
-   from att1
-   where attnum > 0)
- select distinct
-     cls.relkind,
-     cls.relname,
-     atts,
-     coalesce(sysAtts,''),
-     nspname
-   from att left outer join sysAtt using (attrelid)
-   inner join pg_class cls
-     on cls.oid = attrelid
-   inner join pg_namespace ns
-      on cls.relnamespace = ns.oid
-   order by relkind,relname;
-
-\end{code}
-
->                |] []
->    return
->      $ concat [cts
->               ,map (uncurry CatCreateDomain) domainDefs
->               ,map (\(a,b,c) -> CatCreateCast a b c) casts
->               ,map (\(a,b,c) ->
->                     CatCreateFunction FunPrefix a b c False) prefixOps
->               ,map (\(a,b,c) ->
->                     CatCreateFunction FunPostfix a b c False) postfixOps
->               ,map (\(a,b,c) ->
->                     CatCreateFunction FunBinary a b c False) binaryOps
->               ,map (\(a,b,c) ->
->                     CatCreateFunction FunName a b c False) fnProts
->               ,map (\(a,b,c) ->
->                     CatCreateFunction FunAgg a b c False) aggProts
->               ,map (\(a,b,c) ->
->                     CatCreateFunction FunWindow a b c False) winProts
->               ,comps]
->    where
->      convertAttString jlt s =
->          let ps = split ',' s
->              ps1 = map (split ';') ps
->          in map (\pl -> (head pl, jlt (pl!!1))) ps1
->      convFnRow jlt l =
->         (head l,fnArgs,fnRet)
->         where
->           fnRet = let rt1 = jlt (l!!3)
->                   in if read (l!!2)::Bool
->                        then SetOfType rt1
->                        else rt1
->           fnArgs = if (l!!1) == ""
->                      then []
->                      else let a = split ',' (l!!1)
->                           in map jlt a
->      convTypeInfoRow l =
->        let name = canonicalizeTypeName (l!!2)
->            ctor = case (l!!1) of
->                     "b" -> ScalarType
->                     "c" -> NamedCompositeType
->                     "d" -> DomainType
->                     "e" -> EnumType
->                     "p" -> Pseudo . pn
->                     _ -> error $ "internal error: unknown type type: "
->                          ++ (l !! 1)
->            scType = (head l, ctor name, name)
->        in if (l!!4) /= "0"
->           then [(l!!5,ArrayType $ ctor name, '_':name), scType]
->           else [scType]
->      pn t = case t of
->                    "any" -> Any
->                    "anyarray" -> AnyArray
->                    "anyelement" -> AnyElement
->                    "anyenum" -> AnyEnum
->                    "anynonarray" -> AnyNonArray
->                    "cstring" -> Cstring
->                    "internal" -> Internal
->                    "language_handler" -> LanguageHandler
->                    "opaque" -> Opaque
->                    "record" -> Record
->                    "trigger" -> Trigger
->                    "void" -> Void
->                    "fdw_handler" -> FdwHandler
->                    _ -> error $ "internal error: unknown pseudo " ++ t
-
-> split :: Char -> String -> [String]
-> split _ ""                =  []
-> split c s                 =  let (l, s') = break (== c) s
->                            in  l : case s' of
->                                            [] -> []
->                                            (_:s'') -> split c s''
diff --git a/src-extra/util/Database/HsSqlPpp/Utils/Here.lhs b/src-extra/util/Database/HsSqlPpp/Utils/Here.lhs
deleted file mode 100644
--- a/src-extra/util/Database/HsSqlPpp/Utils/Here.lhs
+++ /dev/null
@@ -1,16 +0,0 @@
-
-Multiline string support, mainly used to enter multiline sql strings
-
-robbed from http://old.nabble.com/Multi-line-string-literals-are-both-easy--and--elegant-in-Haskell-td19959973.html
-
-> module Database.HsSqlPpp.Utils.Here where
->
-> import Language.Haskell.TH.Quote
-> --import Language.Haskell.TH.Syntax
-> import Language.Haskell.TH.Lib
->
-> here :: QuasiQuoter
-> here = QuasiQuoter {quoteExp = litE . stringL
->                    ,quotePat = litP . stringL
->                    ,quoteType = undefined
->                    ,quoteDec = undefined}
diff --git a/src-extra/util/Database/HsSqlPpp/Utils/PgUtils.lhs b/src-extra/util/Database/HsSqlPpp/Utils/PgUtils.lhs
deleted file mode 100644
--- a/src-extra/util/Database/HsSqlPpp/Utils/PgUtils.lhs
+++ /dev/null
@@ -1,37 +0,0 @@
-
-Some simple wrappers around HDBC for the code to use.
-
-> module Database.HsSqlPpp.Utils.PgUtils
->     (withConn
->     ,selectRelation
->     ,runSqlCommand
->     ,withTransaction
->     ,Pg.Connection
->     ,IConnection) where
->
-> import qualified Database.HDBC.PostgreSQL as Pg
-> import Database.HDBC
-> import Control.Exception
->
-> withConn :: String -> (Pg.Connection -> IO c) -> IO c
-> withConn cs = bracket (Pg.connectPostgreSQL cs) disconnect
->
-> selectRelation ::(IConnection conn) =>
->                  conn -> String -> [String] -> IO [[String]]
-> selectRelation conn query args = do
->   sth <- prepare conn query
->   _ <- execute sth $ map sToSql args
->   v <- fetchAllRows' sth
->   return $ map (map sqlToS) v
->
-> runSqlCommand :: (IConnection conn) =>
->           conn -> String -> IO ()
-> runSqlCommand conn query = do
->     _ <- run conn query []
->     commit conn
->
-> sToSql :: String -> SqlValue
-> sToSql s = toSql (s::String)
->
-> sqlToS :: SqlValue -> String
-> sqlToS = fromSql
diff --git a/src/Database/HsSqlPpp/Annotation.lhs b/src/Database/HsSqlPpp/Annotation.lhs
--- a/src/Database/HsSqlPpp/Annotation.lhs
+++ b/src/Database/HsSqlPpp/Annotation.lhs
@@ -9,8 +9,9 @@
 >     (
 >      -- * Annotation data types
 >      Annotation(..)
+>     --,TypeExtra(..)
 >     ,SourcePosition
->     ,ParameterizedStatementType
+>     --,ParameterizedStatementType
 >     ,getAnnotation
 >     --,updateAnnotations
 >     ,updateAnnotation
@@ -19,5 +20,5 @@
 >     --,resetAnnotations
 >     ) where
 >
-> import Database.HsSqlPpp.Internals.AstAnnotation
+> import Database.HsSqlPpp.Internals.AstInternal
 > --import Database.HsSqlPpp.Internals.AnnotationUtils
diff --git a/src/Database/HsSqlPpp/Ast.lhs b/src/Database/HsSqlPpp/Ast.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Ast.lhs
+++ /dev/null
@@ -1,101 +0,0 @@
-
-> {- | This module contains the ast node data types. They are very
->      permissive, in that they allow a lot of invalid SQL to be
->      represented. The type checking process should catch all invalid
->      trees, but doesn't quite manage at the moment.  Sorry about all
->      the seemingly pointless type synonyms below, they are an
->      artefact of using UUAGC. You can see labels for the fields by
->      looking at the ag source here:
->      <http://jakewheat.github.com/hssqlppp/source/src/Database/HsSqlPpp/Internals/AstInternal.ag.html>
->      -}
->
-> module Database.HsSqlPpp.Ast
->     (
->      -- * Main nodes
->      StatementList
->     ,Statement (..)
->     ,ScalarExpr (..)
->     ,QueryExpr (..)
->      -- * Components
->      -- ** Selects
->     ,SelectList (..)
->     ,SelectItem (..)
->     ,TableRef (..)
->     ,TableAlias(..)
->     ,JoinExpr (..)
->     ,JoinType (..)
->     ,Natural (..)
->     ,CombineType (..)
->     ,Direction (..)
->     ,Distinct (..)
->     ,InList (..)
->     ,LiftFlavour (..)
->     ,FrameClause(..)
->     ,WithQueryList
->     ,WithQuery(..)
->     ,IntervalField(..)
->     ,ExtractField(..)
->     ,Name(..)
->     ,NameComponent(..)
->     ,ncStr
->      -- ** dml
->     ,CopySource (..)
->     ,RestartIdentity (..)
->     ,SetClause(..)
->      -- ** ddl
->     ,AttributeDef (..)
->     ,RowConstraint (..)
->     ,Constraint (..)
->     ,AlterTableAction(..)
->     ,TypeAttributeDef (..)
->     ,TypeName (..)
->     ,DropType (..)
->     ,IfExists (..)
->     ,Replace(..)
->     ,Cascade (..)
->     ,TriggerWhen(..)
->     ,TriggerEvent(..)
->     ,TriggerFire(..)
->      -- ** functions
->     ,FnBody (..)
->     ,ParamDef (..)
->     ,VarDef (..)
->     ,RaiseType (..)
->     ,Volatility (..)
->     ,Language (..)
->      -- ** misc
->     ,SetValue(..)
->     -- ,Name(..)
->      -- ** typedefs
->     ,ScalarExprListStatementListPairList
->     ,ScalarExprListStatementListPair
->     ,ScalarExprList
->     ,MaybeSelectList
->     --,StringList
->     ,ParamDefList
->     ,AttributeDefList
->     ,ConstraintList
->     ,TypeAttributeDefList
->     ,TypeNameList
->     ,NameTypeNameListPair
->     ,NameTypeNameListPairList
->     ,ScalarExprStatementListPairList
->     ,CaseScalarExprListScalarExprPairList
->     ,MaybeScalarExpr
->     ,MaybeBoolExpr
->     ,TableRefList
->     ,ScalarExprListList
->     ,SelectItemList
->     ,OnExpr
->     ,RowConstraintList
->     ,VarDefList
->     ,ScalarExprStatementListPair
->     ,CaseScalarExprListScalarExprPair
->     ,ScalarExprDirectionPair
->     ,ScalarExprDirectionPairList
->     ,AlterTableActionList
->     ,SetClauseList
->     ) where
->
-> import Database.HsSqlPpp.Internals.AstInternal
-> --import Database.HsSqlPpp.Internals.Name
diff --git a/src/Database/HsSqlPpp/Catalog.lhs b/src/Database/HsSqlPpp/Catalog.lhs
--- a/src/Database/HsSqlPpp/Catalog.lhs
+++ b/src/Database/HsSqlPpp/Catalog.lhs
@@ -4,23 +4,15 @@
 > {- | This module contains the database catalog data types and helper
 >  functions.
 >
->  The catalog data type serves the following purposes:
->
->  * Contains all the catalog information needed to type check against
->     an existing database.
->
->  * A copy of the catalog information from a default template1
->    database is included - 'defaultTemplate1Catalog'.
->
->  * It is used internally to keep track of updates to the catalog
->     whilst running an annotation process (e.g. so that a select can
->     type check against a create table given in the same source). It
->     is also used to track other identifier types, such as attribute
->     references in select expressions, and argument and variable
->     types inside create function statements.
+> The catalog data type holds the catalog information needed to type
+> check sql code, and a catalog value is produced after typechecking sql
+> which represents the catalog that would be produced (e.g. for sql
+> containing ddl)
 >
->  You can see what kind of stuff is contained in the Catalog type
->  by looking at the 'CatalogUpdate' type.
+
+> You can create a catalog using the 'CatalogUpdate' type, and there
+> is example and util in the repo which reads a catalog from
+> an existing database in postgres.
 >
 > -}
 >
@@ -30,30 +22,42 @@
 >      Catalog
 >      -- ** Updates
 >     ,CatalogUpdate(..)
->     ,ppCatUpdate
+>     --,ppCatUpdate
 >      -- ** bits and pieces
 >     ,CastContext(..)
 >     ,CompositeFlavour(..)
->     ,CompositeDef
->     ,FunctionPrototype
->     ,DomainDefinition
->     ,FunFlav(..)
->      -- * Catalog values
->     ,emptyCatalog
->     ,defaultCatalog
->     ,defaultTemplate1Catalog
->      -- * Catalog comparison
->     ,CatalogDiff(..)
->     ,compareCatalogs
->     ,ppCatDiff
+>     ,CatName
+>     ,CatNameExtra(..)
+>     ,mkCatNameExtra
+>     ,mkCatNameExtraNN
+>     --,CompositeDef
+>     --,FunctionPrototype
+>     --,DomainDefinition
+>     --,FunFlav(..)
+>     --  --  * Catalog values
+>     --,emptyCatalog
+>     --,defaultCatalog
+>     --,ansiCatalog
+>     --,defaultTemplate1Catalog
+>     --,defaultTSQLCatalog
+>     --,odbcCatalog
+>      -- -- * Catalog comparison
+>     --,CatalogDiff(..)
+>     --,compareCatalogs
+>     --,ppCatDiff
 >      -- * Functions
 >     ,updateCatalog
 >     ,deconstructCatalog
->      -- * operator utils
->     ,OperatorType(..)
->     ,getOperatorType
->     ,isOperatorName
+>      -- * testing support
+>     ,Environment
+>     ,brokeEnvironment
+>     ,envSelectListEnvironment
 >     ) where
 >
-> import Database.HsSqlPpp.Internals.Catalog.CatalogInternal
-> import Database.HsSqlPpp.Internals.Catalog.DefaultTemplate1Catalog
+> import Database.HsSqlPpp.Internals.Catalog.CatalogBuilder
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+> --import Database.HsSqlPpp.Internals.Catalog.DefaultTemplate1Catalog
+> --import Database.HsSqlPpp.Internals.Catalog.DefaultTSQLCatalog
+> --import Database.HsSqlPpp.Internals.Catalog.OdbcCatalog
+> --import Database.HsSqlPpp.Internals.Catalog.AnsiCatalog
+> import Database.HsSqlPpp.Internals.TypeChecking.Environment
diff --git a/src/Database/HsSqlPpp/Dialect.lhs b/src/Database/HsSqlPpp/Dialect.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Dialect.lhs
@@ -0,0 +1,21 @@
+
+
+
+
+> module Database.HsSqlPpp.Dialect
+>     (Dialect(..)
+>     ,SyntaxFlavour(..)
+>     ,ansiDialect
+>     ,postgresDialect
+>     ,sqlServerDialect
+>     ,oracleDialect
+>     ,canonicalizeTypeName
+>     ,ansiTypeNameToDialect
+>     ) where
+
+> import Database.HsSqlPpp.Internals.Dialect
+
+> import Database.HsSqlPpp.Dialects.Ansi
+> import Database.HsSqlPpp.Dialects.Postgres
+> import Database.HsSqlPpp.Dialects.Oracle
+> import Database.HsSqlPpp.Dialects.SqlServer
diff --git a/src/Database/HsSqlPpp/Dialects/Ansi.lhs b/src/Database/HsSqlPpp/Dialects/Ansi.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Dialects/Ansi.lhs
@@ -0,0 +1,259 @@
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Dialects.Ansi (ansiDialect) where
+> import Database.HsSqlPpp.Internals.Dialect
+
+> import Database.HsSqlPpp.Internals.Catalog.CatalogBuilder
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+> import Database.HsSqlPpp.Dialects.BaseCatalog
+
+
+> ansiDialect :: Dialect
+> ansiDialect = Dialect
+>     {diName = "ansi"
+>     ,diSyntaxFlavour = Ansi
+>     ,diCanonicalTypeNames = [("char",["character"])
+>                             ,("varchar",["char varying","character varying"])
+>                             ,("clob",["character large object","char large object"])
+>                             ,("nchar",["national character","national char"])
+>                             ,("nvarchar",["national character varying"
+>                                          ,"national char varying"
+>                                          ,"nchar varying"])
+>                             ,("nclob",["national character large object"
+>                                       ,"nchar large object"])
+>                              -- todo: this list isn't complete
+>                             ,("varbinary",["binary varying"])
+>                             ,("blob",["binary large object"])
+>                             ,("int",["integer"])
+>                             ,("float",["double precision"])
+>                             ]
+>     ,diTextTypes = ["char","varchar","clob","nchar","nvarchar","nclob"]
+>     ,diDatetimeTypes = ["date","time","timestamp","interval"]
+>     ,diNumberTypes = ["smallint","int","bigint","decimal","numeric","float","real"]
+>     ,namesForAnsiTypes = [("char","char")
+>                          ,("varchar","varchar")
+>                          ,("bigint","bigint")
+>                          ,("boolean","boolean")
+>                          ,("numeric","numeric")
+>                          ,("int","int")
+>                          ,("date","date")
+>                          ,("time","time")
+>                          ,("timestamp","timestamp")
+>                          ] -- todo: finish this
+>     ,diDefaultCatalog = ansiCatalog
+>     }
+
+
+> ansiCatalog :: Catalog
+> ansiCatalog =
+>     (\l -> case l of
+>              Left x -> error $ show x
+>              Right e -> e) $
+>      flip updateCatalog emptyCatalog (
+>                                        -- todo: duplicated list of text types
+>        [CatCreateScalarType "char"
+>        ,CatCreateScalarType "varchar"
+>        ,CatCreateScalarType "clob"
+
+>        ,CatCreateScalarType "nchar"
+>        ,CatCreateScalarType "nvarchar"
+>        ,CatCreateScalarType "nclob"
+
+>        ,CatCreateScalarType "binary"
+>        ,CatCreateScalarType "varbinary"
+>        ,CatCreateScalarType "blob"
+
+>        ,CatCreateScalarType "numeric"
+>        ,CatCreateScalarType "decimal"
+
+>        ,CatCreateScalarType "smallint"
+>        ,CatCreateScalarType "int"
+>        ,CatCreateScalarType "bigint"
+
+>        ,CatCreateScalarType "float"
+>        ,CatCreateScalarType "real"
+
+>        ,CatCreateScalarType "boolean"
+
+>        ,CatCreateScalarType "date"
+>        ,CatCreateScalarType "time"
+>        ,CatCreateScalarType "timestamp"
+>        ,CatCreateScalarType "interval"
+>        ]
+
+what to do about these?
+
+position
+char_length
+extract
+substring
+convert
+translate
+trim
+overlay
+nromalize
+between
+in
+like
+collate
+
+
+
+>         ++ [CatCreateFunction charLen [t] False "int"
+>            | t <- ["char","varchar","clob"
+>                   ,"nchar","nvarchar","nclob"]
+>            , charLen <- ["char_length", "character_length", "octet_length"] ]
+>         ++ concat
+>         -- unary +- all numeric types plus interval
+>         [ [CatCreatePrefixOp "+" n n
+>           ,CatCreatePrefixOp "-" n n]
+>           | n <- ["numeric","decimal","smallint","int","bigint"
+>                  ,"float","real","interval"] ]
+>         -- binary  + - * / all numeric types
+>         ++ concat
+>         [ [ CatCreateBinaryOp "+" n n n
+>            ,CatCreateBinaryOp "-" n n n
+>            ,CatCreateBinaryOp "*" n n n
+>            ,CatCreateBinaryOp "/" n n n]
+>           | n <- ["numeric","decimal","smallint","int","bigint"
+>                  ,"float","real"] ]
+>         --  || concatenation on strings, binaries and arrays
+>         -- not sure how arrays will work right now
+>         ++ [CatCreateBinaryOp "||" s s s
+>            | s <- ["char","varchar","clob"
+>                   ,"nchar","nvarchar", "nclob"
+>                   ,"binary","varbinary","blob" ] ]
+>         -- comparisons, should some of these be generic?
+>         -- maybe want the option of user defined types
+>         -- not having comparisons? not sure about types without
+>         -- equals makes any sense here
+>         ++ [CatCreateBinaryOp op t t "boolean"
+>            | op <- ["=","<>","<",">","<=",">="]
+>            , t <- ["char","varchar","clob"
+>                   ,"nchar","nvarchar","nclob"
+>                   ,"binary","varbinary","blob"
+>                   ,"numeric","decimal"
+>                   ,"smallint","int","bigint"
+>                   ,"float","real"
+>                   ,"boolean"
+>                   ,"date","time","timestamp","interval"
+>                   ] ]
+>
+>         ++ [CatCreateFunction "abs" [t] False t
+>            | t <- ["numeric", "decimal", "smallint", "int", "bigint", "float","real"]]
+
+>         ++ [CatCreateFunction "mod" [t,t] False t
+>            | t <- ["numeric", "smallint", "int", "bigint"]]
+
+>         ++ [CatCreateFunction fn [t] False t
+>            | t <- ["float","real"]
+>            , fn <- ["ln","exp","pow","sqrt"] ]
+>         ++ [CatCreateFunction fn [t] False t
+>            | t <- ["float","real","numeric"]
+>            , fn <- ["floor","ceil","ceiling"] ]
+
+>         ++ [CatCreateFunction "width_bucket" [t,t,t,"numeric"] False "numeric"
+>            | t <- ["char","varchar","clob"
+>                   ,"nchar","nvarchar","nclob"
+>                   ,"binary","varbinary","blob"
+>                   ,"numeric","decimal"
+>                   ,"smallint","int","bigint"
+>                   ,"float","real"
+>                   ,"boolean"
+>                   ,"date","time","timestamp","interval"
+>                   ] ]
+
+>         ++ [CatCreateFunction fn [t] False t
+>            | t <- ["char","varchar","clob"
+>                   ,"nchar","nvarchar","nclob"]
+>            , fn <- ["lower","upper"] ]
+
+>         ++ concat
+>         [ [ CatCreateBinaryOp "+" dt "interval" dt
+>            ,CatCreateBinaryOp "+" "interval" dt dt
+>            ,CatCreateBinaryOp "-" dt "interval" dt]
+>           | dt <- ["date","time","timestamp"]]
+>         ++ [CatCreateBinaryOp "+" "interval" "interval" "interval"
+>            ,CatCreateBinaryOp "-" "interval" "interval" "interval"]
+
+quick and dirty to get tpch working
+
+>        ++
+>        [ CatCreateAggregate "sum" [ "numeric" ] "numeric"
+>        , CatCreateAggregate "sum" [ "smallint" ] "smallint"
+>          --todo: figure out what the options for the types are here
+>        , CatCreateAggregate "sum" [ "int" ] "bigint"
+>        , CatCreateAggregate "sum" [ "bigint" ] "bigint"
+>        , CatCreateAggregate "avg" [ "numeric" ] "numeric"
+>        , CatCreateAggregate "max" [ "numeric" ] "numeric"
+>        , CatCreateAggregate "min" [ "numeric" ] "numeric"
+>        , CatCreateAggregate "count" [ "any" ] "bigint"]
+
+
+>         ++ [
+>           --todo: these are taken from postgres catalog
+>           -- they need careful review to see if they are exactly
+>           -- what we want in the ansi dialect
+>         CatCreateCast "boolean" "int" ExplicitCastContext,
+>         CatCreateCast "boolean" "varchar" AssignmentCastContext,
+>         CatCreateCast "char" "int" ExplicitCastContext,
+>         CatCreateCast "char" "varchar" AssignmentCastContext,
+>         CatCreateCast "date" "timestamp" ImplicitCastContext,
+>         CatCreateCast "real" "float" ImplicitCastContext,
+>         CatCreateCast "real" "smallint" AssignmentCastContext,
+>         CatCreateCast "real" "int" AssignmentCastContext,
+>         CatCreateCast "real" "bigint" AssignmentCastContext,
+>         CatCreateCast "real" "numeric" AssignmentCastContext,
+>         CatCreateCast "float" "real" AssignmentCastContext,
+>         CatCreateCast "float" "smallint" AssignmentCastContext,
+>         CatCreateCast "float" "int" AssignmentCastContext,
+>         CatCreateCast "float" "bigint" AssignmentCastContext,
+>         CatCreateCast "float" "numeric" AssignmentCastContext,
+>         CatCreateCast "smallint" "real" ImplicitCastContext,
+>         CatCreateCast "smallint" "float" ImplicitCastContext,
+>         CatCreateCast "smallint" "int" ImplicitCastContext,
+>         CatCreateCast "smallint" "bigint" ImplicitCastContext,
+>         CatCreateCast "smallint" "numeric" ImplicitCastContext,
+>         CatCreateCast "int" "boolean" ExplicitCastContext,
+>         CatCreateCast "int" "char" ExplicitCastContext,
+>         CatCreateCast "int" "real" ImplicitCastContext,
+>         CatCreateCast "int" "float" ImplicitCastContext,
+>         CatCreateCast "int" "smallint" AssignmentCastContext,
+>         CatCreateCast "int" "bigint" ImplicitCastContext,
+>         CatCreateCast "int" "numeric" ImplicitCastContext,
+>         CatCreateCast "bigint" "real" ImplicitCastContext,
+>         CatCreateCast "bigint" "float" ImplicitCastContext,
+>         CatCreateCast "bigint" "smallint" AssignmentCastContext,
+>         CatCreateCast "bigint" "int" AssignmentCastContext,
+>         CatCreateCast "bigint" "numeric" ImplicitCastContext,
+>         CatCreateCast "interval" "interval" ImplicitCastContext,
+>         CatCreateCast "interval" "time" AssignmentCastContext,
+>         CatCreateCast "numeric" "real" ImplicitCastContext,
+>         CatCreateCast "numeric" "float" ImplicitCastContext,
+>         CatCreateCast "numeric" "smallint" AssignmentCastContext,
+>         CatCreateCast "numeric" "int" AssignmentCastContext,
+>         CatCreateCast "numeric" "bigint" AssignmentCastContext,
+>         CatCreateCast "numeric" "numeric" ImplicitCastContext,
+>         CatCreateCast "time" "interval" ImplicitCastContext,
+>         CatCreateCast "time" "time" ImplicitCastContext,
+>         CatCreateCast "timestamp" "date" AssignmentCastContext,
+>         CatCreateCast "timestamp" "time" AssignmentCastContext,
+>         CatCreateCast "timestamp" "timestamp" ImplicitCastContext,
+>         CatCreateCast "varchar" "char" AssignmentCastContext,
+>         CatCreateCast "varchar" "varchar" ImplicitCastContext,
+>         CatCreateTypeCategoryEntry "boolean" ("B", True),
+>         CatCreateTypeCategoryEntry "char" ("S", False),
+>         CatCreateTypeCategoryEntry "date" ("D", False),
+>         CatCreateTypeCategoryEntry "real" ("N", False),
+>         CatCreateTypeCategoryEntry "float" ("N", True),
+>         CatCreateTypeCategoryEntry "smallint" ("N", False),
+>         CatCreateTypeCategoryEntry "int" ("N", False),
+>         CatCreateTypeCategoryEntry "bigint" ("N", False),
+>         CatCreateTypeCategoryEntry "interval" ("T", True),
+>         CatCreateTypeCategoryEntry "numeric" ("N", False),
+>         CatCreateTypeCategoryEntry "time" ("D", False),
+>         CatCreateTypeCategoryEntry "timestamp" ("D", False),
+>         CatCreateTypeCategoryEntry "varchar" ("S", False)]
+>         ++ baseCatalog "boolean" "int" ["char","varchar","clob","nchar","nvarchar","nclob"]
+
+>         )
diff --git a/src/Database/HsSqlPpp/Dialects/BaseCatalog.lhs b/src/Database/HsSqlPpp/Dialects/BaseCatalog.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Dialects/BaseCatalog.lhs
@@ -0,0 +1,114 @@
+
+This file contains special definitions which are used by pretty much
+every dialect.
+
+This includes the catalog entries to support:
+mixfix:
+between and not between
+
+keyword operators:
+and, or, not, (not) like, is (not) null, overlaps
+is (not) similar to
+is (not) { true | false | unknown }
+is (not) distinct from
+
+in (list version)
+
+almost-function like operators
+position
+substring
+convert
+translate
+overlay
+trim
+
+coalesce and nullif also appear here
+
+TODO: this isn't complete yet (we cannot even parse some of the above
+currently)
+
+todo: not sure how to handle:
+array subscript and ctor
+cast - very special case
+extract - special case because one of the args is a typename not
+  a scalar expr
+quantified comparisons?
+array and multiset ops
+other subqueries
+
+> {-# LANGUAGE DeriveDataTypeable,OverloadedStrings #-}
+>
+> module Database.HsSqlPpp.Dialects.BaseCatalog
+>     (baseCatalog
+>     --,insertOperators
+>      ) where
+> import Data.Text (Text)
+
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+
+> baseCatalog :: Text -> Text -> [Text] -> [CatalogUpdate]
+> baseCatalog boolTypeName intTypeName textTypeNames =
+>     CatCreateSchema "public"
+>     : (binaryOps boolTypeName intTypeName textTypeNames
+>        ++ prefixOps boolTypeName
+>        ++ postfixOps boolTypeName
+>        ++ functions
+>        ++ specialOps boolTypeName intTypeName textTypeNames)
+
+
+> binaryOps :: Text -> Text -> [Text] -> [CatalogUpdate]
+> binaryOps bool _int texts =
+>    [CatCreateBinaryOp "and" bool bool bool
+>    ,CatCreateBinaryOp "or" bool bool bool
+>    ] ++
+>    concat [ [CatCreateBinaryOp "like" t t bool
+>              -- todo: rename this to "not like"
+>              -- and other operators the same
+>             ,CatCreateBinaryOp "notlike" t t bool
+>              -- todo: overlaps needs a tuple?
+>             --,CatCreateBinaryOp "overlaps" t t bool
+>             --is (not) similar to
+>              -- is (not) distinct from
+>             ]
+>           | t <- texts]
+>    ++ -- these should go in a separate namespace, not functions
+>    [CatCreateFunction "between" ["anyelement","anyelement","anyelement"] False bool
+>    ,CatCreateFunction "notbetween" ["anyelement","anyelement","anyelement"] False bool
+>    ]
+
+todo: do some writeup on namespaces in the hssqlppp catalog code
+
+> specialOps :: Text -> Text -> [Text] -> [CatalogUpdate]
+> specialOps _bool int texts =
+>        -- these should go in a separate namespace along with between
+>        [CatCreateSpecialOp "substring" [t,int,int] False t
+>         -- in (list version) can be treated as a variadic special function
+>         -- extract ... takes a typename as one of the args
+>         -- position
+>         -- convert
+>         -- translate
+>         -- overlay
+>         -- trim
+
+>        | t <- texts]
+
+
+> prefixOps :: Text -> [CatalogUpdate]
+> prefixOps bool =
+>    [CatCreatePrefixOp "not" bool bool]
+
+> postfixOps :: Text -> [CatalogUpdate]
+> postfixOps bool =
+>    [CatCreatePostfixOp "isnull" "anyelement" bool
+>    ,CatCreatePostfixOp "isnotnull" "anyelement" bool
+>     -- is (not) { true | false | unknown }
+>    ]
+
+These appear here since basically every dialect has them the same. Not
+sure if this is a good enough reason.
+
+> functions :: [CatalogUpdate]
+> functions =
+>     [CatCreateVariadicFunction "coalesce" ["anyelement"] False "anyelement"
+>     ,CatCreateFunction "nullif" ["anyelement","anyelement"] False "anyelement"
+>     ]
diff --git a/src/Database/HsSqlPpp/Dialects/GeneratedPostgres.lhs b/src/Database/HsSqlPpp/Dialects/GeneratedPostgres.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Dialects/GeneratedPostgres.lhs
@@ -0,0 +1,6042 @@
+
+
+
+This file is auto generated, to regenerate run
+make regenDefaultTemplate1Catalog. You will need postgresql
+installed to do this.
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Dialects.GeneratedPostgres
+>      (generatedPostgresCatalogEntries) where
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+
+> -- | The catalog from a default template1 database in roughly the
+> -- latest postgres. 'select version()' from the dbms this catalog
+> -- was generated from: 'PostgreSQL 9.4.5 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 5.2.1-23) 5.2.1 20151028, 64-bit'.
+> generatedPostgresCatalogEntries :: [CatalogUpdate]
+> generatedPostgresCatalogEntries =
+
+    
+>        [ CatCreateScalarType "abstime"
+>        , CatCreateScalarType "aclitem"
+>        , CatCreateScalarType "bit"
+>        , CatCreateScalarType "bool"
+>        , CatCreateScalarType "box"
+>        , CatCreateScalarType "bpchar"
+>        , CatCreateScalarType "bytea"
+>        , CatCreateScalarType "char"
+>        , CatCreateScalarType "cid"
+>        , CatCreateScalarType "cidr"
+>        , CatCreateScalarType "circle"
+>        , CatCreateScalarType "date"
+>        , CatCreateScalarType "float4"
+>        , CatCreateScalarType "float8"
+>        , CatCreateScalarType "gtsvector"
+>        , CatCreateScalarType "inet"
+>        , CatCreateScalarType "int2"
+>        , CatCreateScalarType "int2vector"
+>        , CatCreateScalarType "int4"
+>        , CatCreateScalarType "int8"
+>        , CatCreateScalarType "interval"
+>        , CatCreateScalarType "json"
+>        , CatCreateScalarType "jsonb"
+>        , CatCreateScalarType "line"
+>        , CatCreateScalarType "lseg"
+>        , CatCreateScalarType "macaddr"
+>        , CatCreateScalarType "money"
+>        , CatCreateScalarType "name"
+>        , CatCreateScalarType "numeric"
+>        , CatCreateScalarType "oid"
+>        , CatCreateScalarType "oidvector"
+>        , CatCreateScalarType "path"
+>        , CatCreateScalarType "pg_lsn"
+>        , CatCreateScalarType "pg_node_tree"
+>        , CatCreateScalarType "point"
+>        , CatCreateScalarType "polygon"
+>        , CatCreateScalarType "refcursor"
+>        , CatCreateScalarType "regclass"
+>        , CatCreateScalarType "regconfig"
+>        , CatCreateScalarType "regdictionary"
+>        , CatCreateScalarType "regoper"
+>        , CatCreateScalarType "regoperator"
+>        , CatCreateScalarType "regproc"
+>        , CatCreateScalarType "regprocedure"
+>        , CatCreateScalarType "regtype"
+>        , CatCreateScalarType "reltime"
+>        , CatCreateScalarType "smgr"
+>        , CatCreateScalarType "text"
+>        , CatCreateScalarType "tid"
+>        , CatCreateScalarType "time"
+>        , CatCreateScalarType "timestamp"
+>        , CatCreateScalarType "timestamptz"
+>        , CatCreateScalarType "timetz"
+>        , CatCreateScalarType "tinterval"
+>        , CatCreateScalarType "tsquery"
+>        , CatCreateScalarType "tsvector"
+>        , CatCreateScalarType "txid_snapshot"
+>        , CatCreateScalarType "unknown"
+>        , CatCreateScalarType "uuid"
+>        , CatCreateScalarType "varbit"
+>        , CatCreateScalarType "varchar"
+>        , CatCreateScalarType "xid"
+>        , CatCreateScalarType "xml"
+>        , CatCreateDomainType "information_schema.yes_or_no" "varchar"
+>        , CatCreateCast
+>            "information_schema.yes_or_no" "varchar" ImplicitCastContext
+>        , CatCreateDomainType "information_schema.time_stamp" "timestamptz"
+>        , CatCreateCast
+>            "information_schema.time_stamp" "timestamptz" ImplicitCastContext
+>        , CatCreateDomainType "information_schema.sql_identifier" "varchar"
+>        , CatCreateCast
+>            "information_schema.sql_identifier" "varchar" ImplicitCastContext
+>        , CatCreateDomainType "information_schema.character_data" "varchar"
+>        , CatCreateCast
+>            "information_schema.character_data" "varchar" ImplicitCastContext
+>        , CatCreateDomainType "information_schema.cardinal_number" "int4"
+>        , CatCreateCast
+>            "information_schema.cardinal_number" "int4" ImplicitCastContext
+>        , CatCreateArrayType "_xml" "xml"
+>        , CatCreateTypeCategoryEntry "_xml" ( "A" , False )
+>        , CatCreateArrayType "_xid" "xid"
+>        , CatCreateTypeCategoryEntry "_xid" ( "A" , False )
+>        , CatCreateArrayType "_varchar" "varchar"
+>        , CatCreateTypeCategoryEntry "_varchar" ( "A" , False )
+>        , CatCreateArrayType "_varbit" "varbit"
+>        , CatCreateTypeCategoryEntry "_varbit" ( "A" , False )
+>        , CatCreateArrayType "_uuid" "uuid"
+>        , CatCreateTypeCategoryEntry "_uuid" ( "A" , False )
+>        , CatCreateArrayType "_txid_snapshot" "txid_snapshot"
+>        , CatCreateTypeCategoryEntry "_txid_snapshot" ( "A" , False )
+>        , CatCreateArrayType "_tsvector" "tsvector"
+>        , CatCreateTypeCategoryEntry "_tsvector" ( "A" , False )
+>        , CatCreateArrayType "_tstzrange" "tstzrange"
+>        , CatCreateTypeCategoryEntry "_tstzrange" ( "A" , False )
+>        , CatCreateArrayType "_tsrange" "tsrange"
+>        , CatCreateTypeCategoryEntry "_tsrange" ( "A" , False )
+>        , CatCreateArrayType "_tsquery" "tsquery"
+>        , CatCreateTypeCategoryEntry "_tsquery" ( "A" , False )
+>        , CatCreateArrayType "_tinterval" "tinterval"
+>        , CatCreateTypeCategoryEntry "_tinterval" ( "A" , False )
+>        , CatCreateArrayType "_timetz" "timetz"
+>        , CatCreateTypeCategoryEntry "_timetz" ( "A" , False )
+>        , CatCreateArrayType "_timestamptz" "timestamptz"
+>        , CatCreateTypeCategoryEntry "_timestamptz" ( "A" , False )
+>        , CatCreateArrayType "_timestamp" "timestamp"
+>        , CatCreateTypeCategoryEntry "_timestamp" ( "A" , False )
+>        , CatCreateArrayType "_time" "time"
+>        , CatCreateTypeCategoryEntry "_time" ( "A" , False )
+>        , CatCreateArrayType "_tid" "tid"
+>        , CatCreateTypeCategoryEntry "_tid" ( "A" , False )
+>        , CatCreateArrayType "_text" "text"
+>        , CatCreateTypeCategoryEntry "_text" ( "A" , False )
+>        , CatCreateArrayType "_reltime" "reltime"
+>        , CatCreateTypeCategoryEntry "_reltime" ( "A" , False )
+>        , CatCreateArrayType "_regtype" "regtype"
+>        , CatCreateTypeCategoryEntry "_regtype" ( "A" , False )
+>        , CatCreateArrayType "_regprocedure" "regprocedure"
+>        , CatCreateTypeCategoryEntry "_regprocedure" ( "A" , False )
+>        , CatCreateArrayType "_regproc" "regproc"
+>        , CatCreateTypeCategoryEntry "_regproc" ( "A" , False )
+>        , CatCreateArrayType "_regoperator" "regoperator"
+>        , CatCreateTypeCategoryEntry "_regoperator" ( "A" , False )
+>        , CatCreateArrayType "_regoper" "regoper"
+>        , CatCreateTypeCategoryEntry "_regoper" ( "A" , False )
+>        , CatCreateArrayType "_regdictionary" "regdictionary"
+>        , CatCreateTypeCategoryEntry "_regdictionary" ( "A" , False )
+>        , CatCreateArrayType "_regconfig" "regconfig"
+>        , CatCreateTypeCategoryEntry "_regconfig" ( "A" , False )
+>        , CatCreateArrayType "_regclass" "regclass"
+>        , CatCreateTypeCategoryEntry "_regclass" ( "A" , False )
+>        , CatCreateArrayType "_refcursor" "refcursor"
+>        , CatCreateTypeCategoryEntry "_refcursor" ( "A" , False )
+>        , CatCreateArrayType "_record" "record"
+>        , CatCreateTypeCategoryEntry "_record" ( "A" , False )
+>        , CatCreateArrayType "_polygon" "polygon"
+>        , CatCreateTypeCategoryEntry "_polygon" ( "A" , False )
+>        , CatCreateArrayType "_point" "point"
+>        , CatCreateTypeCategoryEntry "_point" ( "A" , False )
+>        , CatCreateArrayType "_pg_lsn" "pg_lsn"
+>        , CatCreateTypeCategoryEntry "_pg_lsn" ( "A" , False )
+>        , CatCreateArrayType "_path" "path"
+>        , CatCreateTypeCategoryEntry "_path" ( "A" , False )
+>        , CatCreateArrayType "_oidvector" "oidvector"
+>        , CatCreateTypeCategoryEntry "_oidvector" ( "A" , False )
+>        , CatCreateArrayType "_oid" "oid"
+>        , CatCreateTypeCategoryEntry "_oid" ( "A" , False )
+>        , CatCreateArrayType "_numrange" "numrange"
+>        , CatCreateTypeCategoryEntry "_numrange" ( "A" , False )
+>        , CatCreateArrayType "_numeric" "numeric"
+>        , CatCreateTypeCategoryEntry "_numeric" ( "A" , False )
+>        , CatCreateArrayType "_name" "name"
+>        , CatCreateTypeCategoryEntry "_name" ( "A" , False )
+>        , CatCreateArrayType "_money" "money"
+>        , CatCreateTypeCategoryEntry "_money" ( "A" , False )
+>        , CatCreateArrayType "_macaddr" "macaddr"
+>        , CatCreateTypeCategoryEntry "_macaddr" ( "A" , False )
+>        , CatCreateArrayType "_lseg" "lseg"
+>        , CatCreateTypeCategoryEntry "_lseg" ( "A" , False )
+>        , CatCreateArrayType "_line" "line"
+>        , CatCreateTypeCategoryEntry "_line" ( "A" , False )
+>        , CatCreateArrayType "_jsonb" "jsonb"
+>        , CatCreateTypeCategoryEntry "_jsonb" ( "A" , False )
+>        , CatCreateArrayType "_json" "json"
+>        , CatCreateTypeCategoryEntry "_json" ( "A" , False )
+>        , CatCreateArrayType "_interval" "interval"
+>        , CatCreateTypeCategoryEntry "_interval" ( "A" , False )
+>        , CatCreateArrayType "_int8range" "int8range"
+>        , CatCreateTypeCategoryEntry "_int8range" ( "A" , False )
+>        , CatCreateArrayType "_int8" "int8"
+>        , CatCreateTypeCategoryEntry "_int8" ( "A" , False )
+>        , CatCreateArrayType "_int4range" "int4range"
+>        , CatCreateTypeCategoryEntry "_int4range" ( "A" , False )
+>        , CatCreateArrayType "_int4" "int4"
+>        , CatCreateTypeCategoryEntry "_int4" ( "A" , False )
+>        , CatCreateArrayType "_int2vector" "int2vector"
+>        , CatCreateTypeCategoryEntry "_int2vector" ( "A" , False )
+>        , CatCreateArrayType "_int2" "int2"
+>        , CatCreateTypeCategoryEntry "_int2" ( "A" , False )
+>        , CatCreateArrayType "_inet" "inet"
+>        , CatCreateTypeCategoryEntry "_inet" ( "A" , False )
+>        , CatCreateArrayType "_gtsvector" "gtsvector"
+>        , CatCreateTypeCategoryEntry "_gtsvector" ( "A" , False )
+>        , CatCreateArrayType "_float8" "float8"
+>        , CatCreateTypeCategoryEntry "_float8" ( "A" , False )
+>        , CatCreateArrayType "_float4" "float4"
+>        , CatCreateTypeCategoryEntry "_float4" ( "A" , False )
+>        , CatCreateArrayType "_daterange" "daterange"
+>        , CatCreateTypeCategoryEntry "_daterange" ( "A" , False )
+>        , CatCreateArrayType "_date" "date"
+>        , CatCreateTypeCategoryEntry "_date" ( "A" , False )
+>        , CatCreateArrayType "_cstring" "cstring"
+>        , CatCreateTypeCategoryEntry "_cstring" ( "A" , False )
+>        , CatCreateArrayType "_circle" "circle"
+>        , CatCreateTypeCategoryEntry "_circle" ( "A" , False )
+>        , CatCreateArrayType "_cidr" "cidr"
+>        , CatCreateTypeCategoryEntry "_cidr" ( "A" , False )
+>        , CatCreateArrayType "_cid" "cid"
+>        , CatCreateTypeCategoryEntry "_cid" ( "A" , False )
+>        , CatCreateArrayType "_char" "char"
+>        , CatCreateTypeCategoryEntry "_char" ( "A" , False )
+>        , CatCreateArrayType "_bytea" "bytea"
+>        , CatCreateTypeCategoryEntry "_bytea" ( "A" , False )
+>        , CatCreateArrayType "_bpchar" "bpchar"
+>        , CatCreateTypeCategoryEntry "_bpchar" ( "A" , False )
+>        , CatCreateArrayType "_box" "box"
+>        , CatCreateTypeCategoryEntry "_box" ( "A" , False )
+>        , CatCreateArrayType "_bool" "bool"
+>        , CatCreateTypeCategoryEntry "_bool" ( "A" , False )
+>        , CatCreateArrayType "_bit" "bit"
+>        , CatCreateTypeCategoryEntry "_bit" ( "A" , False )
+>        , CatCreateArrayType "_aclitem" "aclitem"
+>        , CatCreateTypeCategoryEntry "_aclitem" ( "A" , False )
+>        , CatCreateArrayType "_abstime" "abstime"
+>        , CatCreateTypeCategoryEntry "_abstime" ( "A" , False )
+>        , CatCreatePrefixOp "!!" "int8" "numeric"
+>        , CatCreatePrefixOp "!!" "tsquery" "tsquery"
+>        , CatCreatePrefixOp "#" "path" "int4"
+>        , CatCreatePrefixOp "#" "polygon" "int4"
+>        , CatCreatePrefixOp "+" "int8" "int8"
+>        , CatCreatePrefixOp "+" "int2" "int2"
+>        , CatCreatePrefixOp "+" "int4" "int4"
+>        , CatCreatePrefixOp "+" "float4" "float4"
+>        , CatCreatePrefixOp "+" "float8" "float8"
+>        , CatCreatePrefixOp "+" "numeric" "numeric"
+>        , CatCreatePrefixOp "-" "int8" "int8"
+>        , CatCreatePrefixOp "-" "int2" "int2"
+>        , CatCreatePrefixOp "-" "int4" "int4"
+>        , CatCreatePrefixOp "-" "float4" "float4"
+>        , CatCreatePrefixOp "-" "float8" "float8"
+>        , CatCreatePrefixOp "-" "interval" "interval"
+>        , CatCreatePrefixOp "-" "numeric" "numeric"
+>        , CatCreatePrefixOp "?-" "lseg" "bool"
+>        , CatCreatePrefixOp "?-" "line" "bool"
+>        , CatCreatePrefixOp "?|" "lseg" "bool"
+>        , CatCreatePrefixOp "?|" "line" "bool"
+>        , CatCreatePrefixOp "@" "int8" "int8"
+>        , CatCreatePrefixOp "@" "int2" "int2"
+>        , CatCreatePrefixOp "@" "int4" "int4"
+>        , CatCreatePrefixOp "@" "float4" "float4"
+>        , CatCreatePrefixOp "@" "float8" "float8"
+>        , CatCreatePrefixOp "@" "numeric" "numeric"
+>        , CatCreatePrefixOp "@-@" "lseg" "float8"
+>        , CatCreatePrefixOp "@-@" "path" "float8"
+>        , CatCreatePrefixOp "@@" "lseg" "point"
+>        , CatCreatePrefixOp "@@" "path" "point"
+>        , CatCreatePrefixOp "@@" "box" "point"
+>        , CatCreatePrefixOp "@@" "polygon" "point"
+>        , CatCreatePrefixOp "@@" "circle" "point"
+>        , CatCreatePrefixOp "|" "tinterval" "abstime"
+>        , CatCreatePrefixOp "|/" "float8" "float8"
+>        , CatCreatePrefixOp "||/" "float8" "float8"
+>        , CatCreatePrefixOp "~" "int8" "int8"
+>        , CatCreatePrefixOp "~" "int2" "int2"
+>        , CatCreatePrefixOp "~" "int4" "int4"
+>        , CatCreatePrefixOp "~" "macaddr" "macaddr"
+>        , CatCreatePrefixOp "~" "inet" "inet"
+>        , CatCreatePrefixOp "~" "bit" "bit"
+>        , CatCreatePostfixOp "!" "int8" "numeric"
+>        , CatCreateBinaryOp "!~" "name" "text" "bool"
+>        , CatCreateBinaryOp "!~" "text" "text" "bool"
+>        , CatCreateBinaryOp "!~" "bpchar" "text" "bool"
+>        , CatCreateBinaryOp "!~*" "name" "text" "bool"
+>        , CatCreateBinaryOp "!~*" "text" "text" "bool"
+>        , CatCreateBinaryOp "!~*" "bpchar" "text" "bool"
+>        , CatCreateBinaryOp "!~~" "bytea" "bytea" "bool"
+>        , CatCreateBinaryOp "!~~" "name" "text" "bool"
+>        , CatCreateBinaryOp "!~~" "text" "text" "bool"
+>        , CatCreateBinaryOp "!~~" "bpchar" "text" "bool"
+>        , CatCreateBinaryOp "!~~*" "name" "text" "bool"
+>        , CatCreateBinaryOp "!~~*" "text" "text" "bool"
+>        , CatCreateBinaryOp "!~~*" "bpchar" "text" "bool"
+>        , CatCreateBinaryOp "#" "int8" "int8" "int8"
+>        , CatCreateBinaryOp "#" "int2" "int2" "int2"
+>        , CatCreateBinaryOp "#" "int4" "int4" "int4"
+>        , CatCreateBinaryOp "#" "lseg" "lseg" "point"
+>        , CatCreateBinaryOp "#" "box" "box" "box"
+>        , CatCreateBinaryOp "#" "line" "line" "point"
+>        , CatCreateBinaryOp "#" "bit" "bit" "bit"
+>        , CatCreateBinaryOp "##" "point" "lseg" "point"
+>        , CatCreateBinaryOp "##" "point" "box" "point"
+>        , CatCreateBinaryOp "##" "point" "line" "point"
+>        , CatCreateBinaryOp "##" "lseg" "lseg" "point"
+>        , CatCreateBinaryOp "##" "lseg" "box" "point"
+>        , CatCreateBinaryOp "##" "lseg" "line" "point"
+>        , CatCreateBinaryOp "##" "line" "lseg" "point"
+>        , CatCreateBinaryOp "##" "line" "box" "point"
+>        , CatCreateBinaryOp "#<" "tinterval" "reltime" "bool"
+>        , CatCreateBinaryOp "#<=" "tinterval" "reltime" "bool"
+>        , CatCreateBinaryOp "#<>" "tinterval" "reltime" "bool"
+>        , CatCreateBinaryOp "#=" "tinterval" "reltime" "bool"
+>        , CatCreateBinaryOp "#>" "json" "_text" "json"
+>        , CatCreateBinaryOp "#>" "tinterval" "reltime" "bool"
+>        , CatCreateBinaryOp "#>" "jsonb" "_text" "jsonb"
+>        , CatCreateBinaryOp "#>=" "tinterval" "reltime" "bool"
+>        , CatCreateBinaryOp "#>>" "json" "_text" "text"
+>        , CatCreateBinaryOp "#>>" "jsonb" "_text" "text"
+>        , CatCreateBinaryOp "%" "int8" "int8" "int8"
+>        , CatCreateBinaryOp "%" "int2" "int2" "int2"
+>        , CatCreateBinaryOp "%" "int4" "int4" "int4"
+>        , CatCreateBinaryOp "%" "numeric" "numeric" "numeric"
+>        , CatCreateBinaryOp "&" "int8" "int8" "int8"
+>        , CatCreateBinaryOp "&" "int2" "int2" "int2"
+>        , CatCreateBinaryOp "&" "int4" "int4" "int4"
+>        , CatCreateBinaryOp "&" "macaddr" "macaddr" "macaddr"
+>        , CatCreateBinaryOp "&" "inet" "inet" "inet"
+>        , CatCreateBinaryOp "&" "bit" "bit" "bit"
+>        , CatCreateBinaryOp "&&" "box" "box" "bool"
+>        , CatCreateBinaryOp "&&" "polygon" "polygon" "bool"
+>        , CatCreateBinaryOp "&&" "tinterval" "tinterval" "bool"
+>        , CatCreateBinaryOp "&&" "circle" "circle" "bool"
+>        , CatCreateBinaryOp "&&" "inet" "inet" "bool"
+>        , CatCreateBinaryOp "&&" "anyarray" "anyarray" "bool"
+>        , CatCreateBinaryOp "&&" "tsquery" "tsquery" "tsquery"
+>        , CatCreateBinaryOp "&&" "anyrange" "anyrange" "bool"
+>        , CatCreateBinaryOp "&<" "box" "box" "bool"
+>        , CatCreateBinaryOp "&<" "polygon" "polygon" "bool"
+>        , CatCreateBinaryOp "&<" "circle" "circle" "bool"
+>        , CatCreateBinaryOp "&<" "anyrange" "anyrange" "bool"
+>        , CatCreateBinaryOp "&<|" "box" "box" "bool"
+>        , CatCreateBinaryOp "&<|" "polygon" "polygon" "bool"
+>        , CatCreateBinaryOp "&<|" "circle" "circle" "bool"
+>        , CatCreateBinaryOp "&>" "box" "box" "bool"
+>        , CatCreateBinaryOp "&>" "polygon" "polygon" "bool"
+>        , CatCreateBinaryOp "&>" "circle" "circle" "bool"
+>        , CatCreateBinaryOp "&>" "anyrange" "anyrange" "bool"
+>        , CatCreateBinaryOp "*" "int8" "int8" "int8"
+>        , CatCreateBinaryOp "*" "int8" "int2" "int8"
+>        , CatCreateBinaryOp "*" "int8" "int4" "int8"
+>        , CatCreateBinaryOp "*" "int2" "int8" "int8"
+>        , CatCreateBinaryOp "*" "int2" "int2" "int2"
+>        , CatCreateBinaryOp "*" "int2" "int4" "int4"
+>        , CatCreateBinaryOp "*" "int2" "money" "money"
+>        , CatCreateBinaryOp "*" "int4" "int8" "int8"
+>        , CatCreateBinaryOp "*" "int4" "int2" "int4"
+>        , CatCreateBinaryOp "*" "int4" "int4" "int4"
+>        , CatCreateBinaryOp "*" "int4" "money" "money"
+>        , CatCreateBinaryOp "*" "point" "point" "point"
+>        , CatCreateBinaryOp "*" "path" "point" "path"
+>        , CatCreateBinaryOp "*" "box" "point" "box"
+>        , CatCreateBinaryOp "*" "float4" "float4" "float4"
+>        , CatCreateBinaryOp "*" "float4" "float8" "float8"
+>        , CatCreateBinaryOp "*" "float4" "money" "money"
+>        , CatCreateBinaryOp "*" "float8" "float4" "float8"
+>        , CatCreateBinaryOp "*" "float8" "float8" "float8"
+>        , CatCreateBinaryOp "*" "float8" "money" "money"
+>        , CatCreateBinaryOp "*" "float8" "interval" "interval"
+>        , CatCreateBinaryOp "*" "circle" "point" "circle"
+>        , CatCreateBinaryOp "*" "money" "int2" "money"
+>        , CatCreateBinaryOp "*" "money" "int4" "money"
+>        , CatCreateBinaryOp "*" "money" "float4" "money"
+>        , CatCreateBinaryOp "*" "money" "float8" "money"
+>        , CatCreateBinaryOp "*" "interval" "float8" "interval"
+>        , CatCreateBinaryOp "*" "numeric" "numeric" "numeric"
+>        , CatCreateBinaryOp "*" "anyrange" "anyrange" "anyrange"
+>        , CatCreateBinaryOp "*<" "record" "record" "bool"
+>        , CatCreateBinaryOp "*<=" "record" "record" "bool"
+>        , CatCreateBinaryOp "*<>" "record" "record" "bool"
+>        , CatCreateBinaryOp "*=" "record" "record" "bool"
+>        , CatCreateBinaryOp "*>" "record" "record" "bool"
+>        , CatCreateBinaryOp "*>=" "record" "record" "bool"
+>        , CatCreateBinaryOp "+" "int8" "int8" "int8"
+>        , CatCreateBinaryOp "+" "int8" "int2" "int8"
+>        , CatCreateBinaryOp "+" "int8" "int4" "int8"
+>        , CatCreateBinaryOp "+" "int8" "inet" "inet"
+>        , CatCreateBinaryOp "+" "int2" "int8" "int8"
+>        , CatCreateBinaryOp "+" "int2" "int2" "int2"
+>        , CatCreateBinaryOp "+" "int2" "int4" "int4"
+>        , CatCreateBinaryOp "+" "int4" "int8" "int8"
+>        , CatCreateBinaryOp "+" "int4" "int2" "int4"
+>        , CatCreateBinaryOp "+" "int4" "int4" "int4"
+>        , CatCreateBinaryOp "+" "int4" "date" "date"
+>        , CatCreateBinaryOp "+" "point" "point" "point"
+>        , CatCreateBinaryOp "+" "path" "point" "path"
+>        , CatCreateBinaryOp "+" "path" "path" "path"
+>        , CatCreateBinaryOp "+" "box" "point" "box"
+>        , CatCreateBinaryOp "+" "float4" "float4" "float4"
+>        , CatCreateBinaryOp "+" "float4" "float8" "float8"
+>        , CatCreateBinaryOp "+" "float8" "float4" "float8"
+>        , CatCreateBinaryOp "+" "float8" "float8" "float8"
+>        , CatCreateBinaryOp "+" "abstime" "reltime" "abstime"
+>        , CatCreateBinaryOp "+" "circle" "point" "circle"
+>        , CatCreateBinaryOp "+" "money" "money" "money"
+>        , CatCreateBinaryOp "+" "inet" "int8" "inet"
+>        , CatCreateBinaryOp "+" "_aclitem" "aclitem" "_aclitem"
+>        , CatCreateBinaryOp "+" "date" "int4" "date"
+>        , CatCreateBinaryOp "+" "date" "time" "timestamp"
+>        , CatCreateBinaryOp "+" "date" "interval" "timestamp"
+>        , CatCreateBinaryOp "+" "date" "timetz" "timestamptz"
+>        , CatCreateBinaryOp "+" "time" "date" "timestamp"
+>        , CatCreateBinaryOp "+" "time" "interval" "time"
+>        , CatCreateBinaryOp "+" "timestamp" "interval" "timestamp"
+>        , CatCreateBinaryOp "+" "timestamptz" "interval" "timestamptz"
+>        , CatCreateBinaryOp "+" "interval" "date" "timestamp"
+>        , CatCreateBinaryOp "+" "interval" "time" "time"
+>        , CatCreateBinaryOp "+" "interval" "timestamp" "timestamp"
+>        , CatCreateBinaryOp "+" "interval" "timestamptz" "timestamptz"
+>        , CatCreateBinaryOp "+" "interval" "interval" "interval"
+>        , CatCreateBinaryOp "+" "interval" "timetz" "timetz"
+>        , CatCreateBinaryOp "+" "timetz" "date" "timestamptz"
+>        , CatCreateBinaryOp "+" "timetz" "interval" "timetz"
+>        , CatCreateBinaryOp "+" "numeric" "numeric" "numeric"
+>        , CatCreateBinaryOp "+" "anyrange" "anyrange" "anyrange"
+>        , CatCreateBinaryOp "-" "int8" "int8" "int8"
+>        , CatCreateBinaryOp "-" "int8" "int2" "int8"
+>        , CatCreateBinaryOp "-" "int8" "int4" "int8"
+>        , CatCreateBinaryOp "-" "int2" "int8" "int8"
+>        , CatCreateBinaryOp "-" "int2" "int2" "int2"
+>        , CatCreateBinaryOp "-" "int2" "int4" "int4"
+>        , CatCreateBinaryOp "-" "int4" "int8" "int8"
+>        , CatCreateBinaryOp "-" "int4" "int2" "int4"
+>        , CatCreateBinaryOp "-" "int4" "int4" "int4"
+>        , CatCreateBinaryOp "-" "point" "point" "point"
+>        , CatCreateBinaryOp "-" "path" "point" "path"
+>        , CatCreateBinaryOp "-" "box" "point" "box"
+>        , CatCreateBinaryOp "-" "float4" "float4" "float4"
+>        , CatCreateBinaryOp "-" "float4" "float8" "float8"
+>        , CatCreateBinaryOp "-" "float8" "float4" "float8"
+>        , CatCreateBinaryOp "-" "float8" "float8" "float8"
+>        , CatCreateBinaryOp "-" "abstime" "reltime" "abstime"
+>        , CatCreateBinaryOp "-" "circle" "point" "circle"
+>        , CatCreateBinaryOp "-" "money" "money" "money"
+>        , CatCreateBinaryOp "-" "inet" "int8" "inet"
+>        , CatCreateBinaryOp "-" "inet" "inet" "int8"
+>        , CatCreateBinaryOp "-" "_aclitem" "aclitem" "_aclitem"
+>        , CatCreateBinaryOp "-" "date" "int4" "date"
+>        , CatCreateBinaryOp "-" "date" "date" "int4"
+>        , CatCreateBinaryOp "-" "date" "interval" "timestamp"
+>        , CatCreateBinaryOp "-" "time" "time" "interval"
+>        , CatCreateBinaryOp "-" "time" "interval" "time"
+>        , CatCreateBinaryOp "-" "timestamp" "timestamp" "interval"
+>        , CatCreateBinaryOp "-" "timestamp" "interval" "timestamp"
+>        , CatCreateBinaryOp "-" "timestamptz" "timestamptz" "interval"
+>        , CatCreateBinaryOp "-" "timestamptz" "interval" "timestamptz"
+>        , CatCreateBinaryOp "-" "interval" "interval" "interval"
+>        , CatCreateBinaryOp "-" "timetz" "interval" "timetz"
+>        , CatCreateBinaryOp "-" "numeric" "numeric" "numeric"
+>        , CatCreateBinaryOp "-" "pg_lsn" "pg_lsn" "numeric"
+>        , CatCreateBinaryOp "-" "anyrange" "anyrange" "anyrange"
+>        , CatCreateBinaryOp "->" "json" "int4" "json"
+>        , CatCreateBinaryOp "->" "json" "text" "json"
+>        , CatCreateBinaryOp "->" "jsonb" "int4" "jsonb"
+>        , CatCreateBinaryOp "->" "jsonb" "text" "jsonb"
+>        , CatCreateBinaryOp "->>" "json" "int4" "text"
+>        , CatCreateBinaryOp "->>" "json" "text" "text"
+>        , CatCreateBinaryOp "->>" "jsonb" "int4" "text"
+>        , CatCreateBinaryOp "->>" "jsonb" "text" "text"
+>        , CatCreateBinaryOp "-|-" "anyrange" "anyrange" "bool"
+>        , CatCreateBinaryOp "/" "int8" "int8" "int8"
+>        , CatCreateBinaryOp "/" "int8" "int2" "int8"
+>        , CatCreateBinaryOp "/" "int8" "int4" "int8"
+>        , CatCreateBinaryOp "/" "int2" "int8" "int8"
+>        , CatCreateBinaryOp "/" "int2" "int2" "int2"
+>        , CatCreateBinaryOp "/" "int2" "int4" "int4"
+>        , CatCreateBinaryOp "/" "int4" "int8" "int8"
+>        , CatCreateBinaryOp "/" "int4" "int2" "int4"
+>        , CatCreateBinaryOp "/" "int4" "int4" "int4"
+>        , CatCreateBinaryOp "/" "point" "point" "point"
+>        , CatCreateBinaryOp "/" "path" "point" "path"
+>        , CatCreateBinaryOp "/" "box" "point" "box"
+>        , CatCreateBinaryOp "/" "float4" "float4" "float4"
+>        , CatCreateBinaryOp "/" "float4" "float8" "float8"
+>        , CatCreateBinaryOp "/" "float8" "float4" "float8"
+>        , CatCreateBinaryOp "/" "float8" "float8" "float8"
+>        , CatCreateBinaryOp "/" "circle" "point" "circle"
+>        , CatCreateBinaryOp "/" "money" "int2" "money"
+>        , CatCreateBinaryOp "/" "money" "int4" "money"
+>        , CatCreateBinaryOp "/" "money" "float4" "money"
+>        , CatCreateBinaryOp "/" "money" "float8" "money"
+>        , CatCreateBinaryOp "/" "money" "money" "float8"
+>        , CatCreateBinaryOp "/" "interval" "float8" "interval"
+>        , CatCreateBinaryOp "/" "numeric" "numeric" "numeric"
+>        , CatCreateBinaryOp "<" "bool" "bool" "bool"
+>        , CatCreateBinaryOp "<" "bytea" "bytea" "bool"
+>        , CatCreateBinaryOp "<" "char" "char" "bool"
+>        , CatCreateBinaryOp "<" "name" "name" "bool"
+>        , CatCreateBinaryOp "<" "int8" "int8" "bool"
+>        , CatCreateBinaryOp "<" "int8" "int2" "bool"
+>        , CatCreateBinaryOp "<" "int8" "int4" "bool"
+>        , CatCreateBinaryOp "<" "int2" "int8" "bool"
+>        , CatCreateBinaryOp "<" "int2" "int2" "bool"
+>        , CatCreateBinaryOp "<" "int2" "int4" "bool"
+>        , CatCreateBinaryOp "<" "int4" "int8" "bool"
+>        , CatCreateBinaryOp "<" "int4" "int2" "bool"
+>        , CatCreateBinaryOp "<" "int4" "int4" "bool"
+>        , CatCreateBinaryOp "<" "text" "text" "bool"
+>        , CatCreateBinaryOp "<" "oid" "oid" "bool"
+>        , CatCreateBinaryOp "<" "tid" "tid" "bool"
+>        , CatCreateBinaryOp "<" "oidvector" "oidvector" "bool"
+>        , CatCreateBinaryOp "<" "lseg" "lseg" "bool"
+>        , CatCreateBinaryOp "<" "path" "path" "bool"
+>        , CatCreateBinaryOp "<" "box" "box" "bool"
+>        , CatCreateBinaryOp "<" "float4" "float4" "bool"
+>        , CatCreateBinaryOp "<" "float4" "float8" "bool"
+>        , CatCreateBinaryOp "<" "float8" "float4" "bool"
+>        , CatCreateBinaryOp "<" "float8" "float8" "bool"
+>        , CatCreateBinaryOp "<" "abstime" "abstime" "bool"
+>        , CatCreateBinaryOp "<" "reltime" "reltime" "bool"
+>        , CatCreateBinaryOp "<" "tinterval" "tinterval" "bool"
+>        , CatCreateBinaryOp "<" "circle" "circle" "bool"
+>        , CatCreateBinaryOp "<" "money" "money" "bool"
+>        , CatCreateBinaryOp "<" "macaddr" "macaddr" "bool"
+>        , CatCreateBinaryOp "<" "inet" "inet" "bool"
+>        , CatCreateBinaryOp "<" "bpchar" "bpchar" "bool"
+>        , CatCreateBinaryOp "<" "date" "date" "bool"
+>        , CatCreateBinaryOp "<" "date" "timestamp" "bool"
+>        , CatCreateBinaryOp "<" "date" "timestamptz" "bool"
+>        , CatCreateBinaryOp "<" "time" "time" "bool"
+>        , CatCreateBinaryOp "<" "timestamp" "date" "bool"
+>        , CatCreateBinaryOp "<" "timestamp" "timestamp" "bool"
+>        , CatCreateBinaryOp "<" "timestamp" "timestamptz" "bool"
+>        , CatCreateBinaryOp "<" "timestamptz" "date" "bool"
+>        , CatCreateBinaryOp "<" "timestamptz" "timestamp" "bool"
+>        , CatCreateBinaryOp "<" "timestamptz" "timestamptz" "bool"
+>        , CatCreateBinaryOp "<" "interval" "interval" "bool"
+>        , CatCreateBinaryOp "<" "timetz" "timetz" "bool"
+>        , CatCreateBinaryOp "<" "bit" "bit" "bool"
+>        , CatCreateBinaryOp "<" "varbit" "varbit" "bool"
+>        , CatCreateBinaryOp "<" "numeric" "numeric" "bool"
+>        , CatCreateBinaryOp "<" "record" "record" "bool"
+>        , CatCreateBinaryOp "<" "anyarray" "anyarray" "bool"
+>        , CatCreateBinaryOp "<" "uuid" "uuid" "bool"
+>        , CatCreateBinaryOp "<" "pg_lsn" "pg_lsn" "bool"
+>        , CatCreateBinaryOp "<" "anyenum" "anyenum" "bool"
+>        , CatCreateBinaryOp "<" "tsvector" "tsvector" "bool"
+>        , CatCreateBinaryOp "<" "tsquery" "tsquery" "bool"
+>        , CatCreateBinaryOp "<" "jsonb" "jsonb" "bool"
+>        , CatCreateBinaryOp "<" "anyrange" "anyrange" "bool"
+>        , CatCreateBinaryOp "<#>" "abstime" "abstime" "tinterval"
+>        , CatCreateBinaryOp "<->" "point" "point" "float8"
+>        , CatCreateBinaryOp "<->" "point" "lseg" "float8"
+>        , CatCreateBinaryOp "<->" "point" "path" "float8"
+>        , CatCreateBinaryOp "<->" "point" "box" "float8"
+>        , CatCreateBinaryOp "<->" "point" "line" "float8"
+>        , CatCreateBinaryOp "<->" "point" "circle" "float8"
+>        , CatCreateBinaryOp "<->" "lseg" "lseg" "float8"
+>        , CatCreateBinaryOp "<->" "lseg" "box" "float8"
+>        , CatCreateBinaryOp "<->" "lseg" "line" "float8"
+>        , CatCreateBinaryOp "<->" "path" "path" "float8"
+>        , CatCreateBinaryOp "<->" "box" "box" "float8"
+>        , CatCreateBinaryOp "<->" "polygon" "polygon" "float8"
+>        , CatCreateBinaryOp "<->" "line" "box" "float8"
+>        , CatCreateBinaryOp "<->" "line" "line" "float8"
+>        , CatCreateBinaryOp "<->" "circle" "polygon" "float8"
+>        , CatCreateBinaryOp "<->" "circle" "circle" "float8"
+>        , CatCreateBinaryOp "<<" "int8" "int4" "int8"
+>        , CatCreateBinaryOp "<<" "int2" "int4" "int2"
+>        , CatCreateBinaryOp "<<" "int4" "int4" "int4"
+>        , CatCreateBinaryOp "<<" "point" "point" "bool"
+>        , CatCreateBinaryOp "<<" "box" "box" "bool"
+>        , CatCreateBinaryOp "<<" "polygon" "polygon" "bool"
+>        , CatCreateBinaryOp "<<" "tinterval" "tinterval" "bool"
+>        , CatCreateBinaryOp "<<" "circle" "circle" "bool"
+>        , CatCreateBinaryOp "<<" "inet" "inet" "bool"
+>        , CatCreateBinaryOp "<<" "bit" "int4" "bit"
+>        , CatCreateBinaryOp "<<" "anyrange" "anyrange" "bool"
+>        , CatCreateBinaryOp "<<=" "inet" "inet" "bool"
+>        , CatCreateBinaryOp "<<|" "box" "box" "bool"
+>        , CatCreateBinaryOp "<<|" "polygon" "polygon" "bool"
+>        , CatCreateBinaryOp "<<|" "circle" "circle" "bool"
+>        , CatCreateBinaryOp "<=" "bool" "bool" "bool"
+>        , CatCreateBinaryOp "<=" "bytea" "bytea" "bool"
+>        , CatCreateBinaryOp "<=" "char" "char" "bool"
+>        , CatCreateBinaryOp "<=" "name" "name" "bool"
+>        , CatCreateBinaryOp "<=" "int8" "int8" "bool"
+>        , CatCreateBinaryOp "<=" "int8" "int2" "bool"
+>        , CatCreateBinaryOp "<=" "int8" "int4" "bool"
+>        , CatCreateBinaryOp "<=" "int2" "int8" "bool"
+>        , CatCreateBinaryOp "<=" "int2" "int2" "bool"
+>        , CatCreateBinaryOp "<=" "int2" "int4" "bool"
+>        , CatCreateBinaryOp "<=" "int4" "int8" "bool"
+>        , CatCreateBinaryOp "<=" "int4" "int2" "bool"
+>        , CatCreateBinaryOp "<=" "int4" "int4" "bool"
+>        , CatCreateBinaryOp "<=" "text" "text" "bool"
+>        , CatCreateBinaryOp "<=" "oid" "oid" "bool"
+>        , CatCreateBinaryOp "<=" "tid" "tid" "bool"
+>        , CatCreateBinaryOp "<=" "oidvector" "oidvector" "bool"
+>        , CatCreateBinaryOp "<=" "lseg" "lseg" "bool"
+>        , CatCreateBinaryOp "<=" "path" "path" "bool"
+>        , CatCreateBinaryOp "<=" "box" "box" "bool"
+>        , CatCreateBinaryOp "<=" "float4" "float4" "bool"
+>        , CatCreateBinaryOp "<=" "float4" "float8" "bool"
+>        , CatCreateBinaryOp "<=" "float8" "float4" "bool"
+>        , CatCreateBinaryOp "<=" "float8" "float8" "bool"
+>        , CatCreateBinaryOp "<=" "abstime" "abstime" "bool"
+>        , CatCreateBinaryOp "<=" "reltime" "reltime" "bool"
+>        , CatCreateBinaryOp "<=" "tinterval" "tinterval" "bool"
+>        , CatCreateBinaryOp "<=" "circle" "circle" "bool"
+>        , CatCreateBinaryOp "<=" "money" "money" "bool"
+>        , CatCreateBinaryOp "<=" "macaddr" "macaddr" "bool"
+>        , CatCreateBinaryOp "<=" "inet" "inet" "bool"
+>        , CatCreateBinaryOp "<=" "bpchar" "bpchar" "bool"
+>        , CatCreateBinaryOp "<=" "date" "date" "bool"
+>        , CatCreateBinaryOp "<=" "date" "timestamp" "bool"
+>        , CatCreateBinaryOp "<=" "date" "timestamptz" "bool"
+>        , CatCreateBinaryOp "<=" "time" "time" "bool"
+>        , CatCreateBinaryOp "<=" "timestamp" "date" "bool"
+>        , CatCreateBinaryOp "<=" "timestamp" "timestamp" "bool"
+>        , CatCreateBinaryOp "<=" "timestamp" "timestamptz" "bool"
+>        , CatCreateBinaryOp "<=" "timestamptz" "date" "bool"
+>        , CatCreateBinaryOp "<=" "timestamptz" "timestamp" "bool"
+>        , CatCreateBinaryOp "<=" "timestamptz" "timestamptz" "bool"
+>        , CatCreateBinaryOp "<=" "interval" "interval" "bool"
+>        , CatCreateBinaryOp "<=" "timetz" "timetz" "bool"
+>        , CatCreateBinaryOp "<=" "bit" "bit" "bool"
+>        , CatCreateBinaryOp "<=" "varbit" "varbit" "bool"
+>        , CatCreateBinaryOp "<=" "numeric" "numeric" "bool"
+>        , CatCreateBinaryOp "<=" "record" "record" "bool"
+>        , CatCreateBinaryOp "<=" "anyarray" "anyarray" "bool"
+>        , CatCreateBinaryOp "<=" "uuid" "uuid" "bool"
+>        , CatCreateBinaryOp "<=" "pg_lsn" "pg_lsn" "bool"
+>        , CatCreateBinaryOp "<=" "anyenum" "anyenum" "bool"
+>        , CatCreateBinaryOp "<=" "tsvector" "tsvector" "bool"
+>        , CatCreateBinaryOp "<=" "tsquery" "tsquery" "bool"
+>        , CatCreateBinaryOp "<=" "jsonb" "jsonb" "bool"
+>        , CatCreateBinaryOp "<=" "anyrange" "anyrange" "bool"
+>        , CatCreateBinaryOp "<>" "bool" "bool" "bool"
+>        , CatCreateBinaryOp "<>" "bytea" "bytea" "bool"
+>        , CatCreateBinaryOp "<>" "char" "char" "bool"
+>        , CatCreateBinaryOp "<>" "name" "name" "bool"
+>        , CatCreateBinaryOp "<>" "int8" "int8" "bool"
+>        , CatCreateBinaryOp "<>" "int8" "int2" "bool"
+>        , CatCreateBinaryOp "<>" "int8" "int4" "bool"
+>        , CatCreateBinaryOp "<>" "int2" "int8" "bool"
+>        , CatCreateBinaryOp "<>" "int2" "int2" "bool"
+>        , CatCreateBinaryOp "<>" "int2" "int4" "bool"
+>        , CatCreateBinaryOp "<>" "int4" "int8" "bool"
+>        , CatCreateBinaryOp "<>" "int4" "int2" "bool"
+>        , CatCreateBinaryOp "<>" "int4" "int4" "bool"
+>        , CatCreateBinaryOp "<>" "text" "text" "bool"
+>        , CatCreateBinaryOp "<>" "oid" "oid" "bool"
+>        , CatCreateBinaryOp "<>" "tid" "tid" "bool"
+>        , CatCreateBinaryOp "<>" "oidvector" "oidvector" "bool"
+>        , CatCreateBinaryOp "<>" "point" "point" "bool"
+>        , CatCreateBinaryOp "<>" "lseg" "lseg" "bool"
+>        , CatCreateBinaryOp "<>" "float4" "float4" "bool"
+>        , CatCreateBinaryOp "<>" "float4" "float8" "bool"
+>        , CatCreateBinaryOp "<>" "float8" "float4" "bool"
+>        , CatCreateBinaryOp "<>" "float8" "float8" "bool"
+>        , CatCreateBinaryOp "<>" "abstime" "abstime" "bool"
+>        , CatCreateBinaryOp "<>" "reltime" "reltime" "bool"
+>        , CatCreateBinaryOp "<>" "tinterval" "tinterval" "bool"
+>        , CatCreateBinaryOp "<>" "circle" "circle" "bool"
+>        , CatCreateBinaryOp "<>" "money" "money" "bool"
+>        , CatCreateBinaryOp "<>" "macaddr" "macaddr" "bool"
+>        , CatCreateBinaryOp "<>" "inet" "inet" "bool"
+>        , CatCreateBinaryOp "<>" "bpchar" "bpchar" "bool"
+>        , CatCreateBinaryOp "<>" "date" "date" "bool"
+>        , CatCreateBinaryOp "<>" "date" "timestamp" "bool"
+>        , CatCreateBinaryOp "<>" "date" "timestamptz" "bool"
+>        , CatCreateBinaryOp "<>" "time" "time" "bool"
+>        , CatCreateBinaryOp "<>" "timestamp" "date" "bool"
+>        , CatCreateBinaryOp "<>" "timestamp" "timestamp" "bool"
+>        , CatCreateBinaryOp "<>" "timestamp" "timestamptz" "bool"
+>        , CatCreateBinaryOp "<>" "timestamptz" "date" "bool"
+>        , CatCreateBinaryOp "<>" "timestamptz" "timestamp" "bool"
+>        , CatCreateBinaryOp "<>" "timestamptz" "timestamptz" "bool"
+>        , CatCreateBinaryOp "<>" "interval" "interval" "bool"
+>        , CatCreateBinaryOp "<>" "timetz" "timetz" "bool"
+>        , CatCreateBinaryOp "<>" "bit" "bit" "bool"
+>        , CatCreateBinaryOp "<>" "varbit" "varbit" "bool"
+>        , CatCreateBinaryOp "<>" "numeric" "numeric" "bool"
+>        , CatCreateBinaryOp "<>" "record" "record" "bool"
+>        , CatCreateBinaryOp "<>" "anyarray" "anyarray" "bool"
+>        , CatCreateBinaryOp "<>" "uuid" "uuid" "bool"
+>        , CatCreateBinaryOp "<>" "pg_lsn" "pg_lsn" "bool"
+>        , CatCreateBinaryOp "<>" "anyenum" "anyenum" "bool"
+>        , CatCreateBinaryOp "<>" "tsvector" "tsvector" "bool"
+>        , CatCreateBinaryOp "<>" "tsquery" "tsquery" "bool"
+>        , CatCreateBinaryOp "<>" "jsonb" "jsonb" "bool"
+>        , CatCreateBinaryOp "<>" "anyrange" "anyrange" "bool"
+>        , CatCreateBinaryOp "<?>" "abstime" "tinterval" "bool"
+>        , CatCreateBinaryOp "<@" "point" "lseg" "bool"
+>        , CatCreateBinaryOp "<@" "point" "path" "bool"
+>        , CatCreateBinaryOp "<@" "point" "box" "bool"
+>        , CatCreateBinaryOp "<@" "point" "polygon" "bool"
+>        , CatCreateBinaryOp "<@" "point" "line" "bool"
+>        , CatCreateBinaryOp "<@" "point" "circle" "bool"
+>        , CatCreateBinaryOp "<@" "lseg" "box" "bool"
+>        , CatCreateBinaryOp "<@" "lseg" "line" "bool"
+>        , CatCreateBinaryOp "<@" "box" "box" "bool"
+>        , CatCreateBinaryOp "<@" "polygon" "polygon" "bool"
+>        , CatCreateBinaryOp "<@" "circle" "circle" "bool"
+>        , CatCreateBinaryOp "<@" "anyarray" "anyarray" "bool"
+>        , CatCreateBinaryOp "<@" "anyelement" "anyrange" "bool"
+>        , CatCreateBinaryOp "<@" "tsquery" "tsquery" "bool"
+>        , CatCreateBinaryOp "<@" "jsonb" "jsonb" "bool"
+>        , CatCreateBinaryOp "<@" "anyrange" "anyrange" "bool"
+>        , CatCreateBinaryOp "<^" "point" "point" "bool"
+>        , CatCreateBinaryOp "<^" "box" "box" "bool"
+>        , CatCreateBinaryOp "=" "bool" "bool" "bool"
+>        , CatCreateBinaryOp "=" "bytea" "bytea" "bool"
+>        , CatCreateBinaryOp "=" "char" "char" "bool"
+>        , CatCreateBinaryOp "=" "name" "name" "bool"
+>        , CatCreateBinaryOp "=" "int8" "int8" "bool"
+>        , CatCreateBinaryOp "=" "int8" "int2" "bool"
+>        , CatCreateBinaryOp "=" "int8" "int4" "bool"
+>        , CatCreateBinaryOp "=" "int2" "int8" "bool"
+>        , CatCreateBinaryOp "=" "int2" "int2" "bool"
+>        , CatCreateBinaryOp "=" "int2" "int4" "bool"
+>        , CatCreateBinaryOp "=" "int2vector" "int2vector" "bool"
+>        , CatCreateBinaryOp "=" "int4" "int8" "bool"
+>        , CatCreateBinaryOp "=" "int4" "int2" "bool"
+>        , CatCreateBinaryOp "=" "int4" "int4" "bool"
+>        , CatCreateBinaryOp "=" "text" "text" "bool"
+>        , CatCreateBinaryOp "=" "oid" "oid" "bool"
+>        , CatCreateBinaryOp "=" "tid" "tid" "bool"
+>        , CatCreateBinaryOp "=" "xid" "int4" "bool"
+>        , CatCreateBinaryOp "=" "xid" "xid" "bool"
+>        , CatCreateBinaryOp "=" "cid" "cid" "bool"
+>        , CatCreateBinaryOp "=" "oidvector" "oidvector" "bool"
+>        , CatCreateBinaryOp "=" "lseg" "lseg" "bool"
+>        , CatCreateBinaryOp "=" "path" "path" "bool"
+>        , CatCreateBinaryOp "=" "box" "box" "bool"
+>        , CatCreateBinaryOp "=" "line" "line" "bool"
+>        , CatCreateBinaryOp "=" "float4" "float4" "bool"
+>        , CatCreateBinaryOp "=" "float4" "float8" "bool"
+>        , CatCreateBinaryOp "=" "float8" "float4" "bool"
+>        , CatCreateBinaryOp "=" "float8" "float8" "bool"
+>        , CatCreateBinaryOp "=" "abstime" "abstime" "bool"
+>        , CatCreateBinaryOp "=" "reltime" "reltime" "bool"
+>        , CatCreateBinaryOp "=" "tinterval" "tinterval" "bool"
+>        , CatCreateBinaryOp "=" "circle" "circle" "bool"
+>        , CatCreateBinaryOp "=" "money" "money" "bool"
+>        , CatCreateBinaryOp "=" "macaddr" "macaddr" "bool"
+>        , CatCreateBinaryOp "=" "inet" "inet" "bool"
+>        , CatCreateBinaryOp "=" "aclitem" "aclitem" "bool"
+>        , CatCreateBinaryOp "=" "bpchar" "bpchar" "bool"
+>        , CatCreateBinaryOp "=" "date" "date" "bool"
+>        , CatCreateBinaryOp "=" "date" "timestamp" "bool"
+>        , CatCreateBinaryOp "=" "date" "timestamptz" "bool"
+>        , CatCreateBinaryOp "=" "time" "time" "bool"
+>        , CatCreateBinaryOp "=" "timestamp" "date" "bool"
+>        , CatCreateBinaryOp "=" "timestamp" "timestamp" "bool"
+>        , CatCreateBinaryOp "=" "timestamp" "timestamptz" "bool"
+>        , CatCreateBinaryOp "=" "timestamptz" "date" "bool"
+>        , CatCreateBinaryOp "=" "timestamptz" "timestamp" "bool"
+>        , CatCreateBinaryOp "=" "timestamptz" "timestamptz" "bool"
+>        , CatCreateBinaryOp "=" "interval" "interval" "bool"
+>        , CatCreateBinaryOp "=" "timetz" "timetz" "bool"
+>        , CatCreateBinaryOp "=" "bit" "bit" "bool"
+>        , CatCreateBinaryOp "=" "varbit" "varbit" "bool"
+>        , CatCreateBinaryOp "=" "numeric" "numeric" "bool"
+>        , CatCreateBinaryOp "=" "record" "record" "bool"
+>        , CatCreateBinaryOp "=" "anyarray" "anyarray" "bool"
+>        , CatCreateBinaryOp "=" "uuid" "uuid" "bool"
+>        , CatCreateBinaryOp "=" "pg_lsn" "pg_lsn" "bool"
+>        , CatCreateBinaryOp "=" "anyenum" "anyenum" "bool"
+>        , CatCreateBinaryOp "=" "tsvector" "tsvector" "bool"
+>        , CatCreateBinaryOp "=" "tsquery" "tsquery" "bool"
+>        , CatCreateBinaryOp "=" "jsonb" "jsonb" "bool"
+>        , CatCreateBinaryOp "=" "anyrange" "anyrange" "bool"
+>        , CatCreateBinaryOp ">" "bool" "bool" "bool"
+>        , CatCreateBinaryOp ">" "bytea" "bytea" "bool"
+>        , CatCreateBinaryOp ">" "char" "char" "bool"
+>        , CatCreateBinaryOp ">" "name" "name" "bool"
+>        , CatCreateBinaryOp ">" "int8" "int8" "bool"
+>        , CatCreateBinaryOp ">" "int8" "int2" "bool"
+>        , CatCreateBinaryOp ">" "int8" "int4" "bool"
+>        , CatCreateBinaryOp ">" "int2" "int8" "bool"
+>        , CatCreateBinaryOp ">" "int2" "int2" "bool"
+>        , CatCreateBinaryOp ">" "int2" "int4" "bool"
+>        , CatCreateBinaryOp ">" "int4" "int8" "bool"
+>        , CatCreateBinaryOp ">" "int4" "int2" "bool"
+>        , CatCreateBinaryOp ">" "int4" "int4" "bool"
+>        , CatCreateBinaryOp ">" "text" "text" "bool"
+>        , CatCreateBinaryOp ">" "oid" "oid" "bool"
+>        , CatCreateBinaryOp ">" "tid" "tid" "bool"
+>        , CatCreateBinaryOp ">" "oidvector" "oidvector" "bool"
+>        , CatCreateBinaryOp ">" "lseg" "lseg" "bool"
+>        , CatCreateBinaryOp ">" "path" "path" "bool"
+>        , CatCreateBinaryOp ">" "box" "box" "bool"
+>        , CatCreateBinaryOp ">" "float4" "float4" "bool"
+>        , CatCreateBinaryOp ">" "float4" "float8" "bool"
+>        , CatCreateBinaryOp ">" "float8" "float4" "bool"
+>        , CatCreateBinaryOp ">" "float8" "float8" "bool"
+>        , CatCreateBinaryOp ">" "abstime" "abstime" "bool"
+>        , CatCreateBinaryOp ">" "reltime" "reltime" "bool"
+>        , CatCreateBinaryOp ">" "tinterval" "tinterval" "bool"
+>        , CatCreateBinaryOp ">" "circle" "circle" "bool"
+>        , CatCreateBinaryOp ">" "money" "money" "bool"
+>        , CatCreateBinaryOp ">" "macaddr" "macaddr" "bool"
+>        , CatCreateBinaryOp ">" "inet" "inet" "bool"
+>        , CatCreateBinaryOp ">" "bpchar" "bpchar" "bool"
+>        , CatCreateBinaryOp ">" "date" "date" "bool"
+>        , CatCreateBinaryOp ">" "date" "timestamp" "bool"
+>        , CatCreateBinaryOp ">" "date" "timestamptz" "bool"
+>        , CatCreateBinaryOp ">" "time" "time" "bool"
+>        , CatCreateBinaryOp ">" "timestamp" "date" "bool"
+>        , CatCreateBinaryOp ">" "timestamp" "timestamp" "bool"
+>        , CatCreateBinaryOp ">" "timestamp" "timestamptz" "bool"
+>        , CatCreateBinaryOp ">" "timestamptz" "date" "bool"
+>        , CatCreateBinaryOp ">" "timestamptz" "timestamp" "bool"
+>        , CatCreateBinaryOp ">" "timestamptz" "timestamptz" "bool"
+>        , CatCreateBinaryOp ">" "interval" "interval" "bool"
+>        , CatCreateBinaryOp ">" "timetz" "timetz" "bool"
+>        , CatCreateBinaryOp ">" "bit" "bit" "bool"
+>        , CatCreateBinaryOp ">" "varbit" "varbit" "bool"
+>        , CatCreateBinaryOp ">" "numeric" "numeric" "bool"
+>        , CatCreateBinaryOp ">" "record" "record" "bool"
+>        , CatCreateBinaryOp ">" "anyarray" "anyarray" "bool"
+>        , CatCreateBinaryOp ">" "uuid" "uuid" "bool"
+>        , CatCreateBinaryOp ">" "pg_lsn" "pg_lsn" "bool"
+>        , CatCreateBinaryOp ">" "anyenum" "anyenum" "bool"
+>        , CatCreateBinaryOp ">" "tsvector" "tsvector" "bool"
+>        , CatCreateBinaryOp ">" "tsquery" "tsquery" "bool"
+>        , CatCreateBinaryOp ">" "jsonb" "jsonb" "bool"
+>        , CatCreateBinaryOp ">" "anyrange" "anyrange" "bool"
+>        , CatCreateBinaryOp ">=" "bool" "bool" "bool"
+>        , CatCreateBinaryOp ">=" "bytea" "bytea" "bool"
+>        , CatCreateBinaryOp ">=" "char" "char" "bool"
+>        , CatCreateBinaryOp ">=" "name" "name" "bool"
+>        , CatCreateBinaryOp ">=" "int8" "int8" "bool"
+>        , CatCreateBinaryOp ">=" "int8" "int2" "bool"
+>        , CatCreateBinaryOp ">=" "int8" "int4" "bool"
+>        , CatCreateBinaryOp ">=" "int2" "int8" "bool"
+>        , CatCreateBinaryOp ">=" "int2" "int2" "bool"
+>        , CatCreateBinaryOp ">=" "int2" "int4" "bool"
+>        , CatCreateBinaryOp ">=" "int4" "int8" "bool"
+>        , CatCreateBinaryOp ">=" "int4" "int2" "bool"
+>        , CatCreateBinaryOp ">=" "int4" "int4" "bool"
+>        , CatCreateBinaryOp ">=" "text" "text" "bool"
+>        , CatCreateBinaryOp ">=" "oid" "oid" "bool"
+>        , CatCreateBinaryOp ">=" "tid" "tid" "bool"
+>        , CatCreateBinaryOp ">=" "oidvector" "oidvector" "bool"
+>        , CatCreateBinaryOp ">=" "lseg" "lseg" "bool"
+>        , CatCreateBinaryOp ">=" "path" "path" "bool"
+>        , CatCreateBinaryOp ">=" "box" "box" "bool"
+>        , CatCreateBinaryOp ">=" "float4" "float4" "bool"
+>        , CatCreateBinaryOp ">=" "float4" "float8" "bool"
+>        , CatCreateBinaryOp ">=" "float8" "float4" "bool"
+>        , CatCreateBinaryOp ">=" "float8" "float8" "bool"
+>        , CatCreateBinaryOp ">=" "abstime" "abstime" "bool"
+>        , CatCreateBinaryOp ">=" "reltime" "reltime" "bool"
+>        , CatCreateBinaryOp ">=" "tinterval" "tinterval" "bool"
+>        , CatCreateBinaryOp ">=" "circle" "circle" "bool"
+>        , CatCreateBinaryOp ">=" "money" "money" "bool"
+>        , CatCreateBinaryOp ">=" "macaddr" "macaddr" "bool"
+>        , CatCreateBinaryOp ">=" "inet" "inet" "bool"
+>        , CatCreateBinaryOp ">=" "bpchar" "bpchar" "bool"
+>        , CatCreateBinaryOp ">=" "date" "date" "bool"
+>        , CatCreateBinaryOp ">=" "date" "timestamp" "bool"
+>        , CatCreateBinaryOp ">=" "date" "timestamptz" "bool"
+>        , CatCreateBinaryOp ">=" "time" "time" "bool"
+>        , CatCreateBinaryOp ">=" "timestamp" "date" "bool"
+>        , CatCreateBinaryOp ">=" "timestamp" "timestamp" "bool"
+>        , CatCreateBinaryOp ">=" "timestamp" "timestamptz" "bool"
+>        , CatCreateBinaryOp ">=" "timestamptz" "date" "bool"
+>        , CatCreateBinaryOp ">=" "timestamptz" "timestamp" "bool"
+>        , CatCreateBinaryOp ">=" "timestamptz" "timestamptz" "bool"
+>        , CatCreateBinaryOp ">=" "interval" "interval" "bool"
+>        , CatCreateBinaryOp ">=" "timetz" "timetz" "bool"
+>        , CatCreateBinaryOp ">=" "bit" "bit" "bool"
+>        , CatCreateBinaryOp ">=" "varbit" "varbit" "bool"
+>        , CatCreateBinaryOp ">=" "numeric" "numeric" "bool"
+>        , CatCreateBinaryOp ">=" "record" "record" "bool"
+>        , CatCreateBinaryOp ">=" "anyarray" "anyarray" "bool"
+>        , CatCreateBinaryOp ">=" "uuid" "uuid" "bool"
+>        , CatCreateBinaryOp ">=" "pg_lsn" "pg_lsn" "bool"
+>        , CatCreateBinaryOp ">=" "anyenum" "anyenum" "bool"
+>        , CatCreateBinaryOp ">=" "tsvector" "tsvector" "bool"
+>        , CatCreateBinaryOp ">=" "tsquery" "tsquery" "bool"
+>        , CatCreateBinaryOp ">=" "jsonb" "jsonb" "bool"
+>        , CatCreateBinaryOp ">=" "anyrange" "anyrange" "bool"
+>        , CatCreateBinaryOp ">>" "int8" "int4" "int8"
+>        , CatCreateBinaryOp ">>" "int2" "int4" "int2"
+>        , CatCreateBinaryOp ">>" "int4" "int4" "int4"
+>        , CatCreateBinaryOp ">>" "point" "point" "bool"
+>        , CatCreateBinaryOp ">>" "box" "box" "bool"
+>        , CatCreateBinaryOp ">>" "polygon" "polygon" "bool"
+>        , CatCreateBinaryOp ">>" "circle" "circle" "bool"
+>        , CatCreateBinaryOp ">>" "inet" "inet" "bool"
+>        , CatCreateBinaryOp ">>" "bit" "int4" "bit"
+>        , CatCreateBinaryOp ">>" "anyrange" "anyrange" "bool"
+>        , CatCreateBinaryOp ">>=" "inet" "inet" "bool"
+>        , CatCreateBinaryOp ">^" "point" "point" "bool"
+>        , CatCreateBinaryOp ">^" "box" "box" "bool"
+>        , CatCreateBinaryOp "?" "jsonb" "text" "bool"
+>        , CatCreateBinaryOp "?#" "lseg" "lseg" "bool"
+>        , CatCreateBinaryOp "?#" "lseg" "box" "bool"
+>        , CatCreateBinaryOp "?#" "lseg" "line" "bool"
+>        , CatCreateBinaryOp "?#" "path" "path" "bool"
+>        , CatCreateBinaryOp "?#" "box" "box" "bool"
+>        , CatCreateBinaryOp "?#" "line" "box" "bool"
+>        , CatCreateBinaryOp "?#" "line" "line" "bool"
+>        , CatCreateBinaryOp "?&" "jsonb" "_text" "bool"
+>        , CatCreateBinaryOp "?-" "point" "point" "bool"
+>        , CatCreateBinaryOp "?-|" "lseg" "lseg" "bool"
+>        , CatCreateBinaryOp "?-|" "line" "line" "bool"
+>        , CatCreateBinaryOp "?|" "point" "point" "bool"
+>        , CatCreateBinaryOp "?|" "jsonb" "_text" "bool"
+>        , CatCreateBinaryOp "?||" "lseg" "lseg" "bool"
+>        , CatCreateBinaryOp "?||" "line" "line" "bool"
+>        , CatCreateBinaryOp "@>" "path" "point" "bool"
+>        , CatCreateBinaryOp "@>" "box" "point" "bool"
+>        , CatCreateBinaryOp "@>" "box" "box" "bool"
+>        , CatCreateBinaryOp "@>" "polygon" "point" "bool"
+>        , CatCreateBinaryOp "@>" "polygon" "polygon" "bool"
+>        , CatCreateBinaryOp "@>" "circle" "point" "bool"
+>        , CatCreateBinaryOp "@>" "circle" "circle" "bool"
+>        , CatCreateBinaryOp "@>" "_aclitem" "aclitem" "bool"
+>        , CatCreateBinaryOp "@>" "anyarray" "anyarray" "bool"
+>        , CatCreateBinaryOp "@>" "tsquery" "tsquery" "bool"
+>        , CatCreateBinaryOp "@>" "jsonb" "jsonb" "bool"
+>        , CatCreateBinaryOp "@>" "anyrange" "anyelement" "bool"
+>        , CatCreateBinaryOp "@>" "anyrange" "anyrange" "bool"
+>        , CatCreateBinaryOp "@@" "text" "text" "bool"
+>        , CatCreateBinaryOp "@@" "text" "tsquery" "bool"
+>        , CatCreateBinaryOp "@@" "tsvector" "tsquery" "bool"
+>        , CatCreateBinaryOp "@@" "tsquery" "tsvector" "bool"
+>        , CatCreateBinaryOp "@@@" "tsvector" "tsquery" "bool"
+>        , CatCreateBinaryOp "@@@" "tsquery" "tsvector" "bool"
+>        , CatCreateBinaryOp "^" "float8" "float8" "float8"
+>        , CatCreateBinaryOp "^" "numeric" "numeric" "numeric"
+>        , CatCreateBinaryOp "|" "int8" "int8" "int8"
+>        , CatCreateBinaryOp "|" "int2" "int2" "int2"
+>        , CatCreateBinaryOp "|" "int4" "int4" "int4"
+>        , CatCreateBinaryOp "|" "macaddr" "macaddr" "macaddr"
+>        , CatCreateBinaryOp "|" "inet" "inet" "inet"
+>        , CatCreateBinaryOp "|" "bit" "bit" "bit"
+>        , CatCreateBinaryOp "|&>" "box" "box" "bool"
+>        , CatCreateBinaryOp "|&>" "polygon" "polygon" "bool"
+>        , CatCreateBinaryOp "|&>" "circle" "circle" "bool"
+>        , CatCreateBinaryOp "|>>" "box" "box" "bool"
+>        , CatCreateBinaryOp "|>>" "polygon" "polygon" "bool"
+>        , CatCreateBinaryOp "|>>" "circle" "circle" "bool"
+>        , CatCreateBinaryOp "||" "bytea" "bytea" "bytea"
+>        , CatCreateBinaryOp "||" "text" "text" "text"
+>        , CatCreateBinaryOp "||" "text" "anynonarray" "text"
+>        , CatCreateBinaryOp "||" "varbit" "varbit" "varbit"
+>        , CatCreateBinaryOp "||" "anyarray" "anyarray" "anyarray"
+>        , CatCreateBinaryOp "||" "anyarray" "anyelement" "anyarray"
+>        , CatCreateBinaryOp "||" "anyelement" "anyarray" "anyarray"
+>        , CatCreateBinaryOp "||" "anynonarray" "text" "text"
+>        , CatCreateBinaryOp "||" "tsvector" "tsvector" "tsvector"
+>        , CatCreateBinaryOp "||" "tsquery" "tsquery" "tsquery"
+>        , CatCreateBinaryOp "~" "name" "text" "bool"
+>        , CatCreateBinaryOp "~" "text" "text" "bool"
+>        , CatCreateBinaryOp "~" "path" "point" "bool"
+>        , CatCreateBinaryOp "~" "box" "box" "bool"
+>        , CatCreateBinaryOp "~" "polygon" "point" "bool"
+>        , CatCreateBinaryOp "~" "polygon" "polygon" "bool"
+>        , CatCreateBinaryOp "~" "circle" "point" "bool"
+>        , CatCreateBinaryOp "~" "circle" "circle" "bool"
+>        , CatCreateBinaryOp "~" "_aclitem" "aclitem" "bool"
+>        , CatCreateBinaryOp "~" "bpchar" "text" "bool"
+>        , CatCreateBinaryOp "~*" "name" "text" "bool"
+>        , CatCreateBinaryOp "~*" "text" "text" "bool"
+>        , CatCreateBinaryOp "~*" "bpchar" "text" "bool"
+>        , CatCreateBinaryOp "~<=~" "text" "text" "bool"
+>        , CatCreateBinaryOp "~<=~" "bpchar" "bpchar" "bool"
+>        , CatCreateBinaryOp "~<~" "text" "text" "bool"
+>        , CatCreateBinaryOp "~<~" "bpchar" "bpchar" "bool"
+>        , CatCreateBinaryOp "~=" "point" "point" "bool"
+>        , CatCreateBinaryOp "~=" "box" "box" "bool"
+>        , CatCreateBinaryOp "~=" "polygon" "polygon" "bool"
+>        , CatCreateBinaryOp "~=" "tinterval" "tinterval" "bool"
+>        , CatCreateBinaryOp "~=" "circle" "circle" "bool"
+>        , CatCreateBinaryOp "~>=~" "text" "text" "bool"
+>        , CatCreateBinaryOp "~>=~" "bpchar" "bpchar" "bool"
+>        , CatCreateBinaryOp "~>~" "text" "text" "bool"
+>        , CatCreateBinaryOp "~>~" "bpchar" "bpchar" "bool"
+>        , CatCreateBinaryOp "~~" "bytea" "bytea" "bool"
+>        , CatCreateBinaryOp "~~" "name" "text" "bool"
+>        , CatCreateBinaryOp "~~" "text" "text" "bool"
+>        , CatCreateBinaryOp "~~" "bpchar" "text" "bool"
+>        , CatCreateBinaryOp "~~*" "name" "text" "bool"
+>        , CatCreateBinaryOp "~~*" "text" "text" "bool"
+>        , CatCreateBinaryOp "~~*" "bpchar" "text" "bool"
+>        , CatCreateFunction "abbrev" [ "inet" ] False "text"
+>        , CatCreateFunction "abbrev" [ "cidr" ] False "text"
+>        , CatCreateFunction "abs" [ "float4" ] False "float4"
+>        , CatCreateFunction "abs" [ "float8" ] False "float8"
+>        , CatCreateFunction "abs" [ "int8" ] False "int8"
+>        , CatCreateFunction "abs" [ "int4" ] False "int4"
+>        , CatCreateFunction "abs" [ "int2" ] False "int2"
+>        , CatCreateFunction "abs" [ "numeric" ] False "numeric"
+>        , CatCreateFunction "abstime" [ "timestamptz" ] False "abstime"
+>        , CatCreateFunction "abstime" [ "timestamp" ] False "abstime"
+>        , CatCreateFunction
+>            "abstimeeq" [ "abstime" , "abstime" ] False "bool"
+>        , CatCreateFunction
+>            "abstimege" [ "abstime" , "abstime" ] False "bool"
+>        , CatCreateFunction
+>            "abstimegt" [ "abstime" , "abstime" ] False "bool"
+>        , CatCreateFunction "abstimein" [ "cstring" ] False "abstime"
+>        , CatCreateFunction
+>            "abstimele" [ "abstime" , "abstime" ] False "bool"
+>        , CatCreateFunction
+>            "abstimelt" [ "abstime" , "abstime" ] False "bool"
+>        , CatCreateFunction
+>            "abstimene" [ "abstime" , "abstime" ] False "bool"
+>        , CatCreateFunction "abstimeout" [ "abstime" ] False "cstring"
+>        , CatCreateFunction "abstimerecv" [ "internal" ] False "abstime"
+>        , CatCreateFunction "abstimesend" [ "abstime" ] False "bytea"
+>        , CatCreateFunction
+>            "aclcontains" [ "aclitem" , "_aclitem" ] False "bool"
+>        , CatCreateFunction
+>            "acldefault" [ "char" , "oid" ] False "_aclitem"
+>        , CatCreateFunction "aclexplode" [ "_aclitem" ] True "record"
+>        , CatCreateFunction
+>            "aclinsert" [ "aclitem" , "_aclitem" ] False "_aclitem"
+>        , CatCreateFunction
+>            "aclitemeq" [ "aclitem" , "aclitem" ] False "bool"
+>        , CatCreateFunction "aclitemin" [ "cstring" ] False "aclitem"
+>        , CatCreateFunction "aclitemout" [ "aclitem" ] False "cstring"
+>        , CatCreateFunction
+>            "aclremove" [ "aclitem" , "_aclitem" ] False "_aclitem"
+>        , CatCreateFunction "acos" [ "float8" ] False "float8"
+>        , CatCreateFunction "age" [ "xid" ] False "int4"
+>        , CatCreateFunction
+>            "age" [ "timestamptz" , "timestamptz" ] False "interval"
+>        , CatCreateFunction "age" [ "timestamptz" ] False "interval"
+>        , CatCreateFunction
+>            "age" [ "timestamp" , "timestamp" ] False "interval"
+>        , CatCreateFunction "age" [ "timestamp" ] False "interval"
+>        , CatCreateFunction "any_in" [ "cstring" ] False "any"
+>        , CatCreateFunction "any_out" [ "any" ] False "cstring"
+>        , CatCreateFunction "anyarray_in" [ "cstring" ] False "anyarray"
+>        , CatCreateFunction "anyarray_out" [ "anyarray" ] False "cstring"
+>        , CatCreateFunction "anyarray_recv" [ "internal" ] False "anyarray"
+>        , CatCreateFunction "anyarray_send" [ "anyarray" ] False "bytea"
+>        , CatCreateFunction
+>            "anyelement_in" [ "cstring" ] False "anyelement"
+>        , CatCreateFunction
+>            "anyelement_out" [ "anyelement" ] False "cstring"
+>        , CatCreateFunction "anyenum_in" [ "cstring" ] False "anyenum"
+>        , CatCreateFunction "anyenum_out" [ "anyenum" ] False "cstring"
+>        , CatCreateFunction
+>            "anynonarray_in" [ "cstring" ] False "anynonarray"
+>        , CatCreateFunction
+>            "anynonarray_out" [ "anynonarray" ] False "cstring"
+>        , CatCreateFunction
+>            "anyrange_in" [ "int4" , "cstring" , "oid" ] False "anyrange"
+>        , CatCreateFunction "anyrange_out" [ "anyrange" ] False "cstring"
+>        , CatCreateFunction
+>            "anytextcat" [ "text" , "anynonarray" ] False "text"
+>        , CatCreateFunction "area" [ "box" ] False "float8"
+>        , CatCreateFunction "area" [ "path" ] False "float8"
+>        , CatCreateFunction "area" [ "circle" ] False "float8"
+>        , CatCreateFunction
+>            "areajoinsel"
+>            [ "internal" , "internal" , "oid" , "internal" , "int2" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "areasel"
+>            [ "internal" , "int4" , "oid" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "array_agg_finalfn" [ "anyelement" , "internal" ] False "anyarray"
+>        , CatCreateFunction
+>            "array_agg_transfn" [ "internal" , "anyelement" ] False "internal"
+>        , CatCreateFunction
+>            "array_append" [ "anyelement" , "anyarray" ] False "anyarray"
+>        , CatCreateFunction
+>            "array_cat" [ "anyarray" , "anyarray" ] False "anyarray"
+>        , CatCreateFunction "array_dims" [ "anyarray" ] False "text"
+>        , CatCreateFunction
+>            "array_eq" [ "anyarray" , "anyarray" ] False "bool"
+>        , CatCreateFunction
+>            "array_fill" [ "_int4" , "anyelement" ] False "anyarray"
+>        , CatCreateFunction
+>            "array_fill" [ "_int4" , "anyelement" , "_int4" ] False "anyarray"
+>        , CatCreateFunction
+>            "array_ge" [ "anyarray" , "anyarray" ] False "bool"
+>        , CatCreateFunction
+>            "array_gt" [ "anyarray" , "anyarray" ] False "bool"
+>        , CatCreateFunction
+>            "array_in" [ "int4" , "cstring" , "oid" ] False "anyarray"
+>        , CatCreateFunction
+>            "array_larger" [ "anyarray" , "anyarray" ] False "anyarray"
+>        , CatCreateFunction
+>            "array_le" [ "anyarray" , "anyarray" ] False "bool"
+>        , CatCreateFunction
+>            "array_length" [ "int4" , "anyarray" ] False "int4"
+>        , CatCreateFunction
+>            "array_lower" [ "anyarray" , "int4" ] False "int4"
+>        , CatCreateFunction
+>            "array_lt" [ "anyarray" , "anyarray" ] False "bool"
+>        , CatCreateFunction "array_ndims" [ "anyarray" ] False "int4"
+>        , CatCreateFunction
+>            "array_ne" [ "anyarray" , "anyarray" ] False "bool"
+>        , CatCreateFunction "array_out" [ "anyarray" ] False "cstring"
+>        , CatCreateFunction
+>            "array_prepend" [ "anyelement" , "anyarray" ] False "anyarray"
+>        , CatCreateFunction
+>            "array_recv" [ "int4" , "internal" , "oid" ] False "anyarray"
+>        , CatCreateFunction
+>            "array_remove" [ "anyarray" , "anyelement" ] False "anyarray"
+>        , CatCreateFunction
+>            "array_replace"
+>            [ "anyelement" , "anyelement" , "anyarray" ]
+>            False
+>            "anyarray"
+>        , CatCreateFunction "array_send" [ "anyarray" ] False "bytea"
+>        , CatCreateFunction
+>            "array_smaller" [ "anyarray" , "anyarray" ] False "anyarray"
+>        , CatCreateFunction "array_to_json" [ "anyarray" ] False "json"
+>        , CatCreateFunction
+>            "array_to_json" [ "bool" , "anyarray" ] False "json"
+>        , CatCreateFunction
+>            "array_to_string" [ "text" , "anyarray" , "text" ] False "text"
+>        , CatCreateFunction
+>            "array_to_string" [ "text" , "anyarray" ] False "text"
+>        , CatCreateFunction "array_typanalyze" [ "internal" ] False "bool"
+>        , CatCreateFunction
+>            "array_upper" [ "anyarray" , "int4" ] False "int4"
+>        , CatCreateFunction
+>            "arraycontained" [ "anyarray" , "anyarray" ] False "bool"
+>        , CatCreateFunction
+>            "arraycontains" [ "anyarray" , "anyarray" ] False "bool"
+>        , CatCreateFunction
+>            "arraycontjoinsel"
+>            [ "internal" , "internal" , "oid" , "internal" , "int2" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "arraycontsel"
+>            [ "int4" , "internal" , "internal" , "oid" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "arrayoverlap" [ "anyarray" , "anyarray" ] False "bool"
+>        , CatCreateFunction "ascii" [ "text" ] False "int4"
+>        , CatCreateFunction
+>            "ascii_to_mic"
+>            [ "int4" , "int4" , "int4" , "cstring" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "ascii_to_utf8"
+>            [ "int4" , "cstring" , "int4" , "int4" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction "asin" [ "float8" ] False "float8"
+>        , CatCreateFunction "atan" [ "float8" ] False "float8"
+>        , CatCreateFunction "atan2" [ "float8" , "float8" ] False "float8"
+>        , CatCreateFunction
+>            "big5_to_euc_tw"
+>            [ "int4" , "int4" , "int4" , "internal" , "cstring" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "big5_to_mic"
+>            [ "int4" , "cstring" , "internal" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "big5_to_utf8"
+>            [ "int4" , "int4" , "cstring" , "int4" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction "bit" [ "int4" , "int4" ] False "bit"
+>        , CatCreateFunction "bit" [ "int4" , "bit" , "bool" ] False "bit"
+>        , CatCreateFunction "bit" [ "int8" , "int4" ] False "bit"
+>        , CatCreateFunction
+>            "bit_in" [ "int4" , "cstring" , "oid" ] False "bit"
+>        , CatCreateFunction "bit_length" [ "bytea" ] False "int4"
+>        , CatCreateFunction "bit_length" [ "text" ] False "int4"
+>        , CatCreateFunction "bit_length" [ "bit" ] False "int4"
+>        , CatCreateFunction "bit_out" [ "bit" ] False "cstring"
+>        , CatCreateFunction
+>            "bit_recv" [ "internal" , "oid" , "int4" ] False "bit"
+>        , CatCreateFunction "bit_send" [ "bit" ] False "bytea"
+>        , CatCreateFunction "bitand" [ "bit" , "bit" ] False "bit"
+>        , CatCreateFunction "bitcat" [ "varbit" , "varbit" ] False "varbit"
+>        , CatCreateFunction "bitcmp" [ "bit" , "bit" ] False "int4"
+>        , CatCreateFunction "biteq" [ "bit" , "bit" ] False "bool"
+>        , CatCreateFunction "bitge" [ "bit" , "bit" ] False "bool"
+>        , CatCreateFunction "bitgt" [ "bit" , "bit" ] False "bool"
+>        , CatCreateFunction "bitle" [ "bit" , "bit" ] False "bool"
+>        , CatCreateFunction "bitlt" [ "bit" , "bit" ] False "bool"
+>        , CatCreateFunction "bitne" [ "bit" , "bit" ] False "bool"
+>        , CatCreateFunction "bitnot" [ "bit" ] False "bit"
+>        , CatCreateFunction "bitor" [ "bit" , "bit" ] False "bit"
+>        , CatCreateFunction "bitshiftleft" [ "int4" , "bit" ] False "bit"
+>        , CatCreateFunction "bitshiftright" [ "bit" , "int4" ] False "bit"
+>        , CatCreateFunction "bittypmodin" [ "_cstring" ] False "int4"
+>        , CatCreateFunction "bittypmodout" [ "int4" ] False "cstring"
+>        , CatCreateFunction "bitxor" [ "bit" , "bit" ] False "bit"
+>        , CatCreateFunction "bool" [ "int4" ] False "bool"
+>        , CatCreateFunction
+>            "bool_accum" [ "bool" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "bool_accum_inv" [ "bool" , "internal" ] False "internal"
+>        , CatCreateFunction "bool_alltrue" [ "internal" ] False "bool"
+>        , CatCreateFunction "bool_anytrue" [ "internal" ] False "bool"
+>        , CatCreateFunction
+>            "booland_statefunc" [ "bool" , "bool" ] False "bool"
+>        , CatCreateFunction "booleq" [ "bool" , "bool" ] False "bool"
+>        , CatCreateFunction "boolge" [ "bool" , "bool" ] False "bool"
+>        , CatCreateFunction "boolgt" [ "bool" , "bool" ] False "bool"
+>        , CatCreateFunction "boolin" [ "cstring" ] False "bool"
+>        , CatCreateFunction "boolle" [ "bool" , "bool" ] False "bool"
+>        , CatCreateFunction "boollt" [ "bool" , "bool" ] False "bool"
+>        , CatCreateFunction "boolne" [ "bool" , "bool" ] False "bool"
+>        , CatCreateFunction
+>            "boolor_statefunc" [ "bool" , "bool" ] False "bool"
+>        , CatCreateFunction "boolout" [ "bool" ] False "cstring"
+>        , CatCreateFunction "boolrecv" [ "internal" ] False "bool"
+>        , CatCreateFunction "boolsend" [ "bool" ] False "bytea"
+>        , CatCreateFunction "box" [ "point" , "point" ] False "box"
+>        , CatCreateFunction "box" [ "polygon" ] False "box"
+>        , CatCreateFunction "box" [ "circle" ] False "box"
+>        , CatCreateFunction "box_above" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_above_eq" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_add" [ "point" , "box" ] False "box"
+>        , CatCreateFunction "box_below" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_below_eq" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_center" [ "box" ] False "point"
+>        , CatCreateFunction "box_contain" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction
+>            "box_contain_pt" [ "point" , "box" ] False "bool"
+>        , CatCreateFunction "box_contained" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_distance" [ "box" , "box" ] False "float8"
+>        , CatCreateFunction "box_div" [ "point" , "box" ] False "box"
+>        , CatCreateFunction "box_eq" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_ge" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_gt" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_in" [ "cstring" ] False "box"
+>        , CatCreateFunction "box_intersect" [ "box" , "box" ] False "box"
+>        , CatCreateFunction "box_le" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_left" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_lt" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_mul" [ "point" , "box" ] False "box"
+>        , CatCreateFunction "box_out" [ "box" ] False "cstring"
+>        , CatCreateFunction "box_overabove" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_overbelow" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_overlap" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_overleft" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_overright" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_recv" [ "internal" ] False "box"
+>        , CatCreateFunction "box_right" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_same" [ "box" , "box" ] False "bool"
+>        , CatCreateFunction "box_send" [ "box" ] False "bytea"
+>        , CatCreateFunction "box_sub" [ "point" , "box" ] False "box"
+>        , CatCreateFunction "bpchar" [ "name" ] False "bpchar"
+>        , CatCreateFunction
+>            "bpchar" [ "bpchar" , "bool" , "int4" ] False "bpchar"
+>        , CatCreateFunction "bpchar" [ "char" ] False "bpchar"
+>        , CatCreateFunction
+>            "bpchar_larger" [ "bpchar" , "bpchar" ] False "bpchar"
+>        , CatCreateFunction
+>            "bpchar_pattern_ge" [ "bpchar" , "bpchar" ] False "bool"
+>        , CatCreateFunction
+>            "bpchar_pattern_gt" [ "bpchar" , "bpchar" ] False "bool"
+>        , CatCreateFunction
+>            "bpchar_pattern_le" [ "bpchar" , "bpchar" ] False "bool"
+>        , CatCreateFunction
+>            "bpchar_pattern_lt" [ "bpchar" , "bpchar" ] False "bool"
+>        , CatCreateFunction
+>            "bpchar_smaller" [ "bpchar" , "bpchar" ] False "bpchar"
+>        , CatCreateFunction
+>            "bpcharcmp" [ "bpchar" , "bpchar" ] False "int4"
+>        , CatCreateFunction "bpchareq" [ "bpchar" , "bpchar" ] False "bool"
+>        , CatCreateFunction "bpcharge" [ "bpchar" , "bpchar" ] False "bool"
+>        , CatCreateFunction "bpchargt" [ "bpchar" , "bpchar" ] False "bool"
+>        , CatCreateFunction
+>            "bpchariclike" [ "bpchar" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "bpcharicnlike" [ "bpchar" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "bpcharicregexeq" [ "text" , "bpchar" ] False "bool"
+>        , CatCreateFunction
+>            "bpcharicregexne" [ "bpchar" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "bpcharin" [ "cstring" , "oid" , "int4" ] False "bpchar"
+>        , CatCreateFunction "bpcharle" [ "bpchar" , "bpchar" ] False "bool"
+>        , CatCreateFunction "bpcharlike" [ "text" , "bpchar" ] False "bool"
+>        , CatCreateFunction "bpcharlt" [ "bpchar" , "bpchar" ] False "bool"
+>        , CatCreateFunction "bpcharne" [ "bpchar" , "bpchar" ] False "bool"
+>        , CatCreateFunction
+>            "bpcharnlike" [ "text" , "bpchar" ] False "bool"
+>        , CatCreateFunction "bpcharout" [ "bpchar" ] False "cstring"
+>        , CatCreateFunction
+>            "bpcharrecv" [ "int4" , "oid" , "internal" ] False "bpchar"
+>        , CatCreateFunction
+>            "bpcharregexeq" [ "text" , "bpchar" ] False "bool"
+>        , CatCreateFunction
+>            "bpcharregexne" [ "text" , "bpchar" ] False "bool"
+>        , CatCreateFunction "bpcharsend" [ "bpchar" ] False "bytea"
+>        , CatCreateFunction "bpchartypmodin" [ "_cstring" ] False "int4"
+>        , CatCreateFunction "bpchartypmodout" [ "int4" ] False "cstring"
+>        , CatCreateFunction "broadcast" [ "inet" ] False "inet"
+>        , CatCreateFunction
+>            "btabstimecmp" [ "abstime" , "abstime" ] False "int4"
+>        , CatCreateFunction
+>            "btarraycmp" [ "anyarray" , "anyarray" ] False "int4"
+>        , CatCreateFunction
+>            "btbeginscan"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction "btboolcmp" [ "bool" , "bool" ] False "int4"
+>        , CatCreateFunction
+>            "btbpchar_pattern_cmp" [ "bpchar" , "bpchar" ] False "int4"
+>        , CatCreateFunction
+>            "btbuild" [ "internal" , "internal" , "internal" ] False "internal"
+>        , CatCreateFunction "btbuildempty" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "btbulkdelete"
+>            [ "internal" , "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction "btcanreturn" [ "internal" ] False "bool"
+>        , CatCreateFunction "btcharcmp" [ "char" , "char" ] False "int4"
+>        , CatCreateFunction
+>            "btcostestimate"
+>            [ "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "void"
+>        , CatCreateFunction "btendscan" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "btfloat48cmp" [ "float8" , "float4" ] False "int4"
+>        , CatCreateFunction
+>            "btfloat4cmp" [ "float4" , "float4" ] False "int4"
+>        , CatCreateFunction
+>            "btfloat4sortsupport" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "btfloat84cmp" [ "float4" , "float8" ] False "int4"
+>        , CatCreateFunction
+>            "btfloat8cmp" [ "float8" , "float8" ] False "int4"
+>        , CatCreateFunction
+>            "btfloat8sortsupport" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "btgetbitmap" [ "internal" , "internal" ] False "int8"
+>        , CatCreateFunction
+>            "btgettuple" [ "internal" , "internal" ] False "bool"
+>        , CatCreateFunction
+>            "btinsert"
+>            [ "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "bool"
+>        , CatCreateFunction "btint24cmp" [ "int4" , "int2" ] False "int4"
+>        , CatCreateFunction "btint28cmp" [ "int2" , "int8" ] False "int4"
+>        , CatCreateFunction "btint2cmp" [ "int2" , "int2" ] False "int4"
+>        , CatCreateFunction "btint2sortsupport" [ "internal" ] False "void"
+>        , CatCreateFunction "btint42cmp" [ "int2" , "int4" ] False "int4"
+>        , CatCreateFunction "btint48cmp" [ "int4" , "int8" ] False "int4"
+>        , CatCreateFunction "btint4cmp" [ "int4" , "int4" ] False "int4"
+>        , CatCreateFunction "btint4sortsupport" [ "internal" ] False "void"
+>        , CatCreateFunction "btint82cmp" [ "int8" , "int2" ] False "int4"
+>        , CatCreateFunction "btint84cmp" [ "int8" , "int4" ] False "int4"
+>        , CatCreateFunction "btint8cmp" [ "int8" , "int8" ] False "int4"
+>        , CatCreateFunction "btint8sortsupport" [ "internal" ] False "void"
+>        , CatCreateFunction "btmarkpos" [ "internal" ] False "void"
+>        , CatCreateFunction "btnamecmp" [ "name" , "name" ] False "int4"
+>        , CatCreateFunction "btnamesortsupport" [ "internal" ] False "void"
+>        , CatCreateFunction "btoidcmp" [ "oid" , "oid" ] False "int4"
+>        , CatCreateFunction "btoidsortsupport" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "btoidvectorcmp" [ "oidvector" , "oidvector" ] False "int4"
+>        , CatCreateFunction "btoptions" [ "bool" , "_text" ] False "bytea"
+>        , CatCreateFunction
+>            "btrecordcmp" [ "record" , "record" ] False "int4"
+>        , CatCreateFunction
+>            "btrecordimagecmp" [ "record" , "record" ] False "int4"
+>        , CatCreateFunction
+>            "btreltimecmp" [ "reltime" , "reltime" ] False "int4"
+>        , CatCreateFunction
+>            "btrescan"
+>            [ "internal" , "internal" , "internal" , "internal" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction "btrestrpos" [ "internal" ] False "void"
+>        , CatCreateFunction "btrim" [ "text" , "text" ] False "text"
+>        , CatCreateFunction "btrim" [ "text" ] False "text"
+>        , CatCreateFunction "btrim" [ "bytea" , "bytea" ] False "bytea"
+>        , CatCreateFunction
+>            "bttext_pattern_cmp" [ "text" , "text" ] False "int4"
+>        , CatCreateFunction "bttextcmp" [ "text" , "text" ] False "int4"
+>        , CatCreateFunction "bttidcmp" [ "tid" , "tid" ] False "int4"
+>        , CatCreateFunction
+>            "bttintervalcmp" [ "tinterval" , "tinterval" ] False "int4"
+>        , CatCreateFunction
+>            "btvacuumcleanup" [ "internal" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "bytea_string_agg_finalfn" [ "internal" ] False "bytea"
+>        , CatCreateFunction
+>            "bytea_string_agg_transfn"
+>            [ "internal" , "bytea" , "bytea" ]
+>            False
+>            "internal"
+>        , CatCreateFunction "byteacat" [ "bytea" , "bytea" ] False "bytea"
+>        , CatCreateFunction "byteacmp" [ "bytea" , "bytea" ] False "int4"
+>        , CatCreateFunction "byteaeq" [ "bytea" , "bytea" ] False "bool"
+>        , CatCreateFunction "byteage" [ "bytea" , "bytea" ] False "bool"
+>        , CatCreateFunction "byteagt" [ "bytea" , "bytea" ] False "bool"
+>        , CatCreateFunction "byteain" [ "cstring" ] False "bytea"
+>        , CatCreateFunction "byteale" [ "bytea" , "bytea" ] False "bool"
+>        , CatCreateFunction "bytealike" [ "bytea" , "bytea" ] False "bool"
+>        , CatCreateFunction "bytealt" [ "bytea" , "bytea" ] False "bool"
+>        , CatCreateFunction "byteane" [ "bytea" , "bytea" ] False "bool"
+>        , CatCreateFunction "byteanlike" [ "bytea" , "bytea" ] False "bool"
+>        , CatCreateFunction "byteaout" [ "bytea" ] False "cstring"
+>        , CatCreateFunction "bytearecv" [ "internal" ] False "bytea"
+>        , CatCreateFunction "byteasend" [ "bytea" ] False "bytea"
+>        , CatCreateFunction "cardinality" [ "anyarray" ] False "int4"
+>        , CatCreateFunction "cash_cmp" [ "money" , "money" ] False "int4"
+>        , CatCreateFunction
+>            "cash_div_cash" [ "money" , "money" ] False "float8"
+>        , CatCreateFunction
+>            "cash_div_flt4" [ "float4" , "money" ] False "money"
+>        , CatCreateFunction
+>            "cash_div_flt8" [ "money" , "float8" ] False "money"
+>        , CatCreateFunction
+>            "cash_div_int2" [ "money" , "int2" ] False "money"
+>        , CatCreateFunction
+>            "cash_div_int4" [ "int4" , "money" ] False "money"
+>        , CatCreateFunction "cash_eq" [ "money" , "money" ] False "bool"
+>        , CatCreateFunction "cash_ge" [ "money" , "money" ] False "bool"
+>        , CatCreateFunction "cash_gt" [ "money" , "money" ] False "bool"
+>        , CatCreateFunction "cash_in" [ "cstring" ] False "money"
+>        , CatCreateFunction "cash_le" [ "money" , "money" ] False "bool"
+>        , CatCreateFunction "cash_lt" [ "money" , "money" ] False "bool"
+>        , CatCreateFunction "cash_mi" [ "money" , "money" ] False "money"
+>        , CatCreateFunction
+>            "cash_mul_flt4" [ "float4" , "money" ] False "money"
+>        , CatCreateFunction
+>            "cash_mul_flt8" [ "money" , "float8" ] False "money"
+>        , CatCreateFunction
+>            "cash_mul_int2" [ "money" , "int2" ] False "money"
+>        , CatCreateFunction
+>            "cash_mul_int4" [ "int4" , "money" ] False "money"
+>        , CatCreateFunction "cash_ne" [ "money" , "money" ] False "bool"
+>        , CatCreateFunction "cash_out" [ "money" ] False "cstring"
+>        , CatCreateFunction "cash_pl" [ "money" , "money" ] False "money"
+>        , CatCreateFunction "cash_recv" [ "internal" ] False "money"
+>        , CatCreateFunction "cash_send" [ "money" ] False "bytea"
+>        , CatCreateFunction "cash_words" [ "money" ] False "text"
+>        , CatCreateFunction
+>            "cashlarger" [ "money" , "money" ] False "money"
+>        , CatCreateFunction
+>            "cashsmaller" [ "money" , "money" ] False "money"
+>        , CatCreateFunction "cbrt" [ "float8" ] False "float8"
+>        , CatCreateFunction "ceil" [ "numeric" ] False "numeric"
+>        , CatCreateFunction "ceil" [ "float8" ] False "float8"
+>        , CatCreateFunction "ceiling" [ "numeric" ] False "numeric"
+>        , CatCreateFunction "ceiling" [ "float8" ] False "float8"
+>        , CatCreateFunction "center" [ "box" ] False "point"
+>        , CatCreateFunction "center" [ "circle" ] False "point"
+>        , CatCreateFunction "char" [ "int4" ] False "char"
+>        , CatCreateFunction "char" [ "text" ] False "char"
+>        , CatCreateFunction "char_length" [ "bpchar" ] False "int4"
+>        , CatCreateFunction "char_length" [ "text" ] False "int4"
+>        , CatCreateFunction "character_length" [ "bpchar" ] False "int4"
+>        , CatCreateFunction "character_length" [ "text" ] False "int4"
+>        , CatCreateFunction "chareq" [ "char" , "char" ] False "bool"
+>        , CatCreateFunction "charge" [ "char" , "char" ] False "bool"
+>        , CatCreateFunction "chargt" [ "char" , "char" ] False "bool"
+>        , CatCreateFunction "charin" [ "cstring" ] False "char"
+>        , CatCreateFunction "charle" [ "char" , "char" ] False "bool"
+>        , CatCreateFunction "charlt" [ "char" , "char" ] False "bool"
+>        , CatCreateFunction "charne" [ "char" , "char" ] False "bool"
+>        , CatCreateFunction "charout" [ "char" ] False "cstring"
+>        , CatCreateFunction "charrecv" [ "internal" ] False "char"
+>        , CatCreateFunction "charsend" [ "char" ] False "bytea"
+>        , CatCreateFunction "chr" [ "int4" ] False "text"
+>        , CatCreateFunction "cideq" [ "cid" , "cid" ] False "bool"
+>        , CatCreateFunction "cidin" [ "cstring" ] False "cid"
+>        , CatCreateFunction "cidout" [ "cid" ] False "cstring"
+>        , CatCreateFunction "cidr" [ "inet" ] False "cidr"
+>        , CatCreateFunction "cidr_in" [ "cstring" ] False "cidr"
+>        , CatCreateFunction "cidr_out" [ "cidr" ] False "cstring"
+>        , CatCreateFunction "cidr_recv" [ "internal" ] False "cidr"
+>        , CatCreateFunction "cidr_send" [ "cidr" ] False "bytea"
+>        , CatCreateFunction "cidrecv" [ "internal" ] False "cid"
+>        , CatCreateFunction "cidsend" [ "cid" ] False "bytea"
+>        , CatCreateFunction "circle" [ "point" , "float8" ] False "circle"
+>        , CatCreateFunction "circle" [ "polygon" ] False "circle"
+>        , CatCreateFunction "circle" [ "box" ] False "circle"
+>        , CatCreateFunction
+>            "circle_above" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction
+>            "circle_add_pt" [ "circle" , "point" ] False "circle"
+>        , CatCreateFunction
+>            "circle_below" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction "circle_center" [ "circle" ] False "point"
+>        , CatCreateFunction
+>            "circle_contain" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction
+>            "circle_contain_pt" [ "circle" , "point" ] False "bool"
+>        , CatCreateFunction
+>            "circle_contained" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction
+>            "circle_distance" [ "circle" , "circle" ] False "float8"
+>        , CatCreateFunction
+>            "circle_div_pt" [ "circle" , "point" ] False "circle"
+>        , CatCreateFunction
+>            "circle_eq" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction
+>            "circle_ge" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction
+>            "circle_gt" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction "circle_in" [ "cstring" ] False "circle"
+>        , CatCreateFunction
+>            "circle_le" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction
+>            "circle_left" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction
+>            "circle_lt" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction
+>            "circle_mul_pt" [ "point" , "circle" ] False "circle"
+>        , CatCreateFunction
+>            "circle_ne" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction "circle_out" [ "circle" ] False "cstring"
+>        , CatCreateFunction
+>            "circle_overabove" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction
+>            "circle_overbelow" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction
+>            "circle_overlap" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction
+>            "circle_overleft" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction
+>            "circle_overright" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction "circle_recv" [ "internal" ] False "circle"
+>        , CatCreateFunction
+>            "circle_right" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction
+>            "circle_same" [ "circle" , "circle" ] False "bool"
+>        , CatCreateFunction "circle_send" [ "circle" ] False "bytea"
+>        , CatCreateFunction
+>            "circle_sub_pt" [ "point" , "circle" ] False "circle"
+>        , CatCreateFunction "close_lb" [ "line" , "box" ] False "point"
+>        , CatCreateFunction "close_ls" [ "lseg" , "line" ] False "point"
+>        , CatCreateFunction "close_lseg" [ "lseg" , "lseg" ] False "point"
+>        , CatCreateFunction "close_pb" [ "box" , "point" ] False "point"
+>        , CatCreateFunction "close_pl" [ "point" , "line" ] False "point"
+>        , CatCreateFunction "close_ps" [ "point" , "lseg" ] False "point"
+>        , CatCreateFunction "close_sb" [ "lseg" , "box" ] False "point"
+>        , CatCreateFunction "close_sl" [ "lseg" , "line" ] False "point"
+>        , CatCreateFunction
+>            "col_description" [ "int4" , "oid" ] False "text"
+>        , CatCreateFunction
+>            "contjoinsel"
+>            [ "internal" , "int2" , "internal" , "oid" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "contsel"
+>            [ "int4" , "internal" , "oid" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "convert" [ "name" , "bytea" , "name" ] False "bytea"
+>        , CatCreateFunction
+>            "convert_from" [ "name" , "bytea" ] False "text"
+>        , CatCreateFunction "convert_to" [ "text" , "name" ] False "bytea"
+>        , CatCreateFunction "cos" [ "float8" ] False "float8"
+>        , CatCreateFunction "cot" [ "float8" ] False "float8"
+>        , CatCreateFunction "cstring_in" [ "cstring" ] False "cstring"
+>        , CatCreateFunction "cstring_out" [ "cstring" ] False "cstring"
+>        , CatCreateFunction "cstring_recv" [ "internal" ] False "cstring"
+>        , CatCreateFunction "cstring_send" [ "cstring" ] False "bytea"
+>        , CatCreateFunction "current_schemas" [ "bool" ] False "_name"
+>        , CatCreateFunction "current_setting" [ "text" ] False "text"
+>        , CatCreateFunction "currtid" [ "tid" , "oid" ] False "tid"
+>        , CatCreateFunction "currtid2" [ "tid" , "text" ] False "tid"
+>        , CatCreateFunction "currval" [ "regclass" ] False "int8"
+>        , CatCreateFunction
+>            "cursor_to_xml"
+>            [ "bool" , "int4" , "refcursor" , "bool" , "text" ]
+>            False
+>            "xml"
+>        , CatCreateFunction
+>            "cursor_to_xmlschema"
+>            [ "text" , "bool" , "bool" , "refcursor" ]
+>            False
+>            "xml"
+>        , CatCreateFunction
+>            "database_to_xml" [ "bool" , "bool" , "text" ] False "xml"
+>        , CatCreateFunction
+>            "database_to_xml_and_xmlschema"
+>            [ "bool" , "text" , "bool" ]
+>            False
+>            "xml"
+>        , CatCreateFunction
+>            "database_to_xmlschema" [ "text" , "bool" , "bool" ] False "xml"
+>        , CatCreateFunction "date" [ "timestamptz" ] False "date"
+>        , CatCreateFunction "date" [ "abstime" ] False "date"
+>        , CatCreateFunction "date" [ "timestamp" ] False "date"
+>        , CatCreateFunction "date_cmp" [ "date" , "date" ] False "int4"
+>        , CatCreateFunction
+>            "date_cmp_timestamp" [ "timestamp" , "date" ] False "int4"
+>        , CatCreateFunction
+>            "date_cmp_timestamptz" [ "date" , "timestamptz" ] False "int4"
+>        , CatCreateFunction "date_eq" [ "date" , "date" ] False "bool"
+>        , CatCreateFunction
+>            "date_eq_timestamp" [ "date" , "timestamp" ] False "bool"
+>        , CatCreateFunction
+>            "date_eq_timestamptz" [ "timestamptz" , "date" ] False "bool"
+>        , CatCreateFunction "date_ge" [ "date" , "date" ] False "bool"
+>        , CatCreateFunction
+>            "date_ge_timestamp" [ "date" , "timestamp" ] False "bool"
+>        , CatCreateFunction
+>            "date_ge_timestamptz" [ "timestamptz" , "date" ] False "bool"
+>        , CatCreateFunction "date_gt" [ "date" , "date" ] False "bool"
+>        , CatCreateFunction
+>            "date_gt_timestamp" [ "date" , "timestamp" ] False "bool"
+>        , CatCreateFunction
+>            "date_gt_timestamptz" [ "timestamptz" , "date" ] False "bool"
+>        , CatCreateFunction "date_in" [ "cstring" ] False "date"
+>        , CatCreateFunction "date_larger" [ "date" , "date" ] False "date"
+>        , CatCreateFunction "date_le" [ "date" , "date" ] False "bool"
+>        , CatCreateFunction
+>            "date_le_timestamp" [ "timestamp" , "date" ] False "bool"
+>        , CatCreateFunction
+>            "date_le_timestamptz" [ "date" , "timestamptz" ] False "bool"
+>        , CatCreateFunction "date_lt" [ "date" , "date" ] False "bool"
+>        , CatCreateFunction
+>            "date_lt_timestamp" [ "date" , "timestamp" ] False "bool"
+>        , CatCreateFunction
+>            "date_lt_timestamptz" [ "date" , "timestamptz" ] False "bool"
+>        , CatCreateFunction "date_mi" [ "date" , "date" ] False "int4"
+>        , CatCreateFunction
+>            "date_mi_interval" [ "interval" , "date" ] False "timestamp"
+>        , CatCreateFunction "date_mii" [ "int4" , "date" ] False "date"
+>        , CatCreateFunction "date_ne" [ "date" , "date" ] False "bool"
+>        , CatCreateFunction
+>            "date_ne_timestamp" [ "date" , "timestamp" ] False "bool"
+>        , CatCreateFunction
+>            "date_ne_timestamptz" [ "date" , "timestamptz" ] False "bool"
+>        , CatCreateFunction "date_out" [ "date" ] False "cstring"
+>        , CatCreateFunction
+>            "date_part" [ "timestamptz" , "text" ] False "float8"
+>        , CatCreateFunction
+>            "date_part" [ "interval" , "text" ] False "float8"
+>        , CatCreateFunction
+>            "date_part" [ "timetz" , "text" ] False "float8"
+>        , CatCreateFunction
+>            "date_part" [ "abstime" , "text" ] False "float8"
+>        , CatCreateFunction
+>            "date_part" [ "text" , "reltime" ] False "float8"
+>        , CatCreateFunction "date_part" [ "date" , "text" ] False "float8"
+>        , CatCreateFunction "date_part" [ "time" , "text" ] False "float8"
+>        , CatCreateFunction
+>            "date_part" [ "text" , "timestamp" ] False "float8"
+>        , CatCreateFunction
+>            "date_pl_interval" [ "interval" , "date" ] False "timestamp"
+>        , CatCreateFunction "date_pli" [ "int4" , "date" ] False "date"
+>        , CatCreateFunction "date_recv" [ "internal" ] False "date"
+>        , CatCreateFunction "date_send" [ "date" ] False "bytea"
+>        , CatCreateFunction "date_smaller" [ "date" , "date" ] False "date"
+>        , CatCreateFunction "date_sortsupport" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "date_trunc" [ "timestamptz" , "text" ] False "timestamptz"
+>        , CatCreateFunction
+>            "date_trunc" [ "text" , "interval" ] False "interval"
+>        , CatCreateFunction
+>            "date_trunc" [ "text" , "timestamp" ] False "timestamp"
+>        , CatCreateFunction
+>            "daterange" [ "date" , "date" ] False "daterange"
+>        , CatCreateFunction
+>            "daterange" [ "date" , "text" , "date" ] False "daterange"
+>        , CatCreateFunction
+>            "daterange_canonical" [ "daterange" ] False "daterange"
+>        , CatCreateFunction
+>            "daterange_subdiff" [ "date" , "date" ] False "float8"
+>        , CatCreateFunction
+>            "datetime_pl" [ "time" , "date" ] False "timestamp"
+>        , CatCreateFunction
+>            "datetimetz_pl" [ "date" , "timetz" ] False "timestamptz"
+>        , CatCreateFunction "dcbrt" [ "float8" ] False "float8"
+>        , CatCreateFunction "decode" [ "text" , "text" ] False "bytea"
+>        , CatCreateFunction "degrees" [ "float8" ] False "float8"
+>        , CatCreateFunction "dexp" [ "float8" ] False "float8"
+>        , CatCreateFunction "diagonal" [ "box" ] False "lseg"
+>        , CatCreateFunction "diameter" [ "circle" ] False "float8"
+>        , CatCreateFunction "dispell_init" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "dispell_lexize"
+>            [ "internal" , "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "dist_cpoly" [ "polygon" , "circle" ] False "float8"
+>        , CatCreateFunction "dist_lb" [ "line" , "box" ] False "float8"
+>        , CatCreateFunction "dist_pb" [ "box" , "point" ] False "float8"
+>        , CatCreateFunction "dist_pc" [ "circle" , "point" ] False "float8"
+>        , CatCreateFunction "dist_pl" [ "point" , "line" ] False "float8"
+>        , CatCreateFunction
+>            "dist_ppath" [ "point" , "path" ] False "float8"
+>        , CatCreateFunction "dist_ps" [ "point" , "lseg" ] False "float8"
+>        , CatCreateFunction "dist_sb" [ "lseg" , "box" ] False "float8"
+>        , CatCreateFunction "dist_sl" [ "lseg" , "line" ] False "float8"
+>        , CatCreateFunction "div" [ "numeric" , "numeric" ] False "numeric"
+>        , CatCreateFunction "dlog1" [ "float8" ] False "float8"
+>        , CatCreateFunction "dlog10" [ "float8" ] False "float8"
+>        , CatCreateFunction
+>            "domain_in" [ "oid" , "cstring" , "int4" ] False "any"
+>        , CatCreateFunction
+>            "domain_recv" [ "oid" , "int4" , "internal" ] False "any"
+>        , CatCreateFunction "dpow" [ "float8" , "float8" ] False "float8"
+>        , CatCreateFunction "dround" [ "float8" ] False "float8"
+>        , CatCreateFunction "dsimple_init" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "dsimple_lexize"
+>            [ "internal" , "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "dsnowball_init" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "dsnowball_lexize"
+>            [ "internal" , "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction "dsqrt" [ "float8" ] False "float8"
+>        , CatCreateFunction "dsynonym_init" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "dsynonym_lexize"
+>            [ "internal" , "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction "dtrunc" [ "float8" ] False "float8"
+>        , CatCreateFunction
+>            "elem_contained_by_range"
+>            [ "anyrange" , "anyelement" ]
+>            False
+>            "bool"
+>        , CatCreateFunction "encode" [ "bytea" , "text" ] False "text"
+>        , CatCreateFunction
+>            "enum_cmp" [ "anyenum" , "anyenum" ] False "int4"
+>        , CatCreateFunction
+>            "enum_eq" [ "anyenum" , "anyenum" ] False "bool"
+>        , CatCreateFunction "enum_first" [ "anyenum" ] False "anyenum"
+>        , CatCreateFunction
+>            "enum_ge" [ "anyenum" , "anyenum" ] False "bool"
+>        , CatCreateFunction
+>            "enum_gt" [ "anyenum" , "anyenum" ] False "bool"
+>        , CatCreateFunction "enum_in" [ "oid" , "cstring" ] False "anyenum"
+>        , CatCreateFunction
+>            "enum_larger" [ "anyenum" , "anyenum" ] False "anyenum"
+>        , CatCreateFunction "enum_last" [ "anyenum" ] False "anyenum"
+>        , CatCreateFunction
+>            "enum_le" [ "anyenum" , "anyenum" ] False "bool"
+>        , CatCreateFunction
+>            "enum_lt" [ "anyenum" , "anyenum" ] False "bool"
+>        , CatCreateFunction
+>            "enum_ne" [ "anyenum" , "anyenum" ] False "bool"
+>        , CatCreateFunction "enum_out" [ "anyenum" ] False "cstring"
+>        , CatCreateFunction
+>            "enum_range" [ "anyenum" , "anyenum" ] False "anyarray"
+>        , CatCreateFunction "enum_range" [ "anyenum" ] False "anyarray"
+>        , CatCreateFunction
+>            "enum_recv" [ "internal" , "oid" ] False "anyenum"
+>        , CatCreateFunction "enum_send" [ "anyenum" ] False "bytea"
+>        , CatCreateFunction
+>            "enum_smaller" [ "anyenum" , "anyenum" ] False "anyenum"
+>        , CatCreateFunction
+>            "eqjoinsel"
+>            [ "internal" , "oid" , "internal" , "int2" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "eqsel" [ "internal" , "internal" , "int4" , "oid" ] False "float8"
+>        , CatCreateFunction
+>            "euc_cn_to_mic"
+>            [ "cstring" , "int4" , "internal" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "euc_cn_to_utf8"
+>            [ "int4" , "cstring" , "internal" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "euc_jis_2004_to_shift_jis_2004"
+>            [ "int4" , "cstring" , "internal" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "euc_jis_2004_to_utf8"
+>            [ "internal" , "int4" , "cstring" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "euc_jp_to_mic"
+>            [ "int4" , "int4" , "cstring" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "euc_jp_to_sjis"
+>            [ "int4" , "cstring" , "int4" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "euc_jp_to_utf8"
+>            [ "int4" , "int4" , "cstring" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "euc_kr_to_mic"
+>            [ "cstring" , "int4" , "internal" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "euc_kr_to_utf8"
+>            [ "internal" , "int4" , "int4" , "cstring" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "euc_tw_to_big5"
+>            [ "cstring" , "int4" , "internal" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "euc_tw_to_mic"
+>            [ "cstring" , "int4" , "int4" , "int4" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "euc_tw_to_utf8"
+>            [ "int4" , "int4" , "int4" , "internal" , "cstring" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "event_trigger_in" [ "cstring" ] False "event_trigger"
+>        , CatCreateFunction
+>            "event_trigger_out" [ "event_trigger" ] False "cstring"
+>        , CatCreateFunction "exp" [ "float8" ] False "float8"
+>        , CatCreateFunction "exp" [ "numeric" ] False "numeric"
+>        , CatCreateFunction "factorial" [ "int8" ] False "numeric"
+>        , CatCreateFunction "family" [ "inet" ] False "int4"
+>        , CatCreateFunction
+>            "fdw_handler_in" [ "cstring" ] False "fdw_handler"
+>        , CatCreateFunction
+>            "fdw_handler_out" [ "fdw_handler" ] False "cstring"
+>        , CatCreateFunction "float4" [ "int2" ] False "float4"
+>        , CatCreateFunction "float4" [ "float8" ] False "float4"
+>        , CatCreateFunction "float4" [ "int4" ] False "float4"
+>        , CatCreateFunction "float4" [ "int8" ] False "float4"
+>        , CatCreateFunction "float4" [ "numeric" ] False "float4"
+>        , CatCreateFunction
+>            "float48div" [ "float8" , "float4" ] False "float8"
+>        , CatCreateFunction
+>            "float48eq" [ "float4" , "float8" ] False "bool"
+>        , CatCreateFunction
+>            "float48ge" [ "float4" , "float8" ] False "bool"
+>        , CatCreateFunction
+>            "float48gt" [ "float4" , "float8" ] False "bool"
+>        , CatCreateFunction
+>            "float48le" [ "float8" , "float4" ] False "bool"
+>        , CatCreateFunction
+>            "float48lt" [ "float4" , "float8" ] False "bool"
+>        , CatCreateFunction
+>            "float48mi" [ "float4" , "float8" ] False "float8"
+>        , CatCreateFunction
+>            "float48mul" [ "float8" , "float4" ] False "float8"
+>        , CatCreateFunction
+>            "float48ne" [ "float8" , "float4" ] False "bool"
+>        , CatCreateFunction
+>            "float48pl" [ "float4" , "float8" ] False "float8"
+>        , CatCreateFunction
+>            "float4_accum" [ "float4" , "_float8" ] False "_float8"
+>        , CatCreateFunction "float4abs" [ "float4" ] False "float4"
+>        , CatCreateFunction
+>            "float4div" [ "float4" , "float4" ] False "float4"
+>        , CatCreateFunction "float4eq" [ "float4" , "float4" ] False "bool"
+>        , CatCreateFunction "float4ge" [ "float4" , "float4" ] False "bool"
+>        , CatCreateFunction "float4gt" [ "float4" , "float4" ] False "bool"
+>        , CatCreateFunction "float4in" [ "cstring" ] False "float4"
+>        , CatCreateFunction
+>            "float4larger" [ "float4" , "float4" ] False "float4"
+>        , CatCreateFunction "float4le" [ "float4" , "float4" ] False "bool"
+>        , CatCreateFunction "float4lt" [ "float4" , "float4" ] False "bool"
+>        , CatCreateFunction
+>            "float4mi" [ "float4" , "float4" ] False "float4"
+>        , CatCreateFunction
+>            "float4mul" [ "float4" , "float4" ] False "float4"
+>        , CatCreateFunction "float4ne" [ "float4" , "float4" ] False "bool"
+>        , CatCreateFunction "float4out" [ "float4" ] False "cstring"
+>        , CatCreateFunction
+>            "float4pl" [ "float4" , "float4" ] False "float4"
+>        , CatCreateFunction "float4recv" [ "internal" ] False "float4"
+>        , CatCreateFunction "float4send" [ "float4" ] False "bytea"
+>        , CatCreateFunction
+>            "float4smaller" [ "float4" , "float4" ] False "float4"
+>        , CatCreateFunction "float4um" [ "float4" ] False "float4"
+>        , CatCreateFunction "float4up" [ "float4" ] False "float4"
+>        , CatCreateFunction "float8" [ "int2" ] False "float8"
+>        , CatCreateFunction "float8" [ "float4" ] False "float8"
+>        , CatCreateFunction "float8" [ "int4" ] False "float8"
+>        , CatCreateFunction "float8" [ "int8" ] False "float8"
+>        , CatCreateFunction "float8" [ "numeric" ] False "float8"
+>        , CatCreateFunction
+>            "float84div" [ "float4" , "float8" ] False "float8"
+>        , CatCreateFunction
+>            "float84eq" [ "float4" , "float8" ] False "bool"
+>        , CatCreateFunction
+>            "float84ge" [ "float8" , "float4" ] False "bool"
+>        , CatCreateFunction
+>            "float84gt" [ "float8" , "float4" ] False "bool"
+>        , CatCreateFunction
+>            "float84le" [ "float4" , "float8" ] False "bool"
+>        , CatCreateFunction
+>            "float84lt" [ "float8" , "float4" ] False "bool"
+>        , CatCreateFunction
+>            "float84mi" [ "float4" , "float8" ] False "float8"
+>        , CatCreateFunction
+>            "float84mul" [ "float8" , "float4" ] False "float8"
+>        , CatCreateFunction
+>            "float84ne" [ "float8" , "float4" ] False "bool"
+>        , CatCreateFunction
+>            "float84pl" [ "float8" , "float4" ] False "float8"
+>        , CatCreateFunction
+>            "float8_accum" [ "_float8" , "float8" ] False "_float8"
+>        , CatCreateFunction "float8_avg" [ "_float8" ] False "float8"
+>        , CatCreateFunction "float8_corr" [ "_float8" ] False "float8"
+>        , CatCreateFunction "float8_covar_pop" [ "_float8" ] False "float8"
+>        , CatCreateFunction
+>            "float8_covar_samp" [ "_float8" ] False "float8"
+>        , CatCreateFunction
+>            "float8_regr_accum"
+>            [ "float8" , "_float8" , "float8" ]
+>            False
+>            "_float8"
+>        , CatCreateFunction "float8_regr_avgx" [ "_float8" ] False "float8"
+>        , CatCreateFunction "float8_regr_avgy" [ "_float8" ] False "float8"
+>        , CatCreateFunction
+>            "float8_regr_intercept" [ "_float8" ] False "float8"
+>        , CatCreateFunction "float8_regr_r2" [ "_float8" ] False "float8"
+>        , CatCreateFunction
+>            "float8_regr_slope" [ "_float8" ] False "float8"
+>        , CatCreateFunction "float8_regr_sxx" [ "_float8" ] False "float8"
+>        , CatCreateFunction "float8_regr_sxy" [ "_float8" ] False "float8"
+>        , CatCreateFunction "float8_regr_syy" [ "_float8" ] False "float8"
+>        , CatCreateFunction
+>            "float8_stddev_pop" [ "_float8" ] False "float8"
+>        , CatCreateFunction
+>            "float8_stddev_samp" [ "_float8" ] False "float8"
+>        , CatCreateFunction "float8_var_pop" [ "_float8" ] False "float8"
+>        , CatCreateFunction "float8_var_samp" [ "_float8" ] False "float8"
+>        , CatCreateFunction "float8abs" [ "float8" ] False "float8"
+>        , CatCreateFunction
+>            "float8div" [ "float8" , "float8" ] False "float8"
+>        , CatCreateFunction "float8eq" [ "float8" , "float8" ] False "bool"
+>        , CatCreateFunction "float8ge" [ "float8" , "float8" ] False "bool"
+>        , CatCreateFunction "float8gt" [ "float8" , "float8" ] False "bool"
+>        , CatCreateFunction "float8in" [ "cstring" ] False "float8"
+>        , CatCreateFunction
+>            "float8larger" [ "float8" , "float8" ] False "float8"
+>        , CatCreateFunction "float8le" [ "float8" , "float8" ] False "bool"
+>        , CatCreateFunction "float8lt" [ "float8" , "float8" ] False "bool"
+>        , CatCreateFunction
+>            "float8mi" [ "float8" , "float8" ] False "float8"
+>        , CatCreateFunction
+>            "float8mul" [ "float8" , "float8" ] False "float8"
+>        , CatCreateFunction "float8ne" [ "float8" , "float8" ] False "bool"
+>        , CatCreateFunction "float8out" [ "float8" ] False "cstring"
+>        , CatCreateFunction
+>            "float8pl" [ "float8" , "float8" ] False "float8"
+>        , CatCreateFunction "float8recv" [ "internal" ] False "float8"
+>        , CatCreateFunction "float8send" [ "float8" ] False "bytea"
+>        , CatCreateFunction
+>            "float8smaller" [ "float8" , "float8" ] False "float8"
+>        , CatCreateFunction "float8um" [ "float8" ] False "float8"
+>        , CatCreateFunction "float8up" [ "float8" ] False "float8"
+>        , CatCreateFunction "floor" [ "numeric" ] False "numeric"
+>        , CatCreateFunction "floor" [ "float8" ] False "float8"
+>        , CatCreateFunction
+>            "flt4_mul_cash" [ "money" , "float4" ] False "money"
+>        , CatCreateFunction
+>            "flt8_mul_cash" [ "money" , "float8" ] False "money"
+>        , CatCreateFunction "fmgr_c_validator" [ "oid" ] False "void"
+>        , CatCreateFunction
+>            "fmgr_internal_validator" [ "oid" ] False "void"
+>        , CatCreateFunction "fmgr_sql_validator" [ "oid" ] False "void"
+>        , CatCreateFunction "format" [ "text" ] False "text"
+>        , CatCreateFunction "format_type" [ "int4" , "oid" ] False "text"
+>        , CatCreateFunction
+>            "gb18030_to_utf8"
+>            [ "int4" , "int4" , "cstring" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "gbk_to_utf8"
+>            [ "internal" , "int4" , "int4" , "cstring" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "generate_series"
+>            [ "timestamp" , "timestamp" , "interval" ]
+>            True
+>            "timestamp"
+>        , CatCreateFunction
+>            "generate_series"
+>            [ "timestamptz" , "interval" , "timestamptz" ]
+>            True
+>            "timestamptz"
+>        , CatCreateFunction
+>            "generate_series" [ "int4" , "int4" , "int4" ] True "int4"
+>        , CatCreateFunction
+>            "generate_series" [ "int4" , "int4" ] True "int4"
+>        , CatCreateFunction
+>            "generate_series" [ "int8" , "int8" , "int8" ] True "int8"
+>        , CatCreateFunction
+>            "generate_series" [ "int8" , "int8" ] True "int8"
+>        , CatCreateFunction
+>            "generate_subscripts" [ "int4" , "bool" , "anyarray" ] True "int4"
+>        , CatCreateFunction
+>            "generate_subscripts" [ "anyarray" , "int4" ] True "int4"
+>        , CatCreateFunction "get_bit" [ "bytea" , "int4" ] False "int4"
+>        , CatCreateFunction "get_bit" [ "bit" , "int4" ] False "int4"
+>        , CatCreateFunction "get_byte" [ "int4" , "bytea" ] False "int4"
+>        , CatCreateFunction
+>            "gin_cmp_prefix"
+>            [ "text" , "text" , "internal" , "int2" ]
+>            False
+>            "int4"
+>        , CatCreateFunction
+>            "gin_cmp_tslexeme" [ "text" , "text" ] False "int4"
+>        , CatCreateFunction
+>            "gin_compare_jsonb" [ "text" , "text" ] False "int4"
+>        , CatCreateFunction
+>            "gin_consistent_jsonb"
+>            [ "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "int2"
+>            , "anyarray"
+>            , "int4"
+>            ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "gin_consistent_jsonb_path"
+>            [ "int2"
+>            , "anyarray"
+>            , "int4"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "gin_extract_jsonb"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "gin_extract_jsonb_path"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "gin_extract_jsonb_query"
+>            [ "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "int2"
+>            , "anyarray"
+>            , "internal"
+>            ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "gin_extract_jsonb_query_path"
+>            [ "internal"
+>            , "anyarray"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "int2"
+>            ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "gin_extract_tsquery"
+>            [ "tsquery" , "internal" , "int2" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "gin_extract_tsquery"
+>            [ "internal"
+>            , "internal"
+>            , "tsquery"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "int2"
+>            ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "gin_extract_tsvector" [ "internal" , "tsvector" ] False "internal"
+>        , CatCreateFunction
+>            "gin_extract_tsvector"
+>            [ "internal" , "internal" , "tsvector" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "gin_triconsistent_jsonb"
+>            [ "internal"
+>            , "internal"
+>            , "int4"
+>            , "internal"
+>            , "internal"
+>            , "int2"
+>            , "anyarray"
+>            ]
+>            False
+>            "char"
+>        , CatCreateFunction
+>            "gin_triconsistent_jsonb_path"
+>            [ "int4"
+>            , "internal"
+>            , "internal"
+>            , "anyarray"
+>            , "int2"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "char"
+>        , CatCreateFunction
+>            "gin_tsquery_consistent"
+>            [ "tsquery"
+>            , "internal"
+>            , "internal"
+>            , "int4"
+>            , "int2"
+>            , "internal"
+>            ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "gin_tsquery_consistent"
+>            [ "tsquery"
+>            , "internal"
+>            , "int4"
+>            , "internal"
+>            , "internal"
+>            , "int2"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "gin_tsquery_triconsistent"
+>            [ "internal"
+>            , "internal"
+>            , "int2"
+>            , "tsquery"
+>            , "int4"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "char"
+>        , CatCreateFunction
+>            "ginarrayconsistent"
+>            [ "int2"
+>            , "int4"
+>            , "anyarray"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "ginarrayextract"
+>            [ "internal" , "anyarray" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "ginarrayextract" [ "anyarray" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "ginarraytriconsistent"
+>            [ "int2"
+>            , "anyarray"
+>            , "int4"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "char"
+>        , CatCreateFunction
+>            "ginbeginscan"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "ginbuild"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction "ginbuildempty" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "ginbulkdelete"
+>            [ "internal" , "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "gincostestimate"
+>            [ "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "void"
+>        , CatCreateFunction "ginendscan" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "gingetbitmap" [ "internal" , "internal" ] False "int8"
+>        , CatCreateFunction
+>            "gininsert"
+>            [ "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "bool"
+>        , CatCreateFunction "ginmarkpos" [ "internal" ] False "void"
+>        , CatCreateFunction "ginoptions" [ "bool" , "_text" ] False "bytea"
+>        , CatCreateFunction
+>            "ginqueryarrayextract"
+>            [ "internal"
+>            , "int2"
+>            , "internal"
+>            , "internal"
+>            , "anyarray"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "ginrescan"
+>            [ "internal" , "internal" , "internal" , "internal" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction "ginrestrpos" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "ginvacuumcleanup" [ "internal" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "gist_box_compress" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "gist_box_consistent"
+>            [ "internal" , "internal" , "box" , "int4" , "oid" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "gist_box_decompress" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "gist_box_penalty"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "gist_box_picksplit" [ "internal" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "gist_box_same" [ "box" , "internal" , "box" ] False "internal"
+>        , CatCreateFunction
+>            "gist_box_union" [ "internal" , "internal" ] False "box"
+>        , CatCreateFunction
+>            "gist_circle_compress" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "gist_circle_consistent"
+>            [ "int4" , "internal" , "circle" , "internal" , "oid" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "gist_point_compress" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "gist_point_consistent"
+>            [ "point" , "internal" , "oid" , "int4" , "internal" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "gist_point_distance"
+>            [ "internal" , "int4" , "oid" , "point" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "gist_poly_compress" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "gist_poly_consistent"
+>            [ "internal" , "polygon" , "internal" , "oid" , "int4" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "gistbeginscan"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "gistbuild"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction "gistbuildempty" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "gistbulkdelete"
+>            [ "internal" , "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "gistcostestimate"
+>            [ "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "void"
+>        , CatCreateFunction "gistendscan" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "gistgetbitmap" [ "internal" , "internal" ] False "int8"
+>        , CatCreateFunction
+>            "gistgettuple" [ "internal" , "internal" ] False "bool"
+>        , CatCreateFunction
+>            "gistinsert"
+>            [ "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "bool"
+>        , CatCreateFunction "gistmarkpos" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "gistoptions" [ "_text" , "bool" ] False "bytea"
+>        , CatCreateFunction
+>            "gistrescan"
+>            [ "internal" , "internal" , "internal" , "internal" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction "gistrestrpos" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "gistvacuumcleanup" [ "internal" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "gtsquery_compress" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "gtsquery_consistent"
+>            [ "int4" , "oid" , "internal" , "internal" , "internal" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "gtsquery_decompress" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "gtsquery_penalty"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "gtsquery_picksplit" [ "internal" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "gtsquery_same" [ "internal" , "int8" , "int8" ] False "internal"
+>        , CatCreateFunction
+>            "gtsquery_union" [ "internal" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "gtsvector_compress" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "gtsvector_consistent"
+>            [ "int4" , "oid" , "internal" , "internal" , "gtsvector" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "gtsvector_decompress" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "gtsvector_penalty"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "gtsvector_picksplit" [ "internal" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "gtsvector_same"
+>            [ "gtsvector" , "internal" , "gtsvector" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "gtsvector_union" [ "internal" , "internal" ] False "internal"
+>        , CatCreateFunction "gtsvectorin" [ "cstring" ] False "gtsvector"
+>        , CatCreateFunction "gtsvectorout" [ "gtsvector" ] False "cstring"
+>        , CatCreateFunction
+>            "has_any_column_privilege"
+>            [ "name" , "text" , "text" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "has_any_column_privilege" [ "text" , "oid" , "name" ] False "bool"
+>        , CatCreateFunction
+>            "has_any_column_privilege" [ "oid" , "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_any_column_privilege" [ "oid" , "oid" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_any_column_privilege" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_any_column_privilege" [ "text" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_column_privilege"
+>            [ "name" , "text" , "text" , "text" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "has_column_privilege"
+>            [ "int2" , "text" , "name" , "text" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "has_column_privilege"
+>            [ "text" , "name" , "oid" , "text" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "has_column_privilege"
+>            [ "int2" , "name" , "text" , "oid" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "has_column_privilege"
+>            [ "text" , "oid" , "text" , "text" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "has_column_privilege"
+>            [ "text" , "text" , "int2" , "oid" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "has_column_privilege"
+>            [ "text" , "text" , "oid" , "oid" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "has_column_privilege"
+>            [ "oid" , "oid" , "int2" , "text" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "has_column_privilege" [ "text" , "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_column_privilege" [ "text" , "text" , "int2" ] False "bool"
+>        , CatCreateFunction
+>            "has_column_privilege" [ "oid" , "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_column_privilege" [ "oid" , "text" , "int2" ] False "bool"
+>        , CatCreateFunction
+>            "has_database_privilege" [ "name" , "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_database_privilege" [ "text" , "oid" , "name" ] False "bool"
+>        , CatCreateFunction
+>            "has_database_privilege" [ "oid" , "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_database_privilege" [ "oid" , "text" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_database_privilege" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_database_privilege" [ "text" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_foreign_data_wrapper_privilege"
+>            [ "name" , "text" , "text" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "has_foreign_data_wrapper_privilege"
+>            [ "name" , "oid" , "text" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "has_foreign_data_wrapper_privilege"
+>            [ "oid" , "text" , "text" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "has_foreign_data_wrapper_privilege"
+>            [ "oid" , "text" , "oid" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "has_foreign_data_wrapper_privilege"
+>            [ "text" , "text" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "has_foreign_data_wrapper_privilege"
+>            [ "oid" , "text" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "has_function_privilege" [ "text" , "name" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_function_privilege" [ "name" , "text" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_function_privilege" [ "text" , "oid" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_function_privilege" [ "text" , "oid" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_function_privilege" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_function_privilege" [ "oid" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_language_privilege" [ "text" , "text" , "name" ] False "bool"
+>        , CatCreateFunction
+>            "has_language_privilege" [ "name" , "oid" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_language_privilege" [ "text" , "text" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_language_privilege" [ "oid" , "oid" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_language_privilege" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_language_privilege" [ "oid" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_schema_privilege" [ "name" , "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_schema_privilege" [ "name" , "oid" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_schema_privilege" [ "text" , "text" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_schema_privilege" [ "oid" , "text" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_schema_privilege" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_schema_privilege" [ "text" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_sequence_privilege" [ "text" , "text" , "name" ] False "bool"
+>        , CatCreateFunction
+>            "has_sequence_privilege" [ "name" , "oid" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_sequence_privilege" [ "oid" , "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_sequence_privilege" [ "text" , "oid" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_sequence_privilege" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_sequence_privilege" [ "oid" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_server_privilege" [ "name" , "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_server_privilege" [ "text" , "name" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_server_privilege" [ "oid" , "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_server_privilege" [ "oid" , "oid" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_server_privilege" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_server_privilege" [ "oid" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_table_privilege" [ "text" , "name" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_table_privilege" [ "text" , "oid" , "name" ] False "bool"
+>        , CatCreateFunction
+>            "has_table_privilege" [ "oid" , "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_table_privilege" [ "oid" , "text" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_table_privilege" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_table_privilege" [ "text" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_tablespace_privilege"
+>            [ "name" , "text" , "text" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "has_tablespace_privilege" [ "text" , "oid" , "name" ] False "bool"
+>        , CatCreateFunction
+>            "has_tablespace_privilege" [ "text" , "text" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_tablespace_privilege" [ "oid" , "oid" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_tablespace_privilege" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_tablespace_privilege" [ "oid" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_type_privilege" [ "name" , "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_type_privilege" [ "name" , "text" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_type_privilege" [ "text" , "text" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_type_privilege" [ "oid" , "text" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "has_type_privilege" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "has_type_privilege" [ "oid" , "text" ] False "bool"
+>        , CatCreateFunction "hash_aclitem" [ "aclitem" ] False "int4"
+>        , CatCreateFunction "hash_array" [ "anyarray" ] False "int4"
+>        , CatCreateFunction "hash_numeric" [ "numeric" ] False "int4"
+>        , CatCreateFunction "hash_range" [ "anyrange" ] False "int4"
+>        , CatCreateFunction
+>            "hashbeginscan"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction "hashbpchar" [ "bpchar" ] False "int4"
+>        , CatCreateFunction
+>            "hashbuild"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction "hashbuildempty" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "hashbulkdelete"
+>            [ "internal" , "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction "hashchar" [ "char" ] False "int4"
+>        , CatCreateFunction
+>            "hashcostestimate"
+>            [ "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "void"
+>        , CatCreateFunction "hashendscan" [ "internal" ] False "void"
+>        , CatCreateFunction "hashenum" [ "anyenum" ] False "int4"
+>        , CatCreateFunction "hashfloat4" [ "float4" ] False "int4"
+>        , CatCreateFunction "hashfloat8" [ "float8" ] False "int4"
+>        , CatCreateFunction
+>            "hashgetbitmap" [ "internal" , "internal" ] False "int8"
+>        , CatCreateFunction
+>            "hashgettuple" [ "internal" , "internal" ] False "bool"
+>        , CatCreateFunction "hashinet" [ "inet" ] False "int4"
+>        , CatCreateFunction
+>            "hashinsert"
+>            [ "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "bool"
+>        , CatCreateFunction "hashint2" [ "int2" ] False "int4"
+>        , CatCreateFunction "hashint2vector" [ "int2vector" ] False "int4"
+>        , CatCreateFunction "hashint4" [ "int4" ] False "int4"
+>        , CatCreateFunction "hashint8" [ "int8" ] False "int4"
+>        , CatCreateFunction "hashmacaddr" [ "macaddr" ] False "int4"
+>        , CatCreateFunction "hashmarkpos" [ "internal" ] False "void"
+>        , CatCreateFunction "hashname" [ "name" ] False "int4"
+>        , CatCreateFunction "hashoid" [ "oid" ] False "int4"
+>        , CatCreateFunction "hashoidvector" [ "oidvector" ] False "int4"
+>        , CatCreateFunction
+>            "hashoptions" [ "_text" , "bool" ] False "bytea"
+>        , CatCreateFunction
+>            "hashrescan"
+>            [ "internal" , "internal" , "internal" , "internal" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction "hashrestrpos" [ "internal" ] False "void"
+>        , CatCreateFunction "hashtext" [ "text" ] False "int4"
+>        , CatCreateFunction
+>            "hashvacuumcleanup" [ "internal" , "internal" ] False "internal"
+>        , CatCreateFunction "hashvarlena" [ "internal" ] False "int4"
+>        , CatCreateFunction "height" [ "box" ] False "float8"
+>        , CatCreateFunction "host" [ "inet" ] False "text"
+>        , CatCreateFunction "hostmask" [ "inet" ] False "inet"
+>        , CatCreateFunction
+>            "iclikejoinsel"
+>            [ "int2" , "internal" , "internal" , "internal" , "oid" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "iclikesel"
+>            [ "int4" , "internal" , "internal" , "oid" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "icnlikejoinsel"
+>            [ "internal" , "int2" , "internal" , "internal" , "oid" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "icnlikesel"
+>            [ "internal" , "oid" , "int4" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "icregexeqjoinsel"
+>            [ "internal" , "int2" , "internal" , "oid" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "icregexeqsel"
+>            [ "internal" , "int4" , "oid" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "icregexnejoinsel"
+>            [ "internal" , "internal" , "oid" , "internal" , "int2" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "icregexnesel"
+>            [ "internal" , "int4" , "internal" , "oid" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "inet_gist_compress" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "inet_gist_consistent"
+>            [ "int4" , "inet" , "oid" , "internal" , "internal" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "inet_gist_decompress" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "inet_gist_penalty"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "inet_gist_picksplit" [ "internal" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "inet_gist_same" [ "inet" , "inet" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "inet_gist_union" [ "internal" , "internal" ] False "internal"
+>        , CatCreateFunction "inet_in" [ "cstring" ] False "inet"
+>        , CatCreateFunction "inet_out" [ "inet" ] False "cstring"
+>        , CatCreateFunction "inet_recv" [ "internal" ] False "inet"
+>        , CatCreateFunction "inet_send" [ "inet" ] False "bytea"
+>        , CatCreateFunction "inetand" [ "inet" , "inet" ] False "inet"
+>        , CatCreateFunction "inetmi" [ "inet" , "inet" ] False "int8"
+>        , CatCreateFunction "inetmi_int8" [ "int8" , "inet" ] False "inet"
+>        , CatCreateFunction "inetnot" [ "inet" ] False "inet"
+>        , CatCreateFunction "inetor" [ "inet" , "inet" ] False "inet"
+>        , CatCreateFunction "inetpl" [ "inet" , "int8" ] False "inet"
+>        , CatCreateFunction "initcap" [ "text" ] False "text"
+>        , CatCreateFunction "int2" [ "float8" ] False "int2"
+>        , CatCreateFunction "int2" [ "float4" ] False "int2"
+>        , CatCreateFunction "int2" [ "int4" ] False "int2"
+>        , CatCreateFunction "int2" [ "int8" ] False "int2"
+>        , CatCreateFunction "int2" [ "numeric" ] False "int2"
+>        , CatCreateFunction "int24div" [ "int2" , "int4" ] False "int4"
+>        , CatCreateFunction "int24eq" [ "int4" , "int2" ] False "bool"
+>        , CatCreateFunction "int24ge" [ "int4" , "int2" ] False "bool"
+>        , CatCreateFunction "int24gt" [ "int2" , "int4" ] False "bool"
+>        , CatCreateFunction "int24le" [ "int4" , "int2" ] False "bool"
+>        , CatCreateFunction "int24lt" [ "int4" , "int2" ] False "bool"
+>        , CatCreateFunction "int24mi" [ "int4" , "int2" ] False "int4"
+>        , CatCreateFunction "int24mul" [ "int2" , "int4" ] False "int4"
+>        , CatCreateFunction "int24ne" [ "int4" , "int2" ] False "bool"
+>        , CatCreateFunction "int24pl" [ "int2" , "int4" ] False "int4"
+>        , CatCreateFunction "int28div" [ "int2" , "int8" ] False "int8"
+>        , CatCreateFunction "int28eq" [ "int8" , "int2" ] False "bool"
+>        , CatCreateFunction "int28ge" [ "int2" , "int8" ] False "bool"
+>        , CatCreateFunction "int28gt" [ "int8" , "int2" ] False "bool"
+>        , CatCreateFunction "int28le" [ "int2" , "int8" ] False "bool"
+>        , CatCreateFunction "int28lt" [ "int8" , "int2" ] False "bool"
+>        , CatCreateFunction "int28mi" [ "int2" , "int8" ] False "int8"
+>        , CatCreateFunction "int28mul" [ "int2" , "int8" ] False "int8"
+>        , CatCreateFunction "int28ne" [ "int8" , "int2" ] False "bool"
+>        , CatCreateFunction "int28pl" [ "int2" , "int8" ] False "int8"
+>        , CatCreateFunction
+>            "int2_accum" [ "internal" , "int2" ] False "internal"
+>        , CatCreateFunction
+>            "int2_accum_inv" [ "int2" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "int2_avg_accum" [ "_int8" , "int2" ] False "_int8"
+>        , CatCreateFunction
+>            "int2_avg_accum_inv" [ "_int8" , "int2" ] False "_int8"
+>        , CatCreateFunction
+>            "int2_mul_cash" [ "int2" , "money" ] False "money"
+>        , CatCreateFunction "int2_sum" [ "int8" , "int2" ] False "int8"
+>        , CatCreateFunction "int2abs" [ "int2" ] False "int2"
+>        , CatCreateFunction "int2and" [ "int2" , "int2" ] False "int2"
+>        , CatCreateFunction "int2div" [ "int2" , "int2" ] False "int2"
+>        , CatCreateFunction "int2eq" [ "int2" , "int2" ] False "bool"
+>        , CatCreateFunction "int2ge" [ "int2" , "int2" ] False "bool"
+>        , CatCreateFunction "int2gt" [ "int2" , "int2" ] False "bool"
+>        , CatCreateFunction "int2in" [ "cstring" ] False "int2"
+>        , CatCreateFunction "int2int4_sum" [ "_int8" ] False "int8"
+>        , CatCreateFunction "int2larger" [ "int2" , "int2" ] False "int2"
+>        , CatCreateFunction "int2le" [ "int2" , "int2" ] False "bool"
+>        , CatCreateFunction "int2lt" [ "int2" , "int2" ] False "bool"
+>        , CatCreateFunction "int2mi" [ "int2" , "int2" ] False "int2"
+>        , CatCreateFunction "int2mod" [ "int2" , "int2" ] False "int2"
+>        , CatCreateFunction "int2mul" [ "int2" , "int2" ] False "int2"
+>        , CatCreateFunction "int2ne" [ "int2" , "int2" ] False "bool"
+>        , CatCreateFunction "int2not" [ "int2" ] False "int2"
+>        , CatCreateFunction "int2or" [ "int2" , "int2" ] False "int2"
+>        , CatCreateFunction "int2out" [ "int2" ] False "cstring"
+>        , CatCreateFunction "int2pl" [ "int2" , "int2" ] False "int2"
+>        , CatCreateFunction "int2recv" [ "internal" ] False "int2"
+>        , CatCreateFunction "int2send" [ "int2" ] False "bytea"
+>        , CatCreateFunction "int2shl" [ "int2" , "int4" ] False "int2"
+>        , CatCreateFunction "int2shr" [ "int4" , "int2" ] False "int2"
+>        , CatCreateFunction "int2smaller" [ "int2" , "int2" ] False "int2"
+>        , CatCreateFunction "int2um" [ "int2" ] False "int2"
+>        , CatCreateFunction "int2up" [ "int2" ] False "int2"
+>        , CatCreateFunction
+>            "int2vectoreq" [ "int2vector" , "int2vector" ] False "bool"
+>        , CatCreateFunction "int2vectorin" [ "cstring" ] False "int2vector"
+>        , CatCreateFunction
+>            "int2vectorout" [ "int2vector" ] False "cstring"
+>        , CatCreateFunction
+>            "int2vectorrecv" [ "internal" ] False "int2vector"
+>        , CatCreateFunction "int2vectorsend" [ "int2vector" ] False "bytea"
+>        , CatCreateFunction "int2xor" [ "int2" , "int2" ] False "int2"
+>        , CatCreateFunction "int4" [ "char" ] False "int4"
+>        , CatCreateFunction "int4" [ "int2" ] False "int4"
+>        , CatCreateFunction "int4" [ "float8" ] False "int4"
+>        , CatCreateFunction "int4" [ "float4" ] False "int4"
+>        , CatCreateFunction "int4" [ "int8" ] False "int4"
+>        , CatCreateFunction "int4" [ "bit" ] False "int4"
+>        , CatCreateFunction "int4" [ "numeric" ] False "int4"
+>        , CatCreateFunction "int4" [ "bool" ] False "int4"
+>        , CatCreateFunction "int42div" [ "int2" , "int4" ] False "int4"
+>        , CatCreateFunction "int42eq" [ "int4" , "int2" ] False "bool"
+>        , CatCreateFunction "int42ge" [ "int4" , "int2" ] False "bool"
+>        , CatCreateFunction "int42gt" [ "int4" , "int2" ] False "bool"
+>        , CatCreateFunction "int42le" [ "int2" , "int4" ] False "bool"
+>        , CatCreateFunction "int42lt" [ "int4" , "int2" ] False "bool"
+>        , CatCreateFunction "int42mi" [ "int4" , "int2" ] False "int4"
+>        , CatCreateFunction "int42mul" [ "int4" , "int2" ] False "int4"
+>        , CatCreateFunction "int42ne" [ "int2" , "int4" ] False "bool"
+>        , CatCreateFunction "int42pl" [ "int4" , "int2" ] False "int4"
+>        , CatCreateFunction "int48div" [ "int8" , "int4" ] False "int8"
+>        , CatCreateFunction "int48eq" [ "int8" , "int4" ] False "bool"
+>        , CatCreateFunction "int48ge" [ "int4" , "int8" ] False "bool"
+>        , CatCreateFunction "int48gt" [ "int4" , "int8" ] False "bool"
+>        , CatCreateFunction "int48le" [ "int8" , "int4" ] False "bool"
+>        , CatCreateFunction "int48lt" [ "int4" , "int8" ] False "bool"
+>        , CatCreateFunction "int48mi" [ "int4" , "int8" ] False "int8"
+>        , CatCreateFunction "int48mul" [ "int4" , "int8" ] False "int8"
+>        , CatCreateFunction "int48ne" [ "int4" , "int8" ] False "bool"
+>        , CatCreateFunction "int48pl" [ "int8" , "int4" ] False "int8"
+>        , CatCreateFunction
+>            "int4_accum" [ "int4" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "int4_accum_inv" [ "internal" , "int4" ] False "internal"
+>        , CatCreateFunction
+>            "int4_avg_accum" [ "int4" , "_int8" ] False "_int8"
+>        , CatCreateFunction
+>            "int4_avg_accum_inv" [ "int4" , "_int8" ] False "_int8"
+>        , CatCreateFunction
+>            "int4_mul_cash" [ "money" , "int4" ] False "money"
+>        , CatCreateFunction "int4_sum" [ "int4" , "int8" ] False "int8"
+>        , CatCreateFunction "int4abs" [ "int4" ] False "int4"
+>        , CatCreateFunction "int4and" [ "int4" , "int4" ] False "int4"
+>        , CatCreateFunction "int4div" [ "int4" , "int4" ] False "int4"
+>        , CatCreateFunction "int4eq" [ "int4" , "int4" ] False "bool"
+>        , CatCreateFunction "int4ge" [ "int4" , "int4" ] False "bool"
+>        , CatCreateFunction "int4gt" [ "int4" , "int4" ] False "bool"
+>        , CatCreateFunction "int4in" [ "cstring" ] False "int4"
+>        , CatCreateFunction "int4inc" [ "int4" ] False "int4"
+>        , CatCreateFunction "int4larger" [ "int4" , "int4" ] False "int4"
+>        , CatCreateFunction "int4le" [ "int4" , "int4" ] False "bool"
+>        , CatCreateFunction "int4lt" [ "int4" , "int4" ] False "bool"
+>        , CatCreateFunction "int4mi" [ "int4" , "int4" ] False "int4"
+>        , CatCreateFunction "int4mod" [ "int4" , "int4" ] False "int4"
+>        , CatCreateFunction "int4mul" [ "int4" , "int4" ] False "int4"
+>        , CatCreateFunction "int4ne" [ "int4" , "int4" ] False "bool"
+>        , CatCreateFunction "int4not" [ "int4" ] False "int4"
+>        , CatCreateFunction "int4or" [ "int4" , "int4" ] False "int4"
+>        , CatCreateFunction "int4out" [ "int4" ] False "cstring"
+>        , CatCreateFunction "int4pl" [ "int4" , "int4" ] False "int4"
+>        , CatCreateFunction
+>            "int4range" [ "int4" , "int4" ] False "int4range"
+>        , CatCreateFunction
+>            "int4range" [ "int4" , "text" , "int4" ] False "int4range"
+>        , CatCreateFunction
+>            "int4range_canonical" [ "int4range" ] False "int4range"
+>        , CatCreateFunction
+>            "int4range_subdiff" [ "int4" , "int4" ] False "float8"
+>        , CatCreateFunction "int4recv" [ "internal" ] False "int4"
+>        , CatCreateFunction "int4send" [ "int4" ] False "bytea"
+>        , CatCreateFunction "int4shl" [ "int4" , "int4" ] False "int4"
+>        , CatCreateFunction "int4shr" [ "int4" , "int4" ] False "int4"
+>        , CatCreateFunction "int4smaller" [ "int4" , "int4" ] False "int4"
+>        , CatCreateFunction "int4um" [ "int4" ] False "int4"
+>        , CatCreateFunction "int4up" [ "int4" ] False "int4"
+>        , CatCreateFunction "int4xor" [ "int4" , "int4" ] False "int4"
+>        , CatCreateFunction "int8" [ "int4" ] False "int8"
+>        , CatCreateFunction "int8" [ "float8" ] False "int8"
+>        , CatCreateFunction "int8" [ "float4" ] False "int8"
+>        , CatCreateFunction "int8" [ "int2" ] False "int8"
+>        , CatCreateFunction "int8" [ "oid" ] False "int8"
+>        , CatCreateFunction "int8" [ "numeric" ] False "int8"
+>        , CatCreateFunction "int8" [ "bit" ] False "int8"
+>        , CatCreateFunction "int82div" [ "int2" , "int8" ] False "int8"
+>        , CatCreateFunction "int82eq" [ "int8" , "int2" ] False "bool"
+>        , CatCreateFunction "int82ge" [ "int2" , "int8" ] False "bool"
+>        , CatCreateFunction "int82gt" [ "int8" , "int2" ] False "bool"
+>        , CatCreateFunction "int82le" [ "int8" , "int2" ] False "bool"
+>        , CatCreateFunction "int82lt" [ "int8" , "int2" ] False "bool"
+>        , CatCreateFunction "int82mi" [ "int2" , "int8" ] False "int8"
+>        , CatCreateFunction "int82mul" [ "int8" , "int2" ] False "int8"
+>        , CatCreateFunction "int82ne" [ "int8" , "int2" ] False "bool"
+>        , CatCreateFunction "int82pl" [ "int2" , "int8" ] False "int8"
+>        , CatCreateFunction "int84div" [ "int8" , "int4" ] False "int8"
+>        , CatCreateFunction "int84eq" [ "int4" , "int8" ] False "bool"
+>        , CatCreateFunction "int84ge" [ "int8" , "int4" ] False "bool"
+>        , CatCreateFunction "int84gt" [ "int8" , "int4" ] False "bool"
+>        , CatCreateFunction "int84le" [ "int8" , "int4" ] False "bool"
+>        , CatCreateFunction "int84lt" [ "int8" , "int4" ] False "bool"
+>        , CatCreateFunction "int84mi" [ "int4" , "int8" ] False "int8"
+>        , CatCreateFunction "int84mul" [ "int4" , "int8" ] False "int8"
+>        , CatCreateFunction "int84ne" [ "int4" , "int8" ] False "bool"
+>        , CatCreateFunction "int84pl" [ "int4" , "int8" ] False "int8"
+>        , CatCreateFunction
+>            "int8_accum" [ "internal" , "int8" ] False "internal"
+>        , CatCreateFunction
+>            "int8_accum_inv" [ "int8" , "internal" ] False "internal"
+>        , CatCreateFunction "int8_avg" [ "_int8" ] False "numeric"
+>        , CatCreateFunction
+>            "int8_avg_accum" [ "internal" , "int8" ] False "internal"
+>        , CatCreateFunction
+>            "int8_sum" [ "numeric" , "int8" ] False "numeric"
+>        , CatCreateFunction "int8abs" [ "int8" ] False "int8"
+>        , CatCreateFunction "int8and" [ "int8" , "int8" ] False "int8"
+>        , CatCreateFunction "int8dec" [ "int8" ] False "int8"
+>        , CatCreateFunction "int8dec_any" [ "any" , "int8" ] False "int8"
+>        , CatCreateFunction "int8div" [ "int8" , "int8" ] False "int8"
+>        , CatCreateFunction "int8eq" [ "int8" , "int8" ] False "bool"
+>        , CatCreateFunction "int8ge" [ "int8" , "int8" ] False "bool"
+>        , CatCreateFunction "int8gt" [ "int8" , "int8" ] False "bool"
+>        , CatCreateFunction "int8in" [ "cstring" ] False "int8"
+>        , CatCreateFunction "int8inc" [ "int8" ] False "int8"
+>        , CatCreateFunction "int8inc_any" [ "any" , "int8" ] False "int8"
+>        , CatCreateFunction
+>            "int8inc_float8_float8"
+>            [ "float8" , "int8" , "float8" ]
+>            False
+>            "int8"
+>        , CatCreateFunction "int8larger" [ "int8" , "int8" ] False "int8"
+>        , CatCreateFunction "int8le" [ "int8" , "int8" ] False "bool"
+>        , CatCreateFunction "int8lt" [ "int8" , "int8" ] False "bool"
+>        , CatCreateFunction "int8mi" [ "int8" , "int8" ] False "int8"
+>        , CatCreateFunction "int8mod" [ "int8" , "int8" ] False "int8"
+>        , CatCreateFunction "int8mul" [ "int8" , "int8" ] False "int8"
+>        , CatCreateFunction "int8ne" [ "int8" , "int8" ] False "bool"
+>        , CatCreateFunction "int8not" [ "int8" ] False "int8"
+>        , CatCreateFunction "int8or" [ "int8" , "int8" ] False "int8"
+>        , CatCreateFunction "int8out" [ "int8" ] False "cstring"
+>        , CatCreateFunction "int8pl" [ "int8" , "int8" ] False "int8"
+>        , CatCreateFunction "int8pl_inet" [ "int8" , "inet" ] False "inet"
+>        , CatCreateFunction
+>            "int8range" [ "int8" , "int8" ] False "int8range"
+>        , CatCreateFunction
+>            "int8range" [ "int8" , "int8" , "text" ] False "int8range"
+>        , CatCreateFunction
+>            "int8range_canonical" [ "int8range" ] False "int8range"
+>        , CatCreateFunction
+>            "int8range_subdiff" [ "int8" , "int8" ] False "float8"
+>        , CatCreateFunction "int8recv" [ "internal" ] False "int8"
+>        , CatCreateFunction "int8send" [ "int8" ] False "bytea"
+>        , CatCreateFunction "int8shl" [ "int8" , "int4" ] False "int8"
+>        , CatCreateFunction "int8shr" [ "int8" , "int4" ] False "int8"
+>        , CatCreateFunction "int8smaller" [ "int8" , "int8" ] False "int8"
+>        , CatCreateFunction "int8um" [ "int8" ] False "int8"
+>        , CatCreateFunction "int8up" [ "int8" ] False "int8"
+>        , CatCreateFunction "int8xor" [ "int8" , "int8" ] False "int8"
+>        , CatCreateFunction
+>            "integer_pl_date" [ "date" , "int4" ] False "date"
+>        , CatCreateFunction "inter_lb" [ "line" , "box" ] False "bool"
+>        , CatCreateFunction "inter_sb" [ "box" , "lseg" ] False "bool"
+>        , CatCreateFunction "inter_sl" [ "lseg" , "line" ] False "bool"
+>        , CatCreateFunction "internal_in" [ "cstring" ] False "internal"
+>        , CatCreateFunction "internal_out" [ "internal" ] False "cstring"
+>        , CatCreateFunction "interval" [ "reltime" ] False "interval"
+>        , CatCreateFunction
+>            "interval" [ "int4" , "interval" ] False "interval"
+>        , CatCreateFunction "interval" [ "time" ] False "interval"
+>        , CatCreateFunction
+>            "interval_accum" [ "interval" , "_interval" ] False "_interval"
+>        , CatCreateFunction
+>            "interval_accum_inv" [ "_interval" , "interval" ] False "_interval"
+>        , CatCreateFunction "interval_avg" [ "_interval" ] False "interval"
+>        , CatCreateFunction
+>            "interval_cmp" [ "interval" , "interval" ] False "int4"
+>        , CatCreateFunction
+>            "interval_div" [ "float8" , "interval" ] False "interval"
+>        , CatCreateFunction
+>            "interval_eq" [ "interval" , "interval" ] False "bool"
+>        , CatCreateFunction
+>            "interval_ge" [ "interval" , "interval" ] False "bool"
+>        , CatCreateFunction
+>            "interval_gt" [ "interval" , "interval" ] False "bool"
+>        , CatCreateFunction "interval_hash" [ "interval" ] False "int4"
+>        , CatCreateFunction
+>            "interval_in" [ "cstring" , "int4" , "oid" ] False "interval"
+>        , CatCreateFunction
+>            "interval_larger" [ "interval" , "interval" ] False "interval"
+>        , CatCreateFunction
+>            "interval_le" [ "interval" , "interval" ] False "bool"
+>        , CatCreateFunction
+>            "interval_lt" [ "interval" , "interval" ] False "bool"
+>        , CatCreateFunction
+>            "interval_mi" [ "interval" , "interval" ] False "interval"
+>        , CatCreateFunction
+>            "interval_mul" [ "float8" , "interval" ] False "interval"
+>        , CatCreateFunction
+>            "interval_ne" [ "interval" , "interval" ] False "bool"
+>        , CatCreateFunction "interval_out" [ "interval" ] False "cstring"
+>        , CatCreateFunction
+>            "interval_pl" [ "interval" , "interval" ] False "interval"
+>        , CatCreateFunction
+>            "interval_pl_date" [ "interval" , "date" ] False "timestamp"
+>        , CatCreateFunction
+>            "interval_pl_time" [ "interval" , "time" ] False "time"
+>        , CatCreateFunction
+>            "interval_pl_timestamp"
+>            [ "timestamp" , "interval" ]
+>            False
+>            "timestamp"
+>        , CatCreateFunction
+>            "interval_pl_timestamptz"
+>            [ "timestamptz" , "interval" ]
+>            False
+>            "timestamptz"
+>        , CatCreateFunction
+>            "interval_pl_timetz" [ "interval" , "timetz" ] False "timetz"
+>        , CatCreateFunction
+>            "interval_recv" [ "int4" , "oid" , "internal" ] False "interval"
+>        , CatCreateFunction "interval_send" [ "interval" ] False "bytea"
+>        , CatCreateFunction
+>            "interval_smaller" [ "interval" , "interval" ] False "interval"
+>        , CatCreateFunction
+>            "interval_transform" [ "internal" ] False "internal"
+>        , CatCreateFunction "interval_um" [ "interval" ] False "interval"
+>        , CatCreateFunction "intervaltypmodin" [ "_cstring" ] False "int4"
+>        , CatCreateFunction "intervaltypmodout" [ "int4" ] False "cstring"
+>        , CatCreateFunction
+>            "intinterval" [ "abstime" , "tinterval" ] False "bool"
+>        , CatCreateFunction "isclosed" [ "path" ] False "bool"
+>        , CatCreateFunction "isempty" [ "anyrange" ] False "bool"
+>        , CatCreateFunction "isfinite" [ "abstime" ] False "bool"
+>        , CatCreateFunction "isfinite" [ "date" ] False "bool"
+>        , CatCreateFunction "isfinite" [ "timestamptz" ] False "bool"
+>        , CatCreateFunction "isfinite" [ "interval" ] False "bool"
+>        , CatCreateFunction "isfinite" [ "timestamp" ] False "bool"
+>        , CatCreateFunction
+>            "ishorizontal" [ "point" , "point" ] False "bool"
+>        , CatCreateFunction "ishorizontal" [ "lseg" ] False "bool"
+>        , CatCreateFunction "ishorizontal" [ "line" ] False "bool"
+>        , CatCreateFunction
+>            "iso8859_1_to_utf8"
+>            [ "int4" , "internal" , "cstring" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "iso8859_to_utf8"
+>            [ "int4" , "int4" , "internal" , "int4" , "cstring" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "iso_to_koi8r"
+>            [ "cstring" , "int4" , "internal" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "iso_to_mic"
+>            [ "int4" , "int4" , "int4" , "cstring" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "iso_to_win1251"
+>            [ "int4" , "int4" , "internal" , "cstring" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "iso_to_win866"
+>            [ "internal" , "int4" , "cstring" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction "isopen" [ "path" ] False "bool"
+>        , CatCreateFunction "isparallel" [ "lseg" , "lseg" ] False "bool"
+>        , CatCreateFunction "isparallel" [ "line" , "line" ] False "bool"
+>        , CatCreateFunction "isperp" [ "lseg" , "lseg" ] False "bool"
+>        , CatCreateFunction "isperp" [ "line" , "line" ] False "bool"
+>        , CatCreateFunction "isvertical" [ "point" , "point" ] False "bool"
+>        , CatCreateFunction "isvertical" [ "lseg" ] False "bool"
+>        , CatCreateFunction "isvertical" [ "line" ] False "bool"
+>        , CatCreateFunction
+>            "johab_to_utf8"
+>            [ "int4" , "cstring" , "internal" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction "json_agg_finalfn" [ "internal" ] False "json"
+>        , CatCreateFunction
+>            "json_agg_transfn" [ "internal" , "anyelement" ] False "internal"
+>        , CatCreateFunction
+>            "json_array_element" [ "int4" , "json" ] False "json"
+>        , CatCreateFunction
+>            "json_array_element_text" [ "int4" , "json" ] False "text"
+>        , CatCreateFunction "json_array_elements" [ "json" ] True "json"
+>        , CatCreateFunction
+>            "json_array_elements_text" [ "json" ] True "text"
+>        , CatCreateFunction "json_array_length" [ "json" ] False "int4"
+>        , CatCreateFunction "json_each" [ "json" ] True "record"
+>        , CatCreateFunction "json_each_text" [ "json" ] True "record"
+>        , CatCreateFunction "json_in" [ "cstring" ] False "json"
+>        , CatCreateFunction "json_object" [ "_text" ] False "json"
+>        , CatCreateFunction
+>            "json_object" [ "_text" , "_text" ] False "json"
+>        , CatCreateFunction
+>            "json_object_agg_finalfn" [ "internal" ] False "json"
+>        , CatCreateFunction
+>            "json_object_agg_transfn"
+>            [ "any" , "internal" , "any" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "json_object_field" [ "text" , "json" ] False "json"
+>        , CatCreateFunction
+>            "json_object_field_text" [ "json" , "text" ] False "text"
+>        , CatCreateFunction "json_object_keys" [ "json" ] True "text"
+>        , CatCreateFunction "json_out" [ "json" ] False "cstring"
+>        , CatCreateFunction
+>            "json_populate_record"
+>            [ "json" , "anyelement" , "bool" ]
+>            False
+>            "anyelement"
+>        , CatCreateFunction
+>            "json_populate_recordset"
+>            [ "anyelement" , "json" , "bool" ]
+>            True
+>            "anyelement"
+>        , CatCreateFunction "json_recv" [ "internal" ] False "json"
+>        , CatCreateFunction "json_send" [ "json" ] False "bytea"
+>        , CatCreateFunction "json_to_record" [ "json" ] False "record"
+>        , CatCreateFunction "json_to_recordset" [ "json" ] True "record"
+>        , CatCreateFunction "json_typeof" [ "json" ] False "text"
+>        , CatCreateFunction
+>            "jsonb_array_element" [ "int4" , "jsonb" ] False "jsonb"
+>        , CatCreateFunction
+>            "jsonb_array_element_text" [ "int4" , "jsonb" ] False "text"
+>        , CatCreateFunction "jsonb_array_elements" [ "jsonb" ] True "jsonb"
+>        , CatCreateFunction
+>            "jsonb_array_elements_text" [ "jsonb" ] True "text"
+>        , CatCreateFunction "jsonb_array_length" [ "jsonb" ] False "int4"
+>        , CatCreateFunction "jsonb_cmp" [ "jsonb" , "jsonb" ] False "int4"
+>        , CatCreateFunction
+>            "jsonb_contained" [ "jsonb" , "jsonb" ] False "bool"
+>        , CatCreateFunction
+>            "jsonb_contains" [ "jsonb" , "jsonb" ] False "bool"
+>        , CatCreateFunction "jsonb_each" [ "jsonb" ] True "record"
+>        , CatCreateFunction "jsonb_each_text" [ "jsonb" ] True "record"
+>        , CatCreateFunction "jsonb_eq" [ "jsonb" , "jsonb" ] False "bool"
+>        , CatCreateFunction
+>            "jsonb_exists" [ "jsonb" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "jsonb_exists_all" [ "_text" , "jsonb" ] False "bool"
+>        , CatCreateFunction
+>            "jsonb_exists_any" [ "_text" , "jsonb" ] False "bool"
+>        , CatCreateFunction "jsonb_ge" [ "jsonb" , "jsonb" ] False "bool"
+>        , CatCreateFunction "jsonb_gt" [ "jsonb" , "jsonb" ] False "bool"
+>        , CatCreateFunction "jsonb_hash" [ "jsonb" ] False "int4"
+>        , CatCreateFunction "jsonb_in" [ "cstring" ] False "jsonb"
+>        , CatCreateFunction "jsonb_le" [ "jsonb" , "jsonb" ] False "bool"
+>        , CatCreateFunction "jsonb_lt" [ "jsonb" , "jsonb" ] False "bool"
+>        , CatCreateFunction "jsonb_ne" [ "jsonb" , "jsonb" ] False "bool"
+>        , CatCreateFunction
+>            "jsonb_object_field" [ "text" , "jsonb" ] False "jsonb"
+>        , CatCreateFunction
+>            "jsonb_object_field_text" [ "jsonb" , "text" ] False "text"
+>        , CatCreateFunction "jsonb_object_keys" [ "jsonb" ] True "text"
+>        , CatCreateFunction "jsonb_out" [ "jsonb" ] False "cstring"
+>        , CatCreateFunction
+>            "jsonb_populate_record"
+>            [ "jsonb" , "anyelement" ]
+>            False
+>            "anyelement"
+>        , CatCreateFunction
+>            "jsonb_populate_recordset"
+>            [ "anyelement" , "jsonb" ]
+>            True
+>            "anyelement"
+>        , CatCreateFunction "jsonb_recv" [ "internal" ] False "jsonb"
+>        , CatCreateFunction "jsonb_send" [ "jsonb" ] False "bytea"
+>        , CatCreateFunction "jsonb_to_record" [ "jsonb" ] False "record"
+>        , CatCreateFunction "jsonb_to_recordset" [ "jsonb" ] True "record"
+>        , CatCreateFunction "jsonb_typeof" [ "jsonb" ] False "text"
+>        , CatCreateFunction "justify_days" [ "interval" ] False "interval"
+>        , CatCreateFunction "justify_hours" [ "interval" ] False "interval"
+>        , CatCreateFunction
+>            "justify_interval" [ "interval" ] False "interval"
+>        , CatCreateFunction
+>            "koi8r_to_iso"
+>            [ "int4" , "int4" , "cstring" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "koi8r_to_mic"
+>            [ "int4" , "int4" , "internal" , "cstring" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "koi8r_to_utf8"
+>            [ "int4" , "cstring" , "int4" , "int4" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "koi8r_to_win1251"
+>            [ "int4" , "internal" , "cstring" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "koi8r_to_win866"
+>            [ "cstring" , "int4" , "int4" , "int4" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "koi8u_to_utf8"
+>            [ "internal" , "int4" , "int4" , "int4" , "cstring" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "language_handler_in" [ "cstring" ] False "language_handler"
+>        , CatCreateFunction
+>            "language_handler_out" [ "language_handler" ] False "cstring"
+>        , CatCreateFunction
+>            "latin1_to_mic"
+>            [ "int4" , "cstring" , "int4" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "latin2_to_mic"
+>            [ "int4" , "int4" , "cstring" , "int4" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "latin2_to_win1250"
+>            [ "int4" , "int4" , "cstring" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "latin3_to_mic"
+>            [ "int4" , "int4" , "int4" , "cstring" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "latin4_to_mic"
+>            [ "internal" , "int4" , "int4" , "cstring" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction "left" [ "int4" , "text" ] False "text"
+>        , CatCreateFunction "length" [ "text" ] False "int4"
+>        , CatCreateFunction "length" [ "bpchar" ] False "int4"
+>        , CatCreateFunction "length" [ "lseg" ] False "float8"
+>        , CatCreateFunction "length" [ "path" ] False "float8"
+>        , CatCreateFunction "length" [ "bit" ] False "int4"
+>        , CatCreateFunction "length" [ "bytea" , "name" ] False "int4"
+>        , CatCreateFunction "length" [ "bytea" ] False "int4"
+>        , CatCreateFunction "length" [ "tsvector" ] False "int4"
+>        , CatCreateFunction "like" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction "like" [ "text" , "name" ] False "bool"
+>        , CatCreateFunction "like" [ "bytea" , "bytea" ] False "bool"
+>        , CatCreateFunction "like_escape" [ "text" , "text" ] False "text"
+>        , CatCreateFunction
+>            "like_escape" [ "bytea" , "bytea" ] False "bytea"
+>        , CatCreateFunction
+>            "likejoinsel"
+>            [ "int2" , "internal" , "internal" , "internal" , "oid" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "likesel"
+>            [ "int4" , "oid" , "internal" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction "line" [ "point" , "point" ] False "line"
+>        , CatCreateFunction
+>            "line_distance" [ "line" , "line" ] False "float8"
+>        , CatCreateFunction "line_eq" [ "line" , "line" ] False "bool"
+>        , CatCreateFunction "line_horizontal" [ "line" ] False "bool"
+>        , CatCreateFunction "line_in" [ "cstring" ] False "line"
+>        , CatCreateFunction
+>            "line_interpt" [ "line" , "line" ] False "point"
+>        , CatCreateFunction
+>            "line_intersect" [ "line" , "line" ] False "bool"
+>        , CatCreateFunction "line_out" [ "line" ] False "cstring"
+>        , CatCreateFunction
+>            "line_parallel" [ "line" , "line" ] False "bool"
+>        , CatCreateFunction "line_perp" [ "line" , "line" ] False "bool"
+>        , CatCreateFunction "line_recv" [ "internal" ] False "line"
+>        , CatCreateFunction "line_send" [ "line" ] False "bytea"
+>        , CatCreateFunction "line_vertical" [ "line" ] False "bool"
+>        , CatCreateFunction "ln" [ "float8" ] False "float8"
+>        , CatCreateFunction "ln" [ "numeric" ] False "numeric"
+>        , CatCreateFunction "lo_close" [ "int4" ] False "int4"
+>        , CatCreateFunction "lo_creat" [ "int4" ] False "oid"
+>        , CatCreateFunction "lo_create" [ "oid" ] False "oid"
+>        , CatCreateFunction "lo_export" [ "text" , "oid" ] False "int4"
+>        , CatCreateFunction "lo_from_bytea" [ "oid" , "bytea" ] False "oid"
+>        , CatCreateFunction "lo_get" [ "oid" ] False "bytea"
+>        , CatCreateFunction
+>            "lo_get" [ "int8" , "int4" , "oid" ] False "bytea"
+>        , CatCreateFunction "lo_import" [ "text" ] False "oid"
+>        , CatCreateFunction "lo_import" [ "oid" , "text" ] False "oid"
+>        , CatCreateFunction
+>            "lo_lseek" [ "int4" , "int4" , "int4" ] False "int4"
+>        , CatCreateFunction
+>            "lo_lseek64" [ "int4" , "int8" , "int4" ] False "int8"
+>        , CatCreateFunction "lo_open" [ "int4" , "oid" ] False "int4"
+>        , CatCreateFunction
+>            "lo_put" [ "bytea" , "oid" , "int8" ] False "void"
+>        , CatCreateFunction "lo_tell" [ "int4" ] False "int4"
+>        , CatCreateFunction "lo_tell64" [ "int4" ] False "int8"
+>        , CatCreateFunction "lo_truncate" [ "int4" , "int4" ] False "int4"
+>        , CatCreateFunction
+>            "lo_truncate64" [ "int4" , "int8" ] False "int4"
+>        , CatCreateFunction "lo_unlink" [ "oid" ] False "int4"
+>        , CatCreateFunction "log" [ "float8" ] False "float8"
+>        , CatCreateFunction "log" [ "numeric" , "numeric" ] False "numeric"
+>        , CatCreateFunction "log" [ "numeric" ] False "numeric"
+>        , CatCreateFunction "loread" [ "int4" , "int4" ] False "bytea"
+>        , CatCreateFunction "lower" [ "text" ] False "text"
+>        , CatCreateFunction "lower" [ "anyrange" ] False "anyelement"
+>        , CatCreateFunction "lower_inc" [ "anyrange" ] False "bool"
+>        , CatCreateFunction "lower_inf" [ "anyrange" ] False "bool"
+>        , CatCreateFunction "lowrite" [ "bytea" , "int4" ] False "int4"
+>        , CatCreateFunction
+>            "lpad" [ "int4" , "text" , "text" ] False "text"
+>        , CatCreateFunction "lpad" [ "text" , "int4" ] False "text"
+>        , CatCreateFunction "lseg" [ "point" , "point" ] False "lseg"
+>        , CatCreateFunction "lseg" [ "box" ] False "lseg"
+>        , CatCreateFunction "lseg_center" [ "lseg" ] False "point"
+>        , CatCreateFunction
+>            "lseg_distance" [ "lseg" , "lseg" ] False "float8"
+>        , CatCreateFunction "lseg_eq" [ "lseg" , "lseg" ] False "bool"
+>        , CatCreateFunction "lseg_ge" [ "lseg" , "lseg" ] False "bool"
+>        , CatCreateFunction "lseg_gt" [ "lseg" , "lseg" ] False "bool"
+>        , CatCreateFunction "lseg_horizontal" [ "lseg" ] False "bool"
+>        , CatCreateFunction "lseg_in" [ "cstring" ] False "lseg"
+>        , CatCreateFunction
+>            "lseg_interpt" [ "lseg" , "lseg" ] False "point"
+>        , CatCreateFunction
+>            "lseg_intersect" [ "lseg" , "lseg" ] False "bool"
+>        , CatCreateFunction "lseg_le" [ "lseg" , "lseg" ] False "bool"
+>        , CatCreateFunction "lseg_length" [ "lseg" ] False "float8"
+>        , CatCreateFunction "lseg_lt" [ "lseg" , "lseg" ] False "bool"
+>        , CatCreateFunction "lseg_ne" [ "lseg" , "lseg" ] False "bool"
+>        , CatCreateFunction "lseg_out" [ "lseg" ] False "cstring"
+>        , CatCreateFunction
+>            "lseg_parallel" [ "lseg" , "lseg" ] False "bool"
+>        , CatCreateFunction "lseg_perp" [ "lseg" , "lseg" ] False "bool"
+>        , CatCreateFunction "lseg_recv" [ "internal" ] False "lseg"
+>        , CatCreateFunction "lseg_send" [ "lseg" ] False "bytea"
+>        , CatCreateFunction "lseg_vertical" [ "lseg" ] False "bool"
+>        , CatCreateFunction "ltrim" [ "text" , "text" ] False "text"
+>        , CatCreateFunction "ltrim" [ "text" ] False "text"
+>        , CatCreateFunction
+>            "macaddr_and" [ "macaddr" , "macaddr" ] False "macaddr"
+>        , CatCreateFunction
+>            "macaddr_cmp" [ "macaddr" , "macaddr" ] False "int4"
+>        , CatCreateFunction
+>            "macaddr_eq" [ "macaddr" , "macaddr" ] False "bool"
+>        , CatCreateFunction
+>            "macaddr_ge" [ "macaddr" , "macaddr" ] False "bool"
+>        , CatCreateFunction
+>            "macaddr_gt" [ "macaddr" , "macaddr" ] False "bool"
+>        , CatCreateFunction "macaddr_in" [ "cstring" ] False "macaddr"
+>        , CatCreateFunction
+>            "macaddr_le" [ "macaddr" , "macaddr" ] False "bool"
+>        , CatCreateFunction
+>            "macaddr_lt" [ "macaddr" , "macaddr" ] False "bool"
+>        , CatCreateFunction
+>            "macaddr_ne" [ "macaddr" , "macaddr" ] False "bool"
+>        , CatCreateFunction "macaddr_not" [ "macaddr" ] False "macaddr"
+>        , CatCreateFunction
+>            "macaddr_or" [ "macaddr" , "macaddr" ] False "macaddr"
+>        , CatCreateFunction "macaddr_out" [ "macaddr" ] False "cstring"
+>        , CatCreateFunction "macaddr_recv" [ "internal" ] False "macaddr"
+>        , CatCreateFunction "macaddr_send" [ "macaddr" ] False "bytea"
+>        , CatCreateFunction
+>            "make_date" [ "int4" , "int4" , "int4" ] False "date"
+>        , CatCreateFunction
+>            "make_interval"
+>            [ "int4" , "int4" , "float8" , "int4" , "int4" , "int4" , "int4" ]
+>            False
+>            "interval"
+>        , CatCreateFunction
+>            "make_time" [ "int4" , "float8" , "int4" ] False "time"
+>        , CatCreateFunction
+>            "make_timestamp"
+>            [ "float8" , "int4" , "int4" , "int4" , "int4" , "int4" ]
+>            False
+>            "timestamp"
+>        , CatCreateFunction
+>            "make_timestamptz"
+>            [ "int4" , "int4" , "float8" , "int4" , "int4" , "int4" ]
+>            False
+>            "timestamptz"
+>        , CatCreateFunction
+>            "make_timestamptz"
+>            [ "float8" , "int4" , "int4" , "int4" , "int4" , "int4" , "text" ]
+>            False
+>            "timestamptz"
+>        , CatCreateFunction
+>            "makeaclitem" [ "oid" , "oid" , "text" , "bool" ] False "aclitem"
+>        , CatCreateFunction "masklen" [ "inet" ] False "int4"
+>        , CatCreateFunction "md5" [ "text" ] False "text"
+>        , CatCreateFunction "md5" [ "bytea" ] False "text"
+>        , CatCreateFunction
+>            "mic_to_ascii"
+>            [ "int4" , "int4" , "internal" , "cstring" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "mic_to_big5"
+>            [ "int4" , "int4" , "int4" , "cstring" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "mic_to_euc_cn"
+>            [ "int4" , "int4" , "internal" , "int4" , "cstring" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "mic_to_euc_jp"
+>            [ "int4" , "int4" , "cstring" , "int4" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "mic_to_euc_kr"
+>            [ "cstring" , "int4" , "int4" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "mic_to_euc_tw"
+>            [ "int4" , "internal" , "int4" , "int4" , "cstring" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "mic_to_iso"
+>            [ "int4" , "cstring" , "internal" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "mic_to_koi8r"
+>            [ "int4" , "cstring" , "internal" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "mic_to_latin1"
+>            [ "cstring" , "int4" , "int4" , "int4" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "mic_to_latin2"
+>            [ "int4" , "internal" , "int4" , "int4" , "cstring" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "mic_to_latin3"
+>            [ "internal" , "int4" , "int4" , "int4" , "cstring" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "mic_to_latin4"
+>            [ "int4" , "internal" , "cstring" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "mic_to_sjis"
+>            [ "cstring" , "int4" , "int4" , "int4" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "mic_to_win1250"
+>            [ "int4" , "int4" , "internal" , "cstring" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "mic_to_win1251"
+>            [ "int4" , "int4" , "internal" , "cstring" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "mic_to_win866"
+>            [ "int4" , "cstring" , "int4" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "mktinterval" [ "abstime" , "abstime" ] False "tinterval"
+>        , CatCreateFunction "mod" [ "int2" , "int2" ] False "int2"
+>        , CatCreateFunction "mod" [ "int4" , "int4" ] False "int4"
+>        , CatCreateFunction "mod" [ "int8" , "int8" ] False "int8"
+>        , CatCreateFunction "mod" [ "numeric" , "numeric" ] False "numeric"
+>        , CatCreateFunction
+>            "mode_final" [ "internal" , "anyelement" ] False "anyelement"
+>        , CatCreateFunction "money" [ "int4" ] False "money"
+>        , CatCreateFunction "money" [ "int8" ] False "money"
+>        , CatCreateFunction "money" [ "numeric" ] False "money"
+>        , CatCreateFunction
+>            "mul_d_interval" [ "interval" , "float8" ] False "interval"
+>        , CatCreateFunction "name" [ "text" ] False "name"
+>        , CatCreateFunction "name" [ "bpchar" ] False "name"
+>        , CatCreateFunction "name" [ "varchar" ] False "name"
+>        , CatCreateFunction "nameeq" [ "name" , "name" ] False "bool"
+>        , CatCreateFunction "namege" [ "name" , "name" ] False "bool"
+>        , CatCreateFunction "namegt" [ "name" , "name" ] False "bool"
+>        , CatCreateFunction "nameiclike" [ "text" , "name" ] False "bool"
+>        , CatCreateFunction "nameicnlike" [ "name" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "nameicregexeq" [ "name" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "nameicregexne" [ "text" , "name" ] False "bool"
+>        , CatCreateFunction "namein" [ "cstring" ] False "name"
+>        , CatCreateFunction "namele" [ "name" , "name" ] False "bool"
+>        , CatCreateFunction "namelike" [ "name" , "text" ] False "bool"
+>        , CatCreateFunction "namelt" [ "name" , "name" ] False "bool"
+>        , CatCreateFunction "namene" [ "name" , "name" ] False "bool"
+>        , CatCreateFunction "namenlike" [ "name" , "text" ] False "bool"
+>        , CatCreateFunction "nameout" [ "name" ] False "cstring"
+>        , CatCreateFunction "namerecv" [ "internal" ] False "name"
+>        , CatCreateFunction "nameregexeq" [ "name" , "text" ] False "bool"
+>        , CatCreateFunction "nameregexne" [ "text" , "name" ] False "bool"
+>        , CatCreateFunction "namesend" [ "name" ] False "bytea"
+>        , CatCreateFunction
+>            "neqjoinsel"
+>            [ "internal" , "int2" , "internal" , "oid" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "neqsel"
+>            [ "int4" , "oid" , "internal" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction "netmask" [ "inet" ] False "inet"
+>        , CatCreateFunction "network" [ "inet" ] False "cidr"
+>        , CatCreateFunction "network_cmp" [ "inet" , "inet" ] False "int4"
+>        , CatCreateFunction "network_eq" [ "inet" , "inet" ] False "bool"
+>        , CatCreateFunction "network_ge" [ "inet" , "inet" ] False "bool"
+>        , CatCreateFunction "network_gt" [ "inet" , "inet" ] False "bool"
+>        , CatCreateFunction "network_le" [ "inet" , "inet" ] False "bool"
+>        , CatCreateFunction "network_lt" [ "inet" , "inet" ] False "bool"
+>        , CatCreateFunction "network_ne" [ "inet" , "inet" ] False "bool"
+>        , CatCreateFunction
+>            "network_overlap" [ "inet" , "inet" ] False "bool"
+>        , CatCreateFunction "network_sub" [ "inet" , "inet" ] False "bool"
+>        , CatCreateFunction
+>            "network_subeq" [ "inet" , "inet" ] False "bool"
+>        , CatCreateFunction "network_sup" [ "inet" , "inet" ] False "bool"
+>        , CatCreateFunction
+>            "network_supeq" [ "inet" , "inet" ] False "bool"
+>        , CatCreateFunction
+>            "networkjoinsel"
+>            [ "int2" , "internal" , "internal" , "oid" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "networksel"
+>            [ "internal" , "int4" , "internal" , "oid" ]
+>            False
+>            "float8"
+>        , CatCreateFunction "nextval" [ "regclass" ] False "int8"
+>        , CatCreateFunction
+>            "nlikejoinsel"
+>            [ "int2" , "internal" , "oid" , "internal" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "nlikesel"
+>            [ "internal" , "internal" , "int4" , "oid" ]
+>            False
+>            "float8"
+>        , CatCreateFunction "notlike" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction "notlike" [ "text" , "name" ] False "bool"
+>        , CatCreateFunction "notlike" [ "bytea" , "bytea" ] False "bool"
+>        , CatCreateFunction "npoints" [ "path" ] False "int4"
+>        , CatCreateFunction "npoints" [ "polygon" ] False "int4"
+>        , CatCreateFunction
+>            "numeric" [ "int4" , "numeric" ] False "numeric"
+>        , CatCreateFunction "numeric" [ "int4" ] False "numeric"
+>        , CatCreateFunction "numeric" [ "float4" ] False "numeric"
+>        , CatCreateFunction "numeric" [ "float8" ] False "numeric"
+>        , CatCreateFunction "numeric" [ "int8" ] False "numeric"
+>        , CatCreateFunction "numeric" [ "int2" ] False "numeric"
+>        , CatCreateFunction "numeric" [ "money" ] False "numeric"
+>        , CatCreateFunction "numeric_abs" [ "numeric" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_accum" [ "internal" , "numeric" ] False "internal"
+>        , CatCreateFunction
+>            "numeric_accum_inv" [ "numeric" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "numeric_add" [ "numeric" , "numeric" ] False "numeric"
+>        , CatCreateFunction "numeric_avg" [ "internal" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_avg_accum" [ "internal" , "numeric" ] False "internal"
+>        , CatCreateFunction
+>            "numeric_cmp" [ "numeric" , "numeric" ] False "int4"
+>        , CatCreateFunction
+>            "numeric_div" [ "numeric" , "numeric" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_div_trunc" [ "numeric" , "numeric" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_eq" [ "numeric" , "numeric" ] False "bool"
+>        , CatCreateFunction "numeric_exp" [ "numeric" ] False "numeric"
+>        , CatCreateFunction "numeric_fac" [ "int8" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_ge" [ "numeric" , "numeric" ] False "bool"
+>        , CatCreateFunction
+>            "numeric_gt" [ "numeric" , "numeric" ] False "bool"
+>        , CatCreateFunction
+>            "numeric_in" [ "cstring" , "oid" , "int4" ] False "numeric"
+>        , CatCreateFunction "numeric_inc" [ "numeric" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_larger" [ "numeric" , "numeric" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_le" [ "numeric" , "numeric" ] False "bool"
+>        , CatCreateFunction "numeric_ln" [ "numeric" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_log" [ "numeric" , "numeric" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_lt" [ "numeric" , "numeric" ] False "bool"
+>        , CatCreateFunction
+>            "numeric_mod" [ "numeric" , "numeric" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_mul" [ "numeric" , "numeric" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_ne" [ "numeric" , "numeric" ] False "bool"
+>        , CatCreateFunction "numeric_out" [ "numeric" ] False "cstring"
+>        , CatCreateFunction
+>            "numeric_power" [ "numeric" , "numeric" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_recv" [ "internal" , "oid" , "int4" ] False "numeric"
+>        , CatCreateFunction "numeric_send" [ "numeric" ] False "bytea"
+>        , CatCreateFunction
+>            "numeric_smaller" [ "numeric" , "numeric" ] False "numeric"
+>        , CatCreateFunction "numeric_sqrt" [ "numeric" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_stddev_pop" [ "internal" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_stddev_samp" [ "internal" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_sub" [ "numeric" , "numeric" ] False "numeric"
+>        , CatCreateFunction "numeric_sum" [ "internal" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_transform" [ "internal" ] False "internal"
+>        , CatCreateFunction "numeric_uminus" [ "numeric" ] False "numeric"
+>        , CatCreateFunction "numeric_uplus" [ "numeric" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_var_pop" [ "internal" ] False "numeric"
+>        , CatCreateFunction
+>            "numeric_var_samp" [ "internal" ] False "numeric"
+>        , CatCreateFunction "numerictypmodin" [ "_cstring" ] False "int4"
+>        , CatCreateFunction "numerictypmodout" [ "int4" ] False "cstring"
+>        , CatCreateFunction "numnode" [ "tsquery" ] False "int4"
+>        , CatCreateFunction
+>            "numrange" [ "numeric" , "numeric" ] False "numrange"
+>        , CatCreateFunction
+>            "numrange" [ "text" , "numeric" , "numeric" ] False "numrange"
+>        , CatCreateFunction
+>            "numrange_subdiff" [ "numeric" , "numeric" ] False "float8"
+>        , CatCreateFunction
+>            "obj_description" [ "name" , "oid" ] False "text"
+>        , CatCreateFunction "obj_description" [ "oid" ] False "text"
+>        , CatCreateFunction "octet_length" [ "bytea" ] False "int4"
+>        , CatCreateFunction "octet_length" [ "text" ] False "int4"
+>        , CatCreateFunction "octet_length" [ "bpchar" ] False "int4"
+>        , CatCreateFunction "octet_length" [ "bit" ] False "int4"
+>        , CatCreateFunction "oid" [ "int8" ] False "oid"
+>        , CatCreateFunction "oideq" [ "oid" , "oid" ] False "bool"
+>        , CatCreateFunction "oidge" [ "oid" , "oid" ] False "bool"
+>        , CatCreateFunction "oidgt" [ "oid" , "oid" ] False "bool"
+>        , CatCreateFunction "oidin" [ "cstring" ] False "oid"
+>        , CatCreateFunction "oidlarger" [ "oid" , "oid" ] False "oid"
+>        , CatCreateFunction "oidle" [ "oid" , "oid" ] False "bool"
+>        , CatCreateFunction "oidlt" [ "oid" , "oid" ] False "bool"
+>        , CatCreateFunction "oidne" [ "oid" , "oid" ] False "bool"
+>        , CatCreateFunction "oidout" [ "oid" ] False "cstring"
+>        , CatCreateFunction "oidrecv" [ "internal" ] False "oid"
+>        , CatCreateFunction "oidsend" [ "oid" ] False "bytea"
+>        , CatCreateFunction "oidsmaller" [ "oid" , "oid" ] False "oid"
+>        , CatCreateFunction
+>            "oidvectoreq" [ "oidvector" , "oidvector" ] False "bool"
+>        , CatCreateFunction
+>            "oidvectorge" [ "oidvector" , "oidvector" ] False "bool"
+>        , CatCreateFunction
+>            "oidvectorgt" [ "oidvector" , "oidvector" ] False "bool"
+>        , CatCreateFunction "oidvectorin" [ "cstring" ] False "oidvector"
+>        , CatCreateFunction
+>            "oidvectorle" [ "oidvector" , "oidvector" ] False "bool"
+>        , CatCreateFunction
+>            "oidvectorlt" [ "oidvector" , "oidvector" ] False "bool"
+>        , CatCreateFunction
+>            "oidvectorne" [ "oidvector" , "oidvector" ] False "bool"
+>        , CatCreateFunction "oidvectorout" [ "oidvector" ] False "cstring"
+>        , CatCreateFunction
+>            "oidvectorrecv" [ "internal" ] False "oidvector"
+>        , CatCreateFunction "oidvectorsend" [ "oidvector" ] False "bytea"
+>        , CatCreateFunction "oidvectortypes" [ "oidvector" ] False "text"
+>        , CatCreateFunction "on_pb" [ "box" , "point" ] False "bool"
+>        , CatCreateFunction "on_pl" [ "point" , "line" ] False "bool"
+>        , CatCreateFunction "on_ppath" [ "path" , "point" ] False "bool"
+>        , CatCreateFunction "on_ps" [ "lseg" , "point" ] False "bool"
+>        , CatCreateFunction "on_sb" [ "box" , "lseg" ] False "bool"
+>        , CatCreateFunction "on_sl" [ "lseg" , "line" ] False "bool"
+>        , CatCreateFunction "opaque_in" [ "cstring" ] False "opaque"
+>        , CatCreateFunction "opaque_out" [ "opaque" ] False "cstring"
+>        , CatCreateFunction
+>            "ordered_set_transition" [ "internal" , "any" ] False "internal"
+>        , CatCreateFunction
+>            "overlaps"
+>            [ "timetz" , "timetz" , "timetz" , "timetz" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "overlaps"
+>            [ "timestamptz" , "timestamptz" , "timestamptz" , "timestamptz" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "overlaps"
+>            [ "interval" , "timestamptz" , "interval" , "timestamptz" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "overlaps"
+>            [ "interval" , "timestamptz" , "timestamptz" , "timestamptz" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "overlaps"
+>            [ "timestamptz" , "timestamptz" , "interval" , "timestamptz" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "overlaps" [ "time" , "time" , "time" , "time" ] False "bool"
+>        , CatCreateFunction
+>            "overlaps"
+>            [ "time" , "interval" , "time" , "interval" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "overlaps" [ "interval" , "time" , "time" , "time" ] False "bool"
+>        , CatCreateFunction
+>            "overlaps" [ "time" , "time" , "interval" , "time" ] False "bool"
+>        , CatCreateFunction
+>            "overlaps"
+>            [ "timestamp" , "timestamp" , "timestamp" , "timestamp" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "overlaps"
+>            [ "timestamp" , "interval" , "timestamp" , "interval" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "overlaps"
+>            [ "timestamp" , "timestamp" , "timestamp" , "interval" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "overlaps"
+>            [ "timestamp" , "interval" , "timestamp" , "timestamp" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "overlay" [ "bytea" , "bytea" , "int4" , "int4" ] False "bytea"
+>        , CatCreateFunction
+>            "overlay" [ "int4" , "bytea" , "bytea" ] False "bytea"
+>        , CatCreateFunction
+>            "overlay" [ "int4" , "int4" , "text" , "text" ] False "text"
+>        , CatCreateFunction
+>            "overlay" [ "text" , "text" , "int4" ] False "text"
+>        , CatCreateFunction
+>            "overlay" [ "bit" , "int4" , "int4" , "bit" ] False "bit"
+>        , CatCreateFunction
+>            "overlay" [ "int4" , "bit" , "bit" ] False "bit"
+>        , CatCreateFunction "path" [ "polygon" ] False "path"
+>        , CatCreateFunction "path_add" [ "path" , "path" ] False "path"
+>        , CatCreateFunction "path_add_pt" [ "path" , "point" ] False "path"
+>        , CatCreateFunction "path_center" [ "path" ] False "point"
+>        , CatCreateFunction
+>            "path_contain_pt" [ "point" , "path" ] False "bool"
+>        , CatCreateFunction
+>            "path_distance" [ "path" , "path" ] False "float8"
+>        , CatCreateFunction "path_div_pt" [ "point" , "path" ] False "path"
+>        , CatCreateFunction "path_in" [ "cstring" ] False "path"
+>        , CatCreateFunction "path_inter" [ "path" , "path" ] False "bool"
+>        , CatCreateFunction "path_length" [ "path" ] False "float8"
+>        , CatCreateFunction "path_mul_pt" [ "path" , "point" ] False "path"
+>        , CatCreateFunction "path_n_eq" [ "path" , "path" ] False "bool"
+>        , CatCreateFunction "path_n_ge" [ "path" , "path" ] False "bool"
+>        , CatCreateFunction "path_n_gt" [ "path" , "path" ] False "bool"
+>        , CatCreateFunction "path_n_le" [ "path" , "path" ] False "bool"
+>        , CatCreateFunction "path_n_lt" [ "path" , "path" ] False "bool"
+>        , CatCreateFunction "path_npoints" [ "path" ] False "int4"
+>        , CatCreateFunction "path_out" [ "path" ] False "cstring"
+>        , CatCreateFunction "path_recv" [ "internal" ] False "path"
+>        , CatCreateFunction "path_send" [ "path" ] False "bytea"
+>        , CatCreateFunction "path_sub_pt" [ "path" , "point" ] False "path"
+>        , CatCreateFunction "pclose" [ "path" ] False "path"
+>        , CatCreateFunction
+>            "percentile_cont_float8_final"
+>            [ "internal" , "float8" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "percentile_cont_float8_multi_final"
+>            [ "_float8" , "internal" ]
+>            False
+>            "_float8"
+>        , CatCreateFunction
+>            "percentile_cont_interval_final"
+>            [ "internal" , "float8" ]
+>            False
+>            "interval"
+>        , CatCreateFunction
+>            "percentile_cont_interval_multi_final"
+>            [ "_float8" , "internal" ]
+>            False
+>            "_interval"
+>        , CatCreateFunction
+>            "percentile_disc_final"
+>            [ "float8" , "anyelement" , "internal" ]
+>            False
+>            "anyelement"
+>        , CatCreateFunction
+>            "percentile_disc_multi_final"
+>            [ "internal" , "_float8" , "anyelement" ]
+>            False
+>            "anyarray"
+>        , CatCreateFunction "pg_advisory_lock" [ "int8" ] False "void"
+>        , CatCreateFunction
+>            "pg_advisory_lock" [ "int4" , "int4" ] False "void"
+>        , CatCreateFunction
+>            "pg_advisory_lock_shared" [ "int8" ] False "void"
+>        , CatCreateFunction
+>            "pg_advisory_lock_shared" [ "int4" , "int4" ] False "void"
+>        , CatCreateFunction "pg_advisory_unlock" [ "int8" ] False "bool"
+>        , CatCreateFunction
+>            "pg_advisory_unlock" [ "int4" , "int4" ] False "bool"
+>        , CatCreateFunction
+>            "pg_advisory_unlock_shared" [ "int8" ] False "bool"
+>        , CatCreateFunction
+>            "pg_advisory_unlock_shared" [ "int4" , "int4" ] False "bool"
+>        , CatCreateFunction "pg_advisory_xact_lock" [ "int8" ] False "void"
+>        , CatCreateFunction
+>            "pg_advisory_xact_lock" [ "int4" , "int4" ] False "void"
+>        , CatCreateFunction
+>            "pg_advisory_xact_lock_shared" [ "int8" ] False "void"
+>        , CatCreateFunction
+>            "pg_advisory_xact_lock_shared" [ "int4" , "int4" ] False "void"
+>        , CatCreateFunction "pg_cancel_backend" [ "int4" ] False "bool"
+>        , CatCreateFunction "pg_char_to_encoding" [ "name" ] False "int4"
+>        , CatCreateFunction "pg_collation_for" [ "any" ] False "text"
+>        , CatCreateFunction
+>            "pg_collation_is_visible" [ "oid" ] False "bool"
+>        , CatCreateFunction
+>            "pg_column_is_updatable"
+>            [ "regclass" , "int2" , "bool" ]
+>            False
+>            "bool"
+>        , CatCreateFunction "pg_column_size" [ "any" ] False "int4"
+>        , CatCreateFunction
+>            "pg_conversion_is_visible" [ "oid" ] False "bool"
+>        , CatCreateFunction
+>            "pg_create_logical_replication_slot"
+>            [ "name" , "name" ]
+>            False
+>            "record"
+>        , CatCreateFunction
+>            "pg_create_physical_replication_slot" [ "name" ] False "record"
+>        , CatCreateFunction
+>            "pg_create_restore_point" [ "text" ] False "pg_lsn"
+>        , CatCreateFunction "pg_database_size" [ "name" ] False "int8"
+>        , CatCreateFunction "pg_database_size" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_describe_object" [ "oid" , "oid" , "int4" ] False "text"
+>        , CatCreateFunction
+>            "pg_drop_replication_slot" [ "name" ] False "void"
+>        , CatCreateFunction
+>            "pg_encoding_max_length" [ "int4" ] False "int4"
+>        , CatCreateFunction "pg_encoding_to_char" [ "int4" ] False "name"
+>        , CatCreateFunction
+>            "pg_extension_config_dump" [ "regclass" , "text" ] False "void"
+>        , CatCreateFunction
+>            "pg_extension_update_paths" [ "name" ] True "record"
+>        , CatCreateFunction
+>            "pg_filenode_relation" [ "oid" , "oid" ] False "regclass"
+>        , CatCreateFunction "pg_function_is_visible" [ "oid" ] False "bool"
+>        , CatCreateFunction "pg_get_constraintdef" [ "oid" ] False "text"
+>        , CatCreateFunction
+>            "pg_get_constraintdef" [ "oid" , "bool" ] False "text"
+>        , CatCreateFunction
+>            "pg_get_expr" [ "oid" , "pg_node_tree" ] False "text"
+>        , CatCreateFunction
+>            "pg_get_expr" [ "oid" , "bool" , "pg_node_tree" ] False "text"
+>        , CatCreateFunction
+>            "pg_get_function_arg_default" [ "oid" , "int4" ] False "text"
+>        , CatCreateFunction
+>            "pg_get_function_arguments" [ "oid" ] False "text"
+>        , CatCreateFunction
+>            "pg_get_function_identity_arguments" [ "oid" ] False "text"
+>        , CatCreateFunction "pg_get_function_result" [ "oid" ] False "text"
+>        , CatCreateFunction "pg_get_functiondef" [ "oid" ] False "text"
+>        , CatCreateFunction "pg_get_indexdef" [ "oid" ] False "text"
+>        , CatCreateFunction
+>            "pg_get_indexdef" [ "oid" , "int4" , "bool" ] False "text"
+>        , CatCreateFunction
+>            "pg_get_multixact_members" [ "xid" ] True "record"
+>        , CatCreateFunction "pg_get_ruledef" [ "oid" ] False "text"
+>        , CatCreateFunction
+>            "pg_get_ruledef" [ "oid" , "bool" ] False "text"
+>        , CatCreateFunction
+>            "pg_get_serial_sequence" [ "text" , "text" ] False "text"
+>        , CatCreateFunction "pg_get_triggerdef" [ "oid" ] False "text"
+>        , CatCreateFunction
+>            "pg_get_triggerdef" [ "bool" , "oid" ] False "text"
+>        , CatCreateFunction "pg_get_userbyid" [ "oid" ] False "name"
+>        , CatCreateFunction "pg_get_viewdef" [ "text" ] False "text"
+>        , CatCreateFunction "pg_get_viewdef" [ "oid" ] False "text"
+>        , CatCreateFunction
+>            "pg_get_viewdef" [ "bool" , "text" ] False "text"
+>        , CatCreateFunction
+>            "pg_get_viewdef" [ "oid" , "bool" ] False "text"
+>        , CatCreateFunction
+>            "pg_get_viewdef" [ "int4" , "oid" ] False "text"
+>        , CatCreateFunction
+>            "pg_has_role" [ "text" , "name" , "name" ] False "bool"
+>        , CatCreateFunction
+>            "pg_has_role" [ "text" , "name" , "oid" ] False "bool"
+>        , CatCreateFunction
+>            "pg_has_role" [ "oid" , "name" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "pg_has_role" [ "oid" , "oid" , "text" ] False "bool"
+>        , CatCreateFunction "pg_has_role" [ "text" , "name" ] False "bool"
+>        , CatCreateFunction "pg_has_role" [ "oid" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "pg_identify_object" [ "oid" , "int4" , "oid" ] False "record"
+>        , CatCreateFunction "pg_indexes_size" [ "regclass" ] False "int8"
+>        , CatCreateFunction
+>            "pg_is_other_temp_schema" [ "oid" ] False "bool"
+>        , CatCreateFunction "pg_ls_dir" [ "text" ] True "text"
+>        , CatCreateFunction
+>            "pg_lsn_cmp" [ "pg_lsn" , "pg_lsn" ] False "int4"
+>        , CatCreateFunction
+>            "pg_lsn_eq" [ "pg_lsn" , "pg_lsn" ] False "bool"
+>        , CatCreateFunction
+>            "pg_lsn_ge" [ "pg_lsn" , "pg_lsn" ] False "bool"
+>        , CatCreateFunction
+>            "pg_lsn_gt" [ "pg_lsn" , "pg_lsn" ] False "bool"
+>        , CatCreateFunction "pg_lsn_hash" [ "pg_lsn" ] False "int4"
+>        , CatCreateFunction "pg_lsn_in" [ "cstring" ] False "pg_lsn"
+>        , CatCreateFunction
+>            "pg_lsn_le" [ "pg_lsn" , "pg_lsn" ] False "bool"
+>        , CatCreateFunction
+>            "pg_lsn_lt" [ "pg_lsn" , "pg_lsn" ] False "bool"
+>        , CatCreateFunction
+>            "pg_lsn_mi" [ "pg_lsn" , "pg_lsn" ] False "numeric"
+>        , CatCreateFunction
+>            "pg_lsn_ne" [ "pg_lsn" , "pg_lsn" ] False "bool"
+>        , CatCreateFunction "pg_lsn_out" [ "pg_lsn" ] False "cstring"
+>        , CatCreateFunction "pg_lsn_recv" [ "internal" ] False "pg_lsn"
+>        , CatCreateFunction "pg_lsn_send" [ "pg_lsn" ] False "bytea"
+>        , CatCreateFunction
+>            "pg_node_tree_in" [ "cstring" ] False "pg_node_tree"
+>        , CatCreateFunction
+>            "pg_node_tree_out" [ "pg_node_tree" ] False "cstring"
+>        , CatCreateFunction
+>            "pg_node_tree_recv" [ "internal" ] False "pg_node_tree"
+>        , CatCreateFunction
+>            "pg_node_tree_send" [ "pg_node_tree" ] False "bytea"
+>        , CatCreateFunction "pg_notify" [ "text" , "text" ] False "void"
+>        , CatCreateFunction "pg_opclass_is_visible" [ "oid" ] False "bool"
+>        , CatCreateFunction "pg_operator_is_visible" [ "oid" ] False "bool"
+>        , CatCreateFunction "pg_opfamily_is_visible" [ "oid" ] False "bool"
+>        , CatCreateFunction "pg_options_to_table" [ "_text" ] True "record"
+>        , CatCreateFunction
+>            "pg_read_binary_file" [ "int8" , "text" , "int8" ] False "bytea"
+>        , CatCreateFunction "pg_read_binary_file" [ "text" ] False "bytea"
+>        , CatCreateFunction
+>            "pg_read_file" [ "text" , "int8" , "int8" ] False "text"
+>        , CatCreateFunction "pg_read_file" [ "text" ] False "text"
+>        , CatCreateFunction
+>            "pg_relation_filenode" [ "regclass" ] False "oid"
+>        , CatCreateFunction
+>            "pg_relation_filepath" [ "regclass" ] False "text"
+>        , CatCreateFunction
+>            "pg_relation_is_updatable" [ "bool" , "regclass" ] False "int4"
+>        , CatCreateFunction "pg_relation_size" [ "regclass" ] False "int8"
+>        , CatCreateFunction
+>            "pg_relation_size" [ "regclass" , "text" ] False "int8"
+>        , CatCreateFunction
+>            "pg_sequence_parameters" [ "oid" ] False "record"
+>        , CatCreateFunction "pg_size_pretty" [ "int8" ] False "text"
+>        , CatCreateFunction "pg_size_pretty" [ "numeric" ] False "text"
+>        , CatCreateFunction "pg_sleep" [ "float8" ] False "void"
+>        , CatCreateFunction "pg_sleep_for" [ "interval" ] False "void"
+>        , CatCreateFunction "pg_sleep_until" [ "timestamptz" ] False "void"
+>        , CatCreateFunction
+>            "pg_start_backup" [ "bool" , "text" ] False "pg_lsn"
+>        , CatCreateFunction "pg_stat_file" [ "text" ] False "record"
+>        , CatCreateFunction "pg_stat_get_activity" [ "int4" ] True "record"
+>        , CatCreateFunction
+>            "pg_stat_get_analyze_count" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_autoanalyze_count" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_autovacuum_count" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_backend_activity" [ "int4" ] False "text"
+>        , CatCreateFunction
+>            "pg_stat_get_backend_activity_start" [ "int4" ] False "timestamptz"
+>        , CatCreateFunction
+>            "pg_stat_get_backend_client_addr" [ "int4" ] False "inet"
+>        , CatCreateFunction
+>            "pg_stat_get_backend_client_port" [ "int4" ] False "int4"
+>        , CatCreateFunction
+>            "pg_stat_get_backend_dbid" [ "int4" ] False "oid"
+>        , CatCreateFunction
+>            "pg_stat_get_backend_pid" [ "int4" ] False "int4"
+>        , CatCreateFunction
+>            "pg_stat_get_backend_start" [ "int4" ] False "timestamptz"
+>        , CatCreateFunction
+>            "pg_stat_get_backend_userid" [ "int4" ] False "oid"
+>        , CatCreateFunction
+>            "pg_stat_get_backend_waiting" [ "int4" ] False "bool"
+>        , CatCreateFunction
+>            "pg_stat_get_backend_xact_start" [ "int4" ] False "timestamptz"
+>        , CatCreateFunction
+>            "pg_stat_get_blocks_fetched" [ "oid" ] False "int8"
+>        , CatCreateFunction "pg_stat_get_blocks_hit" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_blk_read_time" [ "oid" ] False "float8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_blk_write_time" [ "oid" ] False "float8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_blocks_fetched" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_blocks_hit" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_conflict_all" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_conflict_bufferpin" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_conflict_lock" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_conflict_snapshot" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_conflict_startup_deadlock" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_conflict_tablespace" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_deadlocks" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_numbackends" [ "oid" ] False "int4"
+>        , CatCreateFunction
+>            "pg_stat_get_db_stat_reset_time" [ "oid" ] False "timestamptz"
+>        , CatCreateFunction
+>            "pg_stat_get_db_temp_bytes" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_temp_files" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_tuples_deleted" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_tuples_fetched" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_tuples_inserted" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_tuples_returned" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_tuples_updated" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_xact_commit" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_db_xact_rollback" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_dead_tuples" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_function_calls" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_function_self_time" [ "oid" ] False "float8"
+>        , CatCreateFunction
+>            "pg_stat_get_function_total_time" [ "oid" ] False "float8"
+>        , CatCreateFunction
+>            "pg_stat_get_last_analyze_time" [ "oid" ] False "timestamptz"
+>        , CatCreateFunction
+>            "pg_stat_get_last_autoanalyze_time" [ "oid" ] False "timestamptz"
+>        , CatCreateFunction
+>            "pg_stat_get_last_autovacuum_time" [ "oid" ] False "timestamptz"
+>        , CatCreateFunction
+>            "pg_stat_get_last_vacuum_time" [ "oid" ] False "timestamptz"
+>        , CatCreateFunction
+>            "pg_stat_get_live_tuples" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_mod_since_analyze" [ "oid" ] False "int8"
+>        , CatCreateFunction "pg_stat_get_numscans" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_tuples_deleted" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_tuples_fetched" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_tuples_hot_updated" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_tuples_inserted" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_tuples_returned" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_tuples_updated" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_vacuum_count" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_xact_blocks_fetched" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_xact_blocks_hit" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_xact_function_calls" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_xact_function_self_time" [ "oid" ] False "float8"
+>        , CatCreateFunction
+>            "pg_stat_get_xact_function_total_time" [ "oid" ] False "float8"
+>        , CatCreateFunction
+>            "pg_stat_get_xact_numscans" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_xact_tuples_deleted" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_xact_tuples_fetched" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_xact_tuples_hot_updated" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_xact_tuples_inserted" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_xact_tuples_returned" [ "oid" ] False "int8"
+>        , CatCreateFunction
+>            "pg_stat_get_xact_tuples_updated" [ "oid" ] False "int8"
+>        , CatCreateFunction "pg_stat_reset_shared" [ "text" ] False "void"
+>        , CatCreateFunction
+>            "pg_stat_reset_single_function_counters" [ "oid" ] False "void"
+>        , CatCreateFunction
+>            "pg_stat_reset_single_table_counters" [ "oid" ] False "void"
+>        , CatCreateFunction "pg_table_is_visible" [ "oid" ] False "bool"
+>        , CatCreateFunction "pg_table_size" [ "regclass" ] False "int8"
+>        , CatCreateFunction "pg_tablespace_databases" [ "oid" ] True "oid"
+>        , CatCreateFunction "pg_tablespace_location" [ "oid" ] False "text"
+>        , CatCreateFunction "pg_tablespace_size" [ "oid" ] False "int8"
+>        , CatCreateFunction "pg_tablespace_size" [ "name" ] False "int8"
+>        , CatCreateFunction "pg_terminate_backend" [ "int4" ] False "bool"
+>        , CatCreateFunction
+>            "pg_total_relation_size" [ "regclass" ] False "int8"
+>        , CatCreateFunction "pg_try_advisory_lock" [ "int8" ] False "bool"
+>        , CatCreateFunction
+>            "pg_try_advisory_lock" [ "int4" , "int4" ] False "bool"
+>        , CatCreateFunction
+>            "pg_try_advisory_lock_shared" [ "int8" ] False "bool"
+>        , CatCreateFunction
+>            "pg_try_advisory_lock_shared" [ "int4" , "int4" ] False "bool"
+>        , CatCreateFunction
+>            "pg_try_advisory_xact_lock" [ "int8" ] False "bool"
+>        , CatCreateFunction
+>            "pg_try_advisory_xact_lock" [ "int4" , "int4" ] False "bool"
+>        , CatCreateFunction
+>            "pg_try_advisory_xact_lock_shared" [ "int8" ] False "bool"
+>        , CatCreateFunction
+>            "pg_try_advisory_xact_lock_shared" [ "int4" , "int4" ] False "bool"
+>        , CatCreateFunction
+>            "pg_ts_config_is_visible" [ "oid" ] False "bool"
+>        , CatCreateFunction "pg_ts_dict_is_visible" [ "oid" ] False "bool"
+>        , CatCreateFunction
+>            "pg_ts_parser_is_visible" [ "oid" ] False "bool"
+>        , CatCreateFunction
+>            "pg_ts_template_is_visible" [ "oid" ] False "bool"
+>        , CatCreateFunction "pg_type_is_visible" [ "oid" ] False "bool"
+>        , CatCreateFunction "pg_typeof" [ "any" ] False "regtype"
+>        , CatCreateFunction
+>            "pg_xlog_location_diff" [ "pg_lsn" , "pg_lsn" ] False "numeric"
+>        , CatCreateFunction "pg_xlogfile_name" [ "pg_lsn" ] False "text"
+>        , CatCreateFunction
+>            "pg_xlogfile_name_offset" [ "pg_lsn" ] False "record"
+>        , CatCreateFunction
+>            "plainto_tsquery" [ "regconfig" , "text" ] False "tsquery"
+>        , CatCreateFunction "plainto_tsquery" [ "text" ] False "tsquery"
+>        , CatCreateFunction
+>            "plpgsql_inline_handler" [ "internal" ] False "void"
+>        , CatCreateFunction "plpgsql_validator" [ "oid" ] False "void"
+>        , CatCreateFunction "point" [ "circle" ] False "point"
+>        , CatCreateFunction "point" [ "float8" , "float8" ] False "point"
+>        , CatCreateFunction "point" [ "lseg" ] False "point"
+>        , CatCreateFunction "point" [ "path" ] False "point"
+>        , CatCreateFunction "point" [ "box" ] False "point"
+>        , CatCreateFunction "point" [ "polygon" ] False "point"
+>        , CatCreateFunction
+>            "point_above" [ "point" , "point" ] False "bool"
+>        , CatCreateFunction "point_add" [ "point" , "point" ] False "point"
+>        , CatCreateFunction
+>            "point_below" [ "point" , "point" ] False "bool"
+>        , CatCreateFunction
+>            "point_distance" [ "point" , "point" ] False "float8"
+>        , CatCreateFunction "point_div" [ "point" , "point" ] False "point"
+>        , CatCreateFunction "point_eq" [ "point" , "point" ] False "bool"
+>        , CatCreateFunction
+>            "point_horiz" [ "point" , "point" ] False "bool"
+>        , CatCreateFunction "point_in" [ "cstring" ] False "point"
+>        , CatCreateFunction "point_left" [ "point" , "point" ] False "bool"
+>        , CatCreateFunction "point_mul" [ "point" , "point" ] False "point"
+>        , CatCreateFunction "point_ne" [ "point" , "point" ] False "bool"
+>        , CatCreateFunction "point_out" [ "point" ] False "cstring"
+>        , CatCreateFunction "point_recv" [ "internal" ] False "point"
+>        , CatCreateFunction
+>            "point_right" [ "point" , "point" ] False "bool"
+>        , CatCreateFunction "point_send" [ "point" ] False "bytea"
+>        , CatCreateFunction "point_sub" [ "point" , "point" ] False "point"
+>        , CatCreateFunction "point_vert" [ "point" , "point" ] False "bool"
+>        , CatCreateFunction
+>            "poly_above" [ "polygon" , "polygon" ] False "bool"
+>        , CatCreateFunction
+>            "poly_below" [ "polygon" , "polygon" ] False "bool"
+>        , CatCreateFunction "poly_center" [ "polygon" ] False "point"
+>        , CatCreateFunction
+>            "poly_contain" [ "polygon" , "polygon" ] False "bool"
+>        , CatCreateFunction
+>            "poly_contain_pt" [ "polygon" , "point" ] False "bool"
+>        , CatCreateFunction
+>            "poly_contained" [ "polygon" , "polygon" ] False "bool"
+>        , CatCreateFunction
+>            "poly_distance" [ "polygon" , "polygon" ] False "float8"
+>        , CatCreateFunction "poly_in" [ "cstring" ] False "polygon"
+>        , CatCreateFunction
+>            "poly_left" [ "polygon" , "polygon" ] False "bool"
+>        , CatCreateFunction "poly_npoints" [ "polygon" ] False "int4"
+>        , CatCreateFunction "poly_out" [ "polygon" ] False "cstring"
+>        , CatCreateFunction
+>            "poly_overabove" [ "polygon" , "polygon" ] False "bool"
+>        , CatCreateFunction
+>            "poly_overbelow" [ "polygon" , "polygon" ] False "bool"
+>        , CatCreateFunction
+>            "poly_overlap" [ "polygon" , "polygon" ] False "bool"
+>        , CatCreateFunction
+>            "poly_overleft" [ "polygon" , "polygon" ] False "bool"
+>        , CatCreateFunction
+>            "poly_overright" [ "polygon" , "polygon" ] False "bool"
+>        , CatCreateFunction "poly_recv" [ "internal" ] False "polygon"
+>        , CatCreateFunction
+>            "poly_right" [ "polygon" , "polygon" ] False "bool"
+>        , CatCreateFunction
+>            "poly_same" [ "polygon" , "polygon" ] False "bool"
+>        , CatCreateFunction "poly_send" [ "polygon" ] False "bytea"
+>        , CatCreateFunction "polygon" [ "box" ] False "polygon"
+>        , CatCreateFunction "polygon" [ "path" ] False "polygon"
+>        , CatCreateFunction "polygon" [ "circle" , "int4" ] False "polygon"
+>        , CatCreateFunction "polygon" [ "circle" ] False "polygon"
+>        , CatCreateFunction "popen" [ "path" ] False "path"
+>        , CatCreateFunction "position" [ "text" , "text" ] False "int4"
+>        , CatCreateFunction "position" [ "bit" , "bit" ] False "int4"
+>        , CatCreateFunction "position" [ "bytea" , "bytea" ] False "int4"
+>        , CatCreateFunction
+>            "positionjoinsel"
+>            [ "int2" , "internal" , "internal" , "oid" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "positionsel"
+>            [ "oid" , "internal" , "int4" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "postgresql_fdw_validator" [ "_text" , "oid" ] False "bool"
+>        , CatCreateFunction "pow" [ "float8" , "float8" ] False "float8"
+>        , CatCreateFunction "pow" [ "numeric" , "numeric" ] False "numeric"
+>        , CatCreateFunction "power" [ "float8" , "float8" ] False "float8"
+>        , CatCreateFunction
+>            "power" [ "numeric" , "numeric" ] False "numeric"
+>        , CatCreateFunction "prsd_end" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "prsd_headline"
+>            [ "internal" , "tsquery" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction "prsd_lextype" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "prsd_nexttoken"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "prsd_start" [ "int4" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "pt_contained_circle" [ "circle" , "point" ] False "bool"
+>        , CatCreateFunction
+>            "pt_contained_poly" [ "polygon" , "point" ] False "bool"
+>        , CatCreateFunction
+>            "query_to_xml" [ "text" , "text" , "bool" , "bool" ] False "xml"
+>        , CatCreateFunction
+>            "query_to_xml_and_xmlschema"
+>            [ "text" , "bool" , "text" , "bool" ]
+>            False
+>            "xml"
+>        , CatCreateFunction
+>            "query_to_xmlschema"
+>            [ "bool" , "text" , "text" , "bool" ]
+>            False
+>            "xml"
+>        , CatCreateFunction "querytree" [ "tsquery" ] False "text"
+>        , CatCreateFunction "quote_ident" [ "text" ] False "text"
+>        , CatCreateFunction "quote_literal" [ "text" ] False "text"
+>        , CatCreateFunction "quote_literal" [ "anyelement" ] False "text"
+>        , CatCreateFunction "quote_nullable" [ "text" ] False "text"
+>        , CatCreateFunction "quote_nullable" [ "anyelement" ] False "text"
+>        , CatCreateFunction "radians" [ "float8" ] False "float8"
+>        , CatCreateFunction "radius" [ "circle" ] False "float8"
+>        , CatCreateFunction
+>            "range_adjacent" [ "anyrange" , "anyrange" ] False "bool"
+>        , CatCreateFunction
+>            "range_after" [ "anyrange" , "anyrange" ] False "bool"
+>        , CatCreateFunction
+>            "range_before" [ "anyrange" , "anyrange" ] False "bool"
+>        , CatCreateFunction
+>            "range_cmp" [ "anyrange" , "anyrange" ] False "int4"
+>        , CatCreateFunction
+>            "range_contained_by" [ "anyrange" , "anyrange" ] False "bool"
+>        , CatCreateFunction
+>            "range_contains" [ "anyrange" , "anyrange" ] False "bool"
+>        , CatCreateFunction
+>            "range_contains_elem" [ "anyelement" , "anyrange" ] False "bool"
+>        , CatCreateFunction
+>            "range_eq" [ "anyrange" , "anyrange" ] False "bool"
+>        , CatCreateFunction
+>            "range_ge" [ "anyrange" , "anyrange" ] False "bool"
+>        , CatCreateFunction
+>            "range_gist_compress" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "range_gist_consistent"
+>            [ "oid" , "internal" , "int4" , "internal" , "anyrange" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "range_gist_decompress" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "range_gist_penalty"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "range_gist_picksplit" [ "internal" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "range_gist_same"
+>            [ "internal" , "anyrange" , "anyrange" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "range_gist_union" [ "internal" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "range_gt" [ "anyrange" , "anyrange" ] False "bool"
+>        , CatCreateFunction
+>            "range_in" [ "cstring" , "oid" , "int4" ] False "anyrange"
+>        , CatCreateFunction
+>            "range_intersect" [ "anyrange" , "anyrange" ] False "anyrange"
+>        , CatCreateFunction
+>            "range_le" [ "anyrange" , "anyrange" ] False "bool"
+>        , CatCreateFunction
+>            "range_lt" [ "anyrange" , "anyrange" ] False "bool"
+>        , CatCreateFunction
+>            "range_minus" [ "anyrange" , "anyrange" ] False "anyrange"
+>        , CatCreateFunction
+>            "range_ne" [ "anyrange" , "anyrange" ] False "bool"
+>        , CatCreateFunction "range_out" [ "anyrange" ] False "cstring"
+>        , CatCreateFunction
+>            "range_overlaps" [ "anyrange" , "anyrange" ] False "bool"
+>        , CatCreateFunction
+>            "range_overleft" [ "anyrange" , "anyrange" ] False "bool"
+>        , CatCreateFunction
+>            "range_overright" [ "anyrange" , "anyrange" ] False "bool"
+>        , CatCreateFunction
+>            "range_recv" [ "internal" , "oid" , "int4" ] False "anyrange"
+>        , CatCreateFunction "range_send" [ "anyrange" ] False "bytea"
+>        , CatCreateFunction "range_typanalyze" [ "internal" ] False "bool"
+>        , CatCreateFunction
+>            "range_union" [ "anyrange" , "anyrange" ] False "anyrange"
+>        , CatCreateFunction
+>            "rangesel"
+>            [ "internal" , "internal" , "oid" , "int4" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "record_eq" [ "record" , "record" ] False "bool"
+>        , CatCreateFunction
+>            "record_ge" [ "record" , "record" ] False "bool"
+>        , CatCreateFunction
+>            "record_gt" [ "record" , "record" ] False "bool"
+>        , CatCreateFunction
+>            "record_image_eq" [ "record" , "record" ] False "bool"
+>        , CatCreateFunction
+>            "record_image_ge" [ "record" , "record" ] False "bool"
+>        , CatCreateFunction
+>            "record_image_gt" [ "record" , "record" ] False "bool"
+>        , CatCreateFunction
+>            "record_image_le" [ "record" , "record" ] False "bool"
+>        , CatCreateFunction
+>            "record_image_lt" [ "record" , "record" ] False "bool"
+>        , CatCreateFunction
+>            "record_image_ne" [ "record" , "record" ] False "bool"
+>        , CatCreateFunction
+>            "record_in" [ "int4" , "cstring" , "oid" ] False "record"
+>        , CatCreateFunction
+>            "record_le" [ "record" , "record" ] False "bool"
+>        , CatCreateFunction
+>            "record_lt" [ "record" , "record" ] False "bool"
+>        , CatCreateFunction
+>            "record_ne" [ "record" , "record" ] False "bool"
+>        , CatCreateFunction "record_out" [ "record" ] False "cstring"
+>        , CatCreateFunction
+>            "record_recv" [ "oid" , "int4" , "internal" ] False "record"
+>        , CatCreateFunction "record_send" [ "record" ] False "bytea"
+>        , CatCreateFunction "regclass" [ "text" ] False "regclass"
+>        , CatCreateFunction "regclassin" [ "cstring" ] False "regclass"
+>        , CatCreateFunction "regclassout" [ "regclass" ] False "cstring"
+>        , CatCreateFunction "regclassrecv" [ "internal" ] False "regclass"
+>        , CatCreateFunction "regclasssend" [ "regclass" ] False "bytea"
+>        , CatCreateFunction "regconfigin" [ "cstring" ] False "regconfig"
+>        , CatCreateFunction "regconfigout" [ "regconfig" ] False "cstring"
+>        , CatCreateFunction
+>            "regconfigrecv" [ "internal" ] False "regconfig"
+>        , CatCreateFunction "regconfigsend" [ "regconfig" ] False "bytea"
+>        , CatCreateFunction
+>            "regdictionaryin" [ "cstring" ] False "regdictionary"
+>        , CatCreateFunction
+>            "regdictionaryout" [ "regdictionary" ] False "cstring"
+>        , CatCreateFunction
+>            "regdictionaryrecv" [ "internal" ] False "regdictionary"
+>        , CatCreateFunction
+>            "regdictionarysend" [ "regdictionary" ] False "bytea"
+>        , CatCreateFunction
+>            "regexeqjoinsel"
+>            [ "internal" , "oid" , "internal" , "internal" , "int2" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "regexeqsel"
+>            [ "internal" , "oid" , "int4" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "regexnejoinsel"
+>            [ "int2" , "internal" , "internal" , "oid" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "regexnesel"
+>            [ "internal" , "oid" , "internal" , "int4" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "regexp_matches" [ "text" , "text" ] True "_text"
+>        , CatCreateFunction
+>            "regexp_matches" [ "text" , "text" , "text" ] True "_text"
+>        , CatCreateFunction
+>            "regexp_replace" [ "text" , "text" , "text" ] False "text"
+>        , CatCreateFunction
+>            "regexp_replace" [ "text" , "text" , "text" , "text" ] False "text"
+>        , CatCreateFunction
+>            "regexp_split_to_array" [ "text" , "text" ] False "_text"
+>        , CatCreateFunction
+>            "regexp_split_to_array" [ "text" , "text" , "text" ] False "_text"
+>        , CatCreateFunction
+>            "regexp_split_to_table" [ "text" , "text" ] True "text"
+>        , CatCreateFunction
+>            "regexp_split_to_table" [ "text" , "text" , "text" ] True "text"
+>        , CatCreateFunction
+>            "regoperatorin" [ "cstring" ] False "regoperator"
+>        , CatCreateFunction
+>            "regoperatorout" [ "regoperator" ] False "cstring"
+>        , CatCreateFunction
+>            "regoperatorrecv" [ "internal" ] False "regoperator"
+>        , CatCreateFunction
+>            "regoperatorsend" [ "regoperator" ] False "bytea"
+>        , CatCreateFunction "regoperin" [ "cstring" ] False "regoper"
+>        , CatCreateFunction "regoperout" [ "regoper" ] False "cstring"
+>        , CatCreateFunction "regoperrecv" [ "internal" ] False "regoper"
+>        , CatCreateFunction "regopersend" [ "regoper" ] False "bytea"
+>        , CatCreateFunction
+>            "regprocedurein" [ "cstring" ] False "regprocedure"
+>        , CatCreateFunction
+>            "regprocedureout" [ "regprocedure" ] False "cstring"
+>        , CatCreateFunction
+>            "regprocedurerecv" [ "internal" ] False "regprocedure"
+>        , CatCreateFunction
+>            "regproceduresend" [ "regprocedure" ] False "bytea"
+>        , CatCreateFunction "regprocin" [ "cstring" ] False "regproc"
+>        , CatCreateFunction "regprocout" [ "regproc" ] False "cstring"
+>        , CatCreateFunction "regprocrecv" [ "internal" ] False "regproc"
+>        , CatCreateFunction "regprocsend" [ "regproc" ] False "bytea"
+>        , CatCreateFunction "regtypein" [ "cstring" ] False "regtype"
+>        , CatCreateFunction "regtypeout" [ "regtype" ] False "cstring"
+>        , CatCreateFunction "regtyperecv" [ "internal" ] False "regtype"
+>        , CatCreateFunction "regtypesend" [ "regtype" ] False "bytea"
+>        , CatCreateFunction "reltime" [ "interval" ] False "reltime"
+>        , CatCreateFunction
+>            "reltimeeq" [ "reltime" , "reltime" ] False "bool"
+>        , CatCreateFunction
+>            "reltimege" [ "reltime" , "reltime" ] False "bool"
+>        , CatCreateFunction
+>            "reltimegt" [ "reltime" , "reltime" ] False "bool"
+>        , CatCreateFunction "reltimein" [ "cstring" ] False "reltime"
+>        , CatCreateFunction
+>            "reltimele" [ "reltime" , "reltime" ] False "bool"
+>        , CatCreateFunction
+>            "reltimelt" [ "reltime" , "reltime" ] False "bool"
+>        , CatCreateFunction
+>            "reltimene" [ "reltime" , "reltime" ] False "bool"
+>        , CatCreateFunction "reltimeout" [ "reltime" ] False "cstring"
+>        , CatCreateFunction "reltimerecv" [ "internal" ] False "reltime"
+>        , CatCreateFunction "reltimesend" [ "reltime" ] False "bytea"
+>        , CatCreateFunction "repeat" [ "int4" , "text" ] False "text"
+>        , CatCreateFunction
+>            "replace" [ "text" , "text" , "text" ] False "text"
+>        , CatCreateFunction "reverse" [ "text" ] False "text"
+>        , CatCreateFunction "right" [ "text" , "int4" ] False "text"
+>        , CatCreateFunction "round" [ "float8" ] False "float8"
+>        , CatCreateFunction "round" [ "int4" , "numeric" ] False "numeric"
+>        , CatCreateFunction "round" [ "numeric" ] False "numeric"
+>        , CatCreateFunction "row_to_json" [ "record" ] False "json"
+>        , CatCreateFunction
+>            "row_to_json" [ "record" , "bool" ] False "json"
+>        , CatCreateFunction
+>            "rpad" [ "text" , "int4" , "text" ] False "text"
+>        , CatCreateFunction "rpad" [ "int4" , "text" ] False "text"
+>        , CatCreateFunction "rtrim" [ "text" , "text" ] False "text"
+>        , CatCreateFunction "rtrim" [ "text" ] False "text"
+>        , CatCreateFunction
+>            "scalargtjoinsel"
+>            [ "internal" , "internal" , "internal" , "int2" , "oid" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "scalargtsel"
+>            [ "internal" , "internal" , "int4" , "oid" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "scalarltjoinsel"
+>            [ "internal" , "internal" , "internal" , "int2" , "oid" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "scalarltsel"
+>            [ "oid" , "internal" , "int4" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "schema_to_xml" [ "bool" , "text" , "bool" , "name" ] False "xml"
+>        , CatCreateFunction
+>            "schema_to_xml_and_xmlschema"
+>            [ "name" , "bool" , "text" , "bool" ]
+>            False
+>            "xml"
+>        , CatCreateFunction
+>            "schema_to_xmlschema"
+>            [ "bool" , "bool" , "name" , "text" ]
+>            False
+>            "xml"
+>        , CatCreateFunction
+>            "set_bit" [ "int4" , "bytea" , "int4" ] False "bytea"
+>        , CatCreateFunction
+>            "set_bit" [ "int4" , "bit" , "int4" ] False "bit"
+>        , CatCreateFunction
+>            "set_byte" [ "int4" , "bytea" , "int4" ] False "bytea"
+>        , CatCreateFunction
+>            "set_config" [ "text" , "text" , "bool" ] False "text"
+>        , CatCreateFunction "set_masklen" [ "int4" , "inet" ] False "inet"
+>        , CatCreateFunction "set_masklen" [ "int4" , "cidr" ] False "cidr"
+>        , CatCreateFunction "setseed" [ "float8" ] False "void"
+>        , CatCreateFunction "setval" [ "regclass" , "int8" ] False "int8"
+>        , CatCreateFunction
+>            "setval" [ "regclass" , "int8" , "bool" ] False "int8"
+>        , CatCreateFunction
+>            "setweight" [ "tsvector" , "char" ] False "tsvector"
+>        , CatCreateFunction "shell_in" [ "cstring" ] False "opaque"
+>        , CatCreateFunction "shell_out" [ "opaque" ] False "cstring"
+>        , CatCreateFunction
+>            "shift_jis_2004_to_euc_jis_2004"
+>            [ "int4" , "cstring" , "int4" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "shift_jis_2004_to_utf8"
+>            [ "int4" , "int4" , "internal" , "cstring" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "shobj_description" [ "name" , "oid" ] False "text"
+>        , CatCreateFunction "sign" [ "numeric" ] False "numeric"
+>        , CatCreateFunction "sign" [ "float8" ] False "float8"
+>        , CatCreateFunction
+>            "similar_escape" [ "text" , "text" ] False "text"
+>        , CatCreateFunction "sin" [ "float8" ] False "float8"
+>        , CatCreateFunction
+>            "sjis_to_euc_jp"
+>            [ "int4" , "int4" , "int4" , "internal" , "cstring" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "sjis_to_mic"
+>            [ "internal" , "int4" , "cstring" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "sjis_to_utf8"
+>            [ "int4" , "int4" , "cstring" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction "slope" [ "point" , "point" ] False "float8"
+>        , CatCreateFunction "smgreq" [ "smgr" , "smgr" ] False "bool"
+>        , CatCreateFunction "smgrin" [ "cstring" ] False "smgr"
+>        , CatCreateFunction "smgrne" [ "smgr" , "smgr" ] False "bool"
+>        , CatCreateFunction "smgrout" [ "smgr" ] False "cstring"
+>        , CatCreateFunction
+>            "spg_kd_choose" [ "internal" , "internal" ] False "void"
+>        , CatCreateFunction
+>            "spg_kd_config" [ "internal" , "internal" ] False "void"
+>        , CatCreateFunction
+>            "spg_kd_inner_consistent" [ "internal" , "internal" ] False "void"
+>        , CatCreateFunction
+>            "spg_kd_picksplit" [ "internal" , "internal" ] False "void"
+>        , CatCreateFunction
+>            "spg_quad_choose" [ "internal" , "internal" ] False "void"
+>        , CatCreateFunction
+>            "spg_quad_config" [ "internal" , "internal" ] False "void"
+>        , CatCreateFunction
+>            "spg_quad_inner_consistent"
+>            [ "internal" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "spg_quad_leaf_consistent" [ "internal" , "internal" ] False "bool"
+>        , CatCreateFunction
+>            "spg_quad_picksplit" [ "internal" , "internal" ] False "void"
+>        , CatCreateFunction
+>            "spg_range_quad_choose" [ "internal" , "internal" ] False "void"
+>        , CatCreateFunction
+>            "spg_range_quad_config" [ "internal" , "internal" ] False "void"
+>        , CatCreateFunction
+>            "spg_range_quad_inner_consistent"
+>            [ "internal" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "spg_range_quad_leaf_consistent"
+>            [ "internal" , "internal" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "spg_range_quad_picksplit" [ "internal" , "internal" ] False "void"
+>        , CatCreateFunction
+>            "spg_text_choose" [ "internal" , "internal" ] False "void"
+>        , CatCreateFunction
+>            "spg_text_config" [ "internal" , "internal" ] False "void"
+>        , CatCreateFunction
+>            "spg_text_inner_consistent"
+>            [ "internal" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "spg_text_leaf_consistent" [ "internal" , "internal" ] False "bool"
+>        , CatCreateFunction
+>            "spg_text_picksplit" [ "internal" , "internal" ] False "void"
+>        , CatCreateFunction
+>            "spgbeginscan"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "spgbuild"
+>            [ "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction "spgbuildempty" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "spgbulkdelete"
+>            [ "internal" , "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction "spgcanreturn" [ "internal" ] False "bool"
+>        , CatCreateFunction
+>            "spgcostestimate"
+>            [ "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "void"
+>        , CatCreateFunction "spgendscan" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "spggetbitmap" [ "internal" , "internal" ] False "int8"
+>        , CatCreateFunction
+>            "spggettuple" [ "internal" , "internal" ] False "bool"
+>        , CatCreateFunction
+>            "spginsert"
+>            [ "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            , "internal"
+>            ]
+>            False
+>            "bool"
+>        , CatCreateFunction "spgmarkpos" [ "internal" ] False "void"
+>        , CatCreateFunction "spgoptions" [ "bool" , "_text" ] False "bytea"
+>        , CatCreateFunction
+>            "spgrescan"
+>            [ "internal" , "internal" , "internal" , "internal" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction "spgrestrpos" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "spgvacuumcleanup" [ "internal" , "internal" ] False "internal"
+>        , CatCreateFunction
+>            "split_part" [ "text" , "int4" , "text" ] False "text"
+>        , CatCreateFunction "sqrt" [ "float8" ] False "float8"
+>        , CatCreateFunction "sqrt" [ "numeric" ] False "numeric"
+>        , CatCreateFunction
+>            "string_agg_finalfn" [ "internal" ] False "text"
+>        , CatCreateFunction
+>            "string_agg_transfn"
+>            [ "internal" , "text" , "text" ]
+>            False
+>            "internal"
+>        , CatCreateFunction
+>            "string_to_array" [ "text" , "text" , "text" ] False "_text"
+>        , CatCreateFunction
+>            "string_to_array" [ "text" , "text" ] False "_text"
+>        , CatCreateFunction "strip" [ "tsvector" ] False "tsvector"
+>        , CatCreateFunction "strpos" [ "text" , "text" ] False "int4"
+>        , CatCreateFunction
+>            "substr" [ "text" , "int4" , "int4" ] False "text"
+>        , CatCreateFunction "substr" [ "text" , "int4" ] False "text"
+>        , CatCreateFunction
+>            "substr" [ "int4" , "bytea" , "int4" ] False "bytea"
+>        , CatCreateFunction "substr" [ "int4" , "bytea" ] False "bytea"
+>        , CatCreateFunction
+>            "substring" [ "text" , "int4" , "int4" ] False "text"
+>        , CatCreateFunction "substring" [ "int4" , "text" ] False "text"
+>        , CatCreateFunction
+>            "substring" [ "bit" , "int4" , "int4" ] False "bit"
+>        , CatCreateFunction "substring" [ "int4" , "bit" ] False "bit"
+>        , CatCreateFunction
+>            "substring" [ "int4" , "int4" , "bytea" ] False "bytea"
+>        , CatCreateFunction "substring" [ "bytea" , "int4" ] False "bytea"
+>        , CatCreateFunction "substring" [ "text" , "text" ] False "text"
+>        , CatCreateFunction
+>            "substring" [ "text" , "text" , "text" ] False "text"
+>        , CatCreateFunction
+>            "table_to_xml"
+>            [ "regclass" , "bool" , "bool" , "text" ]
+>            False
+>            "xml"
+>        , CatCreateFunction
+>            "table_to_xml_and_xmlschema"
+>            [ "bool" , "text" , "bool" , "regclass" ]
+>            False
+>            "xml"
+>        , CatCreateFunction
+>            "table_to_xmlschema"
+>            [ "text" , "regclass" , "bool" , "bool" ]
+>            False
+>            "xml"
+>        , CatCreateFunction "tan" [ "float8" ] False "float8"
+>        , CatCreateFunction "text" [ "bpchar" ] False "text"
+>        , CatCreateFunction "text" [ "name" ] False "text"
+>        , CatCreateFunction "text" [ "inet" ] False "text"
+>        , CatCreateFunction "text" [ "char" ] False "text"
+>        , CatCreateFunction "text" [ "xml" ] False "text"
+>        , CatCreateFunction "text" [ "bool" ] False "text"
+>        , CatCreateFunction "text_ge" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction "text_gt" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction "text_larger" [ "text" , "text" ] False "text"
+>        , CatCreateFunction "text_le" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction "text_lt" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "text_pattern_ge" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "text_pattern_gt" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "text_pattern_le" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "text_pattern_lt" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction "text_smaller" [ "text" , "text" ] False "text"
+>        , CatCreateFunction
+>            "textanycat" [ "anynonarray" , "text" ] False "text"
+>        , CatCreateFunction "textcat" [ "text" , "text" ] False "text"
+>        , CatCreateFunction "texteq" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction "texticlike" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction "texticnlike" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "texticregexeq" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "texticregexne" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction "textin" [ "cstring" ] False "text"
+>        , CatCreateFunction "textlen" [ "text" ] False "int4"
+>        , CatCreateFunction "textlike" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction "textne" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction "textnlike" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction "textout" [ "text" ] False "cstring"
+>        , CatCreateFunction "textrecv" [ "internal" ] False "text"
+>        , CatCreateFunction "textregexeq" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction "textregexne" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction "textsend" [ "text" ] False "bytea"
+>        , CatCreateFunction
+>            "thesaurus_init" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "thesaurus_lexize"
+>            [ "internal" , "internal" , "internal" , "internal" ]
+>            False
+>            "internal"
+>        , CatCreateFunction "tideq" [ "tid" , "tid" ] False "bool"
+>        , CatCreateFunction "tidge" [ "tid" , "tid" ] False "bool"
+>        , CatCreateFunction "tidgt" [ "tid" , "tid" ] False "bool"
+>        , CatCreateFunction "tidin" [ "cstring" ] False "tid"
+>        , CatCreateFunction "tidlarger" [ "tid" , "tid" ] False "tid"
+>        , CatCreateFunction "tidle" [ "tid" , "tid" ] False "bool"
+>        , CatCreateFunction "tidlt" [ "tid" , "tid" ] False "bool"
+>        , CatCreateFunction "tidne" [ "tid" , "tid" ] False "bool"
+>        , CatCreateFunction "tidout" [ "tid" ] False "cstring"
+>        , CatCreateFunction "tidrecv" [ "internal" ] False "tid"
+>        , CatCreateFunction "tidsend" [ "tid" ] False "bytea"
+>        , CatCreateFunction "tidsmaller" [ "tid" , "tid" ] False "tid"
+>        , CatCreateFunction "time" [ "timestamp" ] False "time"
+>        , CatCreateFunction "time" [ "abstime" ] False "time"
+>        , CatCreateFunction "time" [ "interval" ] False "time"
+>        , CatCreateFunction "time" [ "time" , "int4" ] False "time"
+>        , CatCreateFunction "time" [ "timestamptz" ] False "time"
+>        , CatCreateFunction "time" [ "timetz" ] False "time"
+>        , CatCreateFunction "time_cmp" [ "time" , "time" ] False "int4"
+>        , CatCreateFunction "time_eq" [ "time" , "time" ] False "bool"
+>        , CatCreateFunction "time_ge" [ "time" , "time" ] False "bool"
+>        , CatCreateFunction "time_gt" [ "time" , "time" ] False "bool"
+>        , CatCreateFunction "time_hash" [ "time" ] False "int4"
+>        , CatCreateFunction
+>            "time_in" [ "int4" , "cstring" , "oid" ] False "time"
+>        , CatCreateFunction "time_larger" [ "time" , "time" ] False "time"
+>        , CatCreateFunction "time_le" [ "time" , "time" ] False "bool"
+>        , CatCreateFunction "time_lt" [ "time" , "time" ] False "bool"
+>        , CatCreateFunction
+>            "time_mi_interval" [ "interval" , "time" ] False "time"
+>        , CatCreateFunction
+>            "time_mi_time" [ "time" , "time" ] False "interval"
+>        , CatCreateFunction "time_ne" [ "time" , "time" ] False "bool"
+>        , CatCreateFunction "time_out" [ "time" ] False "cstring"
+>        , CatCreateFunction
+>            "time_pl_interval" [ "time" , "interval" ] False "time"
+>        , CatCreateFunction
+>            "time_recv" [ "internal" , "oid" , "int4" ] False "time"
+>        , CatCreateFunction "time_send" [ "time" ] False "bytea"
+>        , CatCreateFunction "time_smaller" [ "time" , "time" ] False "time"
+>        , CatCreateFunction
+>            "time_transform" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "timedate_pl" [ "time" , "date" ] False "timestamp"
+>        , CatCreateFunction
+>            "timemi" [ "abstime" , "reltime" ] False "abstime"
+>        , CatCreateFunction
+>            "timepl" [ "abstime" , "reltime" ] False "abstime"
+>        , CatCreateFunction
+>            "timestamp" [ "timestamp" , "int4" ] False "timestamp"
+>        , CatCreateFunction "timestamp" [ "abstime" ] False "timestamp"
+>        , CatCreateFunction "timestamp" [ "date" ] False "timestamp"
+>        , CatCreateFunction
+>            "timestamp" [ "date" , "time" ] False "timestamp"
+>        , CatCreateFunction "timestamp" [ "timestamptz" ] False "timestamp"
+>        , CatCreateFunction
+>            "timestamp_cmp" [ "timestamp" , "timestamp" ] False "int4"
+>        , CatCreateFunction
+>            "timestamp_cmp_date" [ "date" , "timestamp" ] False "int4"
+>        , CatCreateFunction
+>            "timestamp_cmp_timestamptz"
+>            [ "timestamptz" , "timestamp" ]
+>            False
+>            "int4"
+>        , CatCreateFunction
+>            "timestamp_eq" [ "timestamp" , "timestamp" ] False "bool"
+>        , CatCreateFunction
+>            "timestamp_eq_date" [ "timestamp" , "date" ] False "bool"
+>        , CatCreateFunction
+>            "timestamp_eq_timestamptz"
+>            [ "timestamptz" , "timestamp" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "timestamp_ge" [ "timestamp" , "timestamp" ] False "bool"
+>        , CatCreateFunction
+>            "timestamp_ge_date" [ "timestamp" , "date" ] False "bool"
+>        , CatCreateFunction
+>            "timestamp_ge_timestamptz"
+>            [ "timestamptz" , "timestamp" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "timestamp_gt" [ "timestamp" , "timestamp" ] False "bool"
+>        , CatCreateFunction
+>            "timestamp_gt_date" [ "date" , "timestamp" ] False "bool"
+>        , CatCreateFunction
+>            "timestamp_gt_timestamptz"
+>            [ "timestamptz" , "timestamp" ]
+>            False
+>            "bool"
+>        , CatCreateFunction "timestamp_hash" [ "timestamp" ] False "int4"
+>        , CatCreateFunction
+>            "timestamp_in" [ "cstring" , "oid" , "int4" ] False "timestamp"
+>        , CatCreateFunction
+>            "timestamp_larger" [ "timestamp" , "timestamp" ] False "timestamp"
+>        , CatCreateFunction
+>            "timestamp_le" [ "timestamp" , "timestamp" ] False "bool"
+>        , CatCreateFunction
+>            "timestamp_le_date" [ "timestamp" , "date" ] False "bool"
+>        , CatCreateFunction
+>            "timestamp_le_timestamptz"
+>            [ "timestamp" , "timestamptz" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "timestamp_lt" [ "timestamp" , "timestamp" ] False "bool"
+>        , CatCreateFunction
+>            "timestamp_lt_date" [ "date" , "timestamp" ] False "bool"
+>        , CatCreateFunction
+>            "timestamp_lt_timestamptz"
+>            [ "timestamp" , "timestamptz" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "timestamp_mi" [ "timestamp" , "timestamp" ] False "interval"
+>        , CatCreateFunction
+>            "timestamp_mi_interval"
+>            [ "timestamp" , "interval" ]
+>            False
+>            "timestamp"
+>        , CatCreateFunction
+>            "timestamp_ne" [ "timestamp" , "timestamp" ] False "bool"
+>        , CatCreateFunction
+>            "timestamp_ne_date" [ "timestamp" , "date" ] False "bool"
+>        , CatCreateFunction
+>            "timestamp_ne_timestamptz"
+>            [ "timestamp" , "timestamptz" ]
+>            False
+>            "bool"
+>        , CatCreateFunction "timestamp_out" [ "timestamp" ] False "cstring"
+>        , CatCreateFunction
+>            "timestamp_pl_interval"
+>            [ "timestamp" , "interval" ]
+>            False
+>            "timestamp"
+>        , CatCreateFunction
+>            "timestamp_recv" [ "internal" , "int4" , "oid" ] False "timestamp"
+>        , CatCreateFunction "timestamp_send" [ "timestamp" ] False "bytea"
+>        , CatCreateFunction
+>            "timestamp_smaller" [ "timestamp" , "timestamp" ] False "timestamp"
+>        , CatCreateFunction
+>            "timestamp_sortsupport" [ "internal" ] False "void"
+>        , CatCreateFunction
+>            "timestamp_transform" [ "internal" ] False "internal"
+>        , CatCreateFunction "timestamptypmodin" [ "_cstring" ] False "int4"
+>        , CatCreateFunction "timestamptypmodout" [ "int4" ] False "cstring"
+>        , CatCreateFunction "timestamptz" [ "abstime" ] False "timestamptz"
+>        , CatCreateFunction "timestamptz" [ "date" ] False "timestamptz"
+>        , CatCreateFunction
+>            "timestamptz" [ "time" , "date" ] False "timestamptz"
+>        , CatCreateFunction
+>            "timestamptz" [ "timetz" , "date" ] False "timestamptz"
+>        , CatCreateFunction
+>            "timestamptz" [ "timestamptz" , "int4" ] False "timestamptz"
+>        , CatCreateFunction
+>            "timestamptz" [ "timestamp" ] False "timestamptz"
+>        , CatCreateFunction
+>            "timestamptz_cmp" [ "timestamptz" , "timestamptz" ] False "int4"
+>        , CatCreateFunction
+>            "timestamptz_cmp_date" [ "date" , "timestamptz" ] False "int4"
+>        , CatCreateFunction
+>            "timestamptz_cmp_timestamp"
+>            [ "timestamp" , "timestamptz" ]
+>            False
+>            "int4"
+>        , CatCreateFunction
+>            "timestamptz_eq" [ "timestamptz" , "timestamptz" ] False "bool"
+>        , CatCreateFunction
+>            "timestamptz_eq_date" [ "timestamptz" , "date" ] False "bool"
+>        , CatCreateFunction
+>            "timestamptz_eq_timestamp"
+>            [ "timestamp" , "timestamptz" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "timestamptz_ge" [ "timestamptz" , "timestamptz" ] False "bool"
+>        , CatCreateFunction
+>            "timestamptz_ge_date" [ "timestamptz" , "date" ] False "bool"
+>        , CatCreateFunction
+>            "timestamptz_ge_timestamp"
+>            [ "timestamptz" , "timestamp" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "timestamptz_gt" [ "timestamptz" , "timestamptz" ] False "bool"
+>        , CatCreateFunction
+>            "timestamptz_gt_date" [ "timestamptz" , "date" ] False "bool"
+>        , CatCreateFunction
+>            "timestamptz_gt_timestamp"
+>            [ "timestamptz" , "timestamp" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "timestamptz_in" [ "oid" , "cstring" , "int4" ] False "timestamptz"
+>        , CatCreateFunction
+>            "timestamptz_larger"
+>            [ "timestamptz" , "timestamptz" ]
+>            False
+>            "timestamptz"
+>        , CatCreateFunction
+>            "timestamptz_le" [ "timestamptz" , "timestamptz" ] False "bool"
+>        , CatCreateFunction
+>            "timestamptz_le_date" [ "date" , "timestamptz" ] False "bool"
+>        , CatCreateFunction
+>            "timestamptz_le_timestamp"
+>            [ "timestamp" , "timestamptz" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "timestamptz_lt" [ "timestamptz" , "timestamptz" ] False "bool"
+>        , CatCreateFunction
+>            "timestamptz_lt_date" [ "timestamptz" , "date" ] False "bool"
+>        , CatCreateFunction
+>            "timestamptz_lt_timestamp"
+>            [ "timestamptz" , "timestamp" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "timestamptz_mi" [ "timestamptz" , "timestamptz" ] False "interval"
+>        , CatCreateFunction
+>            "timestamptz_mi_interval"
+>            [ "timestamptz" , "interval" ]
+>            False
+>            "timestamptz"
+>        , CatCreateFunction
+>            "timestamptz_ne" [ "timestamptz" , "timestamptz" ] False "bool"
+>        , CatCreateFunction
+>            "timestamptz_ne_date" [ "date" , "timestamptz" ] False "bool"
+>        , CatCreateFunction
+>            "timestamptz_ne_timestamp"
+>            [ "timestamptz" , "timestamp" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "timestamptz_out" [ "timestamptz" ] False "cstring"
+>        , CatCreateFunction
+>            "timestamptz_pl_interval"
+>            [ "timestamptz" , "interval" ]
+>            False
+>            "timestamptz"
+>        , CatCreateFunction
+>            "timestamptz_recv"
+>            [ "oid" , "int4" , "internal" ]
+>            False
+>            "timestamptz"
+>        , CatCreateFunction
+>            "timestamptz_send" [ "timestamptz" ] False "bytea"
+>        , CatCreateFunction
+>            "timestamptz_smaller"
+>            [ "timestamptz" , "timestamptz" ]
+>            False
+>            "timestamptz"
+>        , CatCreateFunction
+>            "timestamptztypmodin" [ "_cstring" ] False "int4"
+>        , CatCreateFunction
+>            "timestamptztypmodout" [ "int4" ] False "cstring"
+>        , CatCreateFunction "timetypmodin" [ "_cstring" ] False "int4"
+>        , CatCreateFunction "timetypmodout" [ "int4" ] False "cstring"
+>        , CatCreateFunction "timetz" [ "timestamptz" ] False "timetz"
+>        , CatCreateFunction "timetz" [ "int4" , "timetz" ] False "timetz"
+>        , CatCreateFunction "timetz" [ "time" ] False "timetz"
+>        , CatCreateFunction
+>            "timetz_cmp" [ "timetz" , "timetz" ] False "int4"
+>        , CatCreateFunction
+>            "timetz_eq" [ "timetz" , "timetz" ] False "bool"
+>        , CatCreateFunction
+>            "timetz_ge" [ "timetz" , "timetz" ] False "bool"
+>        , CatCreateFunction
+>            "timetz_gt" [ "timetz" , "timetz" ] False "bool"
+>        , CatCreateFunction "timetz_hash" [ "timetz" ] False "int4"
+>        , CatCreateFunction
+>            "timetz_in" [ "int4" , "oid" , "cstring" ] False "timetz"
+>        , CatCreateFunction
+>            "timetz_larger" [ "timetz" , "timetz" ] False "timetz"
+>        , CatCreateFunction
+>            "timetz_le" [ "timetz" , "timetz" ] False "bool"
+>        , CatCreateFunction
+>            "timetz_lt" [ "timetz" , "timetz" ] False "bool"
+>        , CatCreateFunction
+>            "timetz_mi_interval" [ "interval" , "timetz" ] False "timetz"
+>        , CatCreateFunction
+>            "timetz_ne" [ "timetz" , "timetz" ] False "bool"
+>        , CatCreateFunction "timetz_out" [ "timetz" ] False "cstring"
+>        , CatCreateFunction
+>            "timetz_pl_interval" [ "interval" , "timetz" ] False "timetz"
+>        , CatCreateFunction
+>            "timetz_recv" [ "oid" , "internal" , "int4" ] False "timetz"
+>        , CatCreateFunction "timetz_send" [ "timetz" ] False "bytea"
+>        , CatCreateFunction
+>            "timetz_smaller" [ "timetz" , "timetz" ] False "timetz"
+>        , CatCreateFunction
+>            "timetzdate_pl" [ "date" , "timetz" ] False "timestamptz"
+>        , CatCreateFunction "timetztypmodin" [ "_cstring" ] False "int4"
+>        , CatCreateFunction "timetztypmodout" [ "int4" ] False "cstring"
+>        , CatCreateFunction
+>            "timezone" [ "interval" , "timestamptz" ] False "timestamp"
+>        , CatCreateFunction
+>            "timezone" [ "text" , "timestamptz" ] False "timestamp"
+>        , CatCreateFunction "timezone" [ "text" , "timetz" ] False "timetz"
+>        , CatCreateFunction
+>            "timezone" [ "interval" , "timetz" ] False "timetz"
+>        , CatCreateFunction
+>            "timezone" [ "text" , "timestamp" ] False "timestamptz"
+>        , CatCreateFunction
+>            "timezone" [ "timestamp" , "interval" ] False "timestamptz"
+>        , CatCreateFunction
+>            "tinterval" [ "abstime" , "abstime" ] False "tinterval"
+>        , CatCreateFunction
+>            "tintervalct" [ "tinterval" , "tinterval" ] False "bool"
+>        , CatCreateFunction "tintervalend" [ "tinterval" ] False "abstime"
+>        , CatCreateFunction
+>            "tintervaleq" [ "tinterval" , "tinterval" ] False "bool"
+>        , CatCreateFunction
+>            "tintervalge" [ "tinterval" , "tinterval" ] False "bool"
+>        , CatCreateFunction
+>            "tintervalgt" [ "tinterval" , "tinterval" ] False "bool"
+>        , CatCreateFunction "tintervalin" [ "cstring" ] False "tinterval"
+>        , CatCreateFunction
+>            "tintervalle" [ "tinterval" , "tinterval" ] False "bool"
+>        , CatCreateFunction
+>            "tintervalleneq" [ "reltime" , "tinterval" ] False "bool"
+>        , CatCreateFunction
+>            "tintervallenge" [ "reltime" , "tinterval" ] False "bool"
+>        , CatCreateFunction
+>            "tintervallengt" [ "reltime" , "tinterval" ] False "bool"
+>        , CatCreateFunction
+>            "tintervallenle" [ "tinterval" , "reltime" ] False "bool"
+>        , CatCreateFunction
+>            "tintervallenlt" [ "tinterval" , "reltime" ] False "bool"
+>        , CatCreateFunction
+>            "tintervallenne" [ "reltime" , "tinterval" ] False "bool"
+>        , CatCreateFunction
+>            "tintervallt" [ "tinterval" , "tinterval" ] False "bool"
+>        , CatCreateFunction
+>            "tintervalne" [ "tinterval" , "tinterval" ] False "bool"
+>        , CatCreateFunction "tintervalout" [ "tinterval" ] False "cstring"
+>        , CatCreateFunction
+>            "tintervalov" [ "tinterval" , "tinterval" ] False "bool"
+>        , CatCreateFunction
+>            "tintervalrecv" [ "internal" ] False "tinterval"
+>        , CatCreateFunction "tintervalrel" [ "tinterval" ] False "reltime"
+>        , CatCreateFunction
+>            "tintervalsame" [ "tinterval" , "tinterval" ] False "bool"
+>        , CatCreateFunction "tintervalsend" [ "tinterval" ] False "bytea"
+>        , CatCreateFunction
+>            "tintervalstart" [ "tinterval" ] False "abstime"
+>        , CatCreateFunction "to_ascii" [ "text" ] False "text"
+>        , CatCreateFunction "to_ascii" [ "text" , "int4" ] False "text"
+>        , CatCreateFunction "to_ascii" [ "text" , "name" ] False "text"
+>        , CatCreateFunction "to_char" [ "text" , "interval" ] False "text"
+>        , CatCreateFunction
+>            "to_char" [ "timestamptz" , "text" ] False "text"
+>        , CatCreateFunction "to_char" [ "text" , "numeric" ] False "text"
+>        , CatCreateFunction "to_char" [ "text" , "int4" ] False "text"
+>        , CatCreateFunction "to_char" [ "text" , "int8" ] False "text"
+>        , CatCreateFunction "to_char" [ "float4" , "text" ] False "text"
+>        , CatCreateFunction "to_char" [ "text" , "float8" ] False "text"
+>        , CatCreateFunction "to_char" [ "timestamp" , "text" ] False "text"
+>        , CatCreateFunction "to_date" [ "text" , "text" ] False "date"
+>        , CatCreateFunction "to_hex" [ "int4" ] False "text"
+>        , CatCreateFunction "to_hex" [ "int8" ] False "text"
+>        , CatCreateFunction "to_json" [ "anyelement" ] False "json"
+>        , CatCreateFunction "to_number" [ "text" , "text" ] False "numeric"
+>        , CatCreateFunction "to_regclass" [ "cstring" ] False "regclass"
+>        , CatCreateFunction "to_regoper" [ "cstring" ] False "regoper"
+>        , CatCreateFunction
+>            "to_regoperator" [ "cstring" ] False "regoperator"
+>        , CatCreateFunction "to_regproc" [ "cstring" ] False "regproc"
+>        , CatCreateFunction
+>            "to_regprocedure" [ "cstring" ] False "regprocedure"
+>        , CatCreateFunction "to_regtype" [ "cstring" ] False "regtype"
+>        , CatCreateFunction "to_timestamp" [ "float8" ] False "timestamptz"
+>        , CatCreateFunction
+>            "to_timestamp" [ "text" , "text" ] False "timestamptz"
+>        , CatCreateFunction
+>            "to_tsquery" [ "regconfig" , "text" ] False "tsquery"
+>        , CatCreateFunction "to_tsquery" [ "text" ] False "tsquery"
+>        , CatCreateFunction
+>            "to_tsvector" [ "regconfig" , "text" ] False "tsvector"
+>        , CatCreateFunction "to_tsvector" [ "text" ] False "tsvector"
+>        , CatCreateFunction
+>            "translate" [ "text" , "text" , "text" ] False "text"
+>        , CatCreateFunction "trigger_in" [ "cstring" ] False "trigger"
+>        , CatCreateFunction "trigger_out" [ "trigger" ] False "cstring"
+>        , CatCreateFunction "trunc" [ "macaddr" ] False "macaddr"
+>        , CatCreateFunction "trunc" [ "float8" ] False "float8"
+>        , CatCreateFunction "trunc" [ "int4" , "numeric" ] False "numeric"
+>        , CatCreateFunction "trunc" [ "numeric" ] False "numeric"
+>        , CatCreateFunction
+>            "ts_debug" [ "text" , "regconfig" ] True "record"
+>        , CatCreateFunction "ts_debug" [ "text" ] True "record"
+>        , CatCreateFunction
+>            "ts_headline"
+>            [ "text" , "tsquery" , "text" , "regconfig" ]
+>            False
+>            "text"
+>        , CatCreateFunction
+>            "ts_headline" [ "text" , "regconfig" , "tsquery" ] False "text"
+>        , CatCreateFunction
+>            "ts_headline" [ "text" , "text" , "tsquery" ] False "text"
+>        , CatCreateFunction
+>            "ts_headline" [ "text" , "tsquery" ] False "text"
+>        , CatCreateFunction
+>            "ts_lexize" [ "regdictionary" , "text" ] False "_text"
+>        , CatCreateFunction
+>            "ts_match_qv" [ "tsquery" , "tsvector" ] False "bool"
+>        , CatCreateFunction
+>            "ts_match_tq" [ "tsquery" , "text" ] False "bool"
+>        , CatCreateFunction "ts_match_tt" [ "text" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "ts_match_vq" [ "tsquery" , "tsvector" ] False "bool"
+>        , CatCreateFunction "ts_parse" [ "oid" , "text" ] True "record"
+>        , CatCreateFunction "ts_parse" [ "text" , "text" ] True "record"
+>        , CatCreateFunction
+>            "ts_rank"
+>            [ "int4" , "_float4" , "tsvector" , "tsquery" ]
+>            False
+>            "float4"
+>        , CatCreateFunction
+>            "ts_rank" [ "tsvector" , "tsquery" , "_float4" ] False "float4"
+>        , CatCreateFunction
+>            "ts_rank" [ "tsquery" , "int4" , "tsvector" ] False "float4"
+>        , CatCreateFunction
+>            "ts_rank" [ "tsvector" , "tsquery" ] False "float4"
+>        , CatCreateFunction
+>            "ts_rank_cd"
+>            [ "tsvector" , "_float4" , "tsquery" , "int4" ]
+>            False
+>            "float4"
+>        , CatCreateFunction
+>            "ts_rank_cd" [ "_float4" , "tsvector" , "tsquery" ] False "float4"
+>        , CatCreateFunction
+>            "ts_rank_cd" [ "tsquery" , "tsvector" , "int4" ] False "float4"
+>        , CatCreateFunction
+>            "ts_rank_cd" [ "tsvector" , "tsquery" ] False "float4"
+>        , CatCreateFunction
+>            "ts_rewrite" [ "tsquery" , "tsquery" , "tsquery" ] False "tsquery"
+>        , CatCreateFunction
+>            "ts_rewrite" [ "text" , "tsquery" ] False "tsquery"
+>        , CatCreateFunction "ts_stat" [ "text" ] True "record"
+>        , CatCreateFunction "ts_stat" [ "text" , "text" ] True "record"
+>        , CatCreateFunction "ts_token_type" [ "oid" ] True "record"
+>        , CatCreateFunction "ts_token_type" [ "text" ] True "record"
+>        , CatCreateFunction "ts_typanalyze" [ "internal" ] False "bool"
+>        , CatCreateFunction
+>            "tsmatchjoinsel"
+>            [ "oid" , "internal" , "internal" , "int2" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "tsmatchsel"
+>            [ "int4" , "internal" , "oid" , "internal" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "tsq_mcontained" [ "tsquery" , "tsquery" ] False "bool"
+>        , CatCreateFunction
+>            "tsq_mcontains" [ "tsquery" , "tsquery" ] False "bool"
+>        , CatCreateFunction
+>            "tsquery_and" [ "tsquery" , "tsquery" ] False "tsquery"
+>        , CatCreateFunction
+>            "tsquery_cmp" [ "tsquery" , "tsquery" ] False "int4"
+>        , CatCreateFunction
+>            "tsquery_eq" [ "tsquery" , "tsquery" ] False "bool"
+>        , CatCreateFunction
+>            "tsquery_ge" [ "tsquery" , "tsquery" ] False "bool"
+>        , CatCreateFunction
+>            "tsquery_gt" [ "tsquery" , "tsquery" ] False "bool"
+>        , CatCreateFunction
+>            "tsquery_le" [ "tsquery" , "tsquery" ] False "bool"
+>        , CatCreateFunction
+>            "tsquery_lt" [ "tsquery" , "tsquery" ] False "bool"
+>        , CatCreateFunction
+>            "tsquery_ne" [ "tsquery" , "tsquery" ] False "bool"
+>        , CatCreateFunction "tsquery_not" [ "tsquery" ] False "tsquery"
+>        , CatCreateFunction
+>            "tsquery_or" [ "tsquery" , "tsquery" ] False "tsquery"
+>        , CatCreateFunction "tsqueryin" [ "cstring" ] False "tsquery"
+>        , CatCreateFunction "tsqueryout" [ "tsquery" ] False "cstring"
+>        , CatCreateFunction "tsqueryrecv" [ "internal" ] False "tsquery"
+>        , CatCreateFunction "tsquerysend" [ "tsquery" ] False "bytea"
+>        , CatCreateFunction
+>            "tsrange" [ "timestamp" , "timestamp" ] False "tsrange"
+>        , CatCreateFunction
+>            "tsrange" [ "timestamp" , "timestamp" , "text" ] False "tsrange"
+>        , CatCreateFunction
+>            "tsrange_subdiff" [ "timestamp" , "timestamp" ] False "float8"
+>        , CatCreateFunction
+>            "tstzrange" [ "timestamptz" , "timestamptz" ] False "tstzrange"
+>        , CatCreateFunction
+>            "tstzrange"
+>            [ "timestamptz" , "text" , "timestamptz" ]
+>            False
+>            "tstzrange"
+>        , CatCreateFunction
+>            "tstzrange_subdiff"
+>            [ "timestamptz" , "timestamptz" ]
+>            False
+>            "float8"
+>        , CatCreateFunction
+>            "tsvector_cmp" [ "tsvector" , "tsvector" ] False "int4"
+>        , CatCreateFunction
+>            "tsvector_concat" [ "tsvector" , "tsvector" ] False "tsvector"
+>        , CatCreateFunction
+>            "tsvector_eq" [ "tsvector" , "tsvector" ] False "bool"
+>        , CatCreateFunction
+>            "tsvector_ge" [ "tsvector" , "tsvector" ] False "bool"
+>        , CatCreateFunction
+>            "tsvector_gt" [ "tsvector" , "tsvector" ] False "bool"
+>        , CatCreateFunction
+>            "tsvector_le" [ "tsvector" , "tsvector" ] False "bool"
+>        , CatCreateFunction
+>            "tsvector_lt" [ "tsvector" , "tsvector" ] False "bool"
+>        , CatCreateFunction
+>            "tsvector_ne" [ "tsvector" , "tsvector" ] False "bool"
+>        , CatCreateFunction "tsvectorin" [ "cstring" ] False "tsvector"
+>        , CatCreateFunction "tsvectorout" [ "tsvector" ] False "cstring"
+>        , CatCreateFunction "tsvectorrecv" [ "internal" ] False "tsvector"
+>        , CatCreateFunction "tsvectorsend" [ "tsvector" ] False "bytea"
+>        , CatCreateFunction
+>            "txid_snapshot_in" [ "cstring" ] False "txid_snapshot"
+>        , CatCreateFunction
+>            "txid_snapshot_out" [ "txid_snapshot" ] False "cstring"
+>        , CatCreateFunction
+>            "txid_snapshot_recv" [ "internal" ] False "txid_snapshot"
+>        , CatCreateFunction
+>            "txid_snapshot_send" [ "txid_snapshot" ] False "bytea"
+>        , CatCreateFunction
+>            "txid_snapshot_xip" [ "txid_snapshot" ] True "int8"
+>        , CatCreateFunction
+>            "txid_snapshot_xmax" [ "txid_snapshot" ] False "int8"
+>        , CatCreateFunction
+>            "txid_snapshot_xmin" [ "txid_snapshot" ] False "int8"
+>        , CatCreateFunction
+>            "txid_visible_in_snapshot"
+>            [ "int8" , "txid_snapshot" ]
+>            False
+>            "bool"
+>        , CatCreateFunction
+>            "uhc_to_utf8"
+>            [ "internal" , "int4" , "int4" , "cstring" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction "unknownin" [ "cstring" ] False "unknown"
+>        , CatCreateFunction "unknownout" [ "unknown" ] False "cstring"
+>        , CatCreateFunction "unknownrecv" [ "internal" ] False "unknown"
+>        , CatCreateFunction "unknownsend" [ "unknown" ] False "bytea"
+>        , CatCreateFunction "unnest" [ "anyarray" ] True "anyelement"
+>        , CatCreateFunction "upper" [ "text" ] False "text"
+>        , CatCreateFunction "upper" [ "anyrange" ] False "anyelement"
+>        , CatCreateFunction "upper_inc" [ "anyrange" ] False "bool"
+>        , CatCreateFunction "upper_inf" [ "anyrange" ] False "bool"
+>        , CatCreateFunction
+>            "utf8_to_ascii"
+>            [ "internal" , "int4" , "cstring" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_big5"
+>            [ "int4" , "int4" , "internal" , "int4" , "cstring" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_euc_cn"
+>            [ "cstring" , "int4" , "int4" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_euc_jis_2004"
+>            [ "int4" , "internal" , "int4" , "cstring" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_euc_jp"
+>            [ "cstring" , "int4" , "int4" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_euc_kr"
+>            [ "int4" , "int4" , "int4" , "internal" , "cstring" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_euc_tw"
+>            [ "cstring" , "int4" , "internal" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_gb18030"
+>            [ "internal" , "int4" , "int4" , "cstring" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_gbk"
+>            [ "int4" , "int4" , "int4" , "cstring" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_iso8859"
+>            [ "int4" , "int4" , "cstring" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_iso8859_1"
+>            [ "internal" , "int4" , "cstring" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_johab"
+>            [ "internal" , "cstring" , "int4" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_koi8r"
+>            [ "internal" , "int4" , "int4" , "int4" , "cstring" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_koi8u"
+>            [ "int4" , "int4" , "cstring" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_shift_jis_2004"
+>            [ "int4" , "internal" , "cstring" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_sjis"
+>            [ "cstring" , "int4" , "internal" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_uhc"
+>            [ "int4" , "int4" , "int4" , "internal" , "cstring" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "utf8_to_win"
+>            [ "internal" , "int4" , "cstring" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction "uuid_cmp" [ "uuid" , "uuid" ] False "int4"
+>        , CatCreateFunction "uuid_eq" [ "uuid" , "uuid" ] False "bool"
+>        , CatCreateFunction "uuid_ge" [ "uuid" , "uuid" ] False "bool"
+>        , CatCreateFunction "uuid_gt" [ "uuid" , "uuid" ] False "bool"
+>        , CatCreateFunction "uuid_hash" [ "uuid" ] False "int4"
+>        , CatCreateFunction "uuid_in" [ "cstring" ] False "uuid"
+>        , CatCreateFunction "uuid_le" [ "uuid" , "uuid" ] False "bool"
+>        , CatCreateFunction "uuid_lt" [ "uuid" , "uuid" ] False "bool"
+>        , CatCreateFunction "uuid_ne" [ "uuid" , "uuid" ] False "bool"
+>        , CatCreateFunction "uuid_out" [ "uuid" ] False "cstring"
+>        , CatCreateFunction "uuid_recv" [ "internal" ] False "uuid"
+>        , CatCreateFunction "uuid_send" [ "uuid" ] False "bytea"
+>        , CatCreateFunction
+>            "varbit" [ "bool" , "int4" , "varbit" ] False "varbit"
+>        , CatCreateFunction
+>            "varbit_in" [ "int4" , "oid" , "cstring" ] False "varbit"
+>        , CatCreateFunction "varbit_out" [ "varbit" ] False "cstring"
+>        , CatCreateFunction
+>            "varbit_recv" [ "internal" , "int4" , "oid" ] False "varbit"
+>        , CatCreateFunction "varbit_send" [ "varbit" ] False "bytea"
+>        , CatCreateFunction
+>            "varbit_transform" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "varbitcmp" [ "varbit" , "varbit" ] False "int4"
+>        , CatCreateFunction "varbiteq" [ "varbit" , "varbit" ] False "bool"
+>        , CatCreateFunction "varbitge" [ "varbit" , "varbit" ] False "bool"
+>        , CatCreateFunction "varbitgt" [ "varbit" , "varbit" ] False "bool"
+>        , CatCreateFunction "varbitle" [ "varbit" , "varbit" ] False "bool"
+>        , CatCreateFunction "varbitlt" [ "varbit" , "varbit" ] False "bool"
+>        , CatCreateFunction "varbitne" [ "varbit" , "varbit" ] False "bool"
+>        , CatCreateFunction "varbittypmodin" [ "_cstring" ] False "int4"
+>        , CatCreateFunction "varbittypmodout" [ "int4" ] False "cstring"
+>        , CatCreateFunction
+>            "varchar" [ "bool" , "int4" , "varchar" ] False "varchar"
+>        , CatCreateFunction "varchar" [ "name" ] False "varchar"
+>        , CatCreateFunction
+>            "varchar_transform" [ "internal" ] False "internal"
+>        , CatCreateFunction
+>            "varcharin" [ "int4" , "oid" , "cstring" ] False "varchar"
+>        , CatCreateFunction "varcharout" [ "varchar" ] False "cstring"
+>        , CatCreateFunction
+>            "varcharrecv" [ "internal" , "oid" , "int4" ] False "varchar"
+>        , CatCreateFunction "varcharsend" [ "varchar" ] False "bytea"
+>        , CatCreateFunction "varchartypmodin" [ "_cstring" ] False "int4"
+>        , CatCreateFunction "varchartypmodout" [ "int4" ] False "cstring"
+>        , CatCreateFunction "void_in" [ "cstring" ] False "void"
+>        , CatCreateFunction "void_out" [ "void" ] False "cstring"
+>        , CatCreateFunction "void_recv" [ "internal" ] False "void"
+>        , CatCreateFunction "void_send" [ "void" ] False "bytea"
+>        , CatCreateFunction "width" [ "box" ] False "float8"
+>        , CatCreateFunction
+>            "width_bucket"
+>            [ "int4" , "float8" , "float8" , "float8" ]
+>            False
+>            "int4"
+>        , CatCreateFunction
+>            "width_bucket"
+>            [ "numeric" , "numeric" , "int4" , "numeric" ]
+>            False
+>            "int4"
+>        , CatCreateFunction
+>            "win1250_to_latin2"
+>            [ "int4" , "int4" , "internal" , "cstring" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "win1250_to_mic"
+>            [ "internal" , "int4" , "int4" , "int4" , "cstring" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "win1251_to_iso"
+>            [ "cstring" , "int4" , "internal" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "win1251_to_koi8r"
+>            [ "int4" , "internal" , "cstring" , "int4" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "win1251_to_mic"
+>            [ "int4" , "int4" , "cstring" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "win1251_to_win866"
+>            [ "int4" , "int4" , "internal" , "cstring" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "win866_to_iso"
+>            [ "int4" , "int4" , "cstring" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "win866_to_koi8r"
+>            [ "cstring" , "int4" , "int4" , "internal" , "int4" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "win866_to_mic"
+>            [ "cstring" , "int4" , "int4" , "int4" , "internal" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "win866_to_win1251"
+>            [ "internal" , "int4" , "int4" , "int4" , "cstring" ]
+>            False
+>            "void"
+>        , CatCreateFunction
+>            "win_to_utf8"
+>            [ "int4" , "int4" , "internal" , "int4" , "cstring" ]
+>            False
+>            "void"
+>        , CatCreateFunction "xideq" [ "xid" , "xid" ] False "bool"
+>        , CatCreateFunction "xideqint4" [ "xid" , "int4" ] False "bool"
+>        , CatCreateFunction "xidin" [ "cstring" ] False "xid"
+>        , CatCreateFunction "xidout" [ "xid" ] False "cstring"
+>        , CatCreateFunction "xidrecv" [ "internal" ] False "xid"
+>        , CatCreateFunction "xidsend" [ "xid" ] False "bytea"
+>        , CatCreateFunction "xml" [ "text" ] False "xml"
+>        , CatCreateFunction "xml_in" [ "cstring" ] False "xml"
+>        , CatCreateFunction "xml_is_well_formed" [ "text" ] False "bool"
+>        , CatCreateFunction
+>            "xml_is_well_formed_content" [ "text" ] False "bool"
+>        , CatCreateFunction
+>            "xml_is_well_formed_document" [ "text" ] False "bool"
+>        , CatCreateFunction "xml_out" [ "xml" ] False "cstring"
+>        , CatCreateFunction "xml_recv" [ "internal" ] False "xml"
+>        , CatCreateFunction "xml_send" [ "xml" ] False "bytea"
+>        , CatCreateFunction "xmlcomment" [ "text" ] False "xml"
+>        , CatCreateFunction "xmlconcat2" [ "xml" , "xml" ] False "xml"
+>        , CatCreateFunction "xmlexists" [ "xml" , "text" ] False "bool"
+>        , CatCreateFunction "xmlvalidate" [ "xml" , "text" ] False "bool"
+>        , CatCreateFunction
+>            "xpath" [ "xml" , "text" , "_text" ] False "_xml"
+>        , CatCreateFunction "xpath" [ "text" , "xml" ] False "_xml"
+>        , CatCreateFunction
+>            "xpath_exists" [ "text" , "_text" , "xml" ] False "bool"
+>        , CatCreateFunction "xpath_exists" [ "text" , "xml" ] False "bool"
+>        , CatCreateAggregate "array_agg" [ "anyelement" ] "anyarray"
+>        , CatCreateAggregate "avg" [ "int8" ] "numeric"
+>        , CatCreateAggregate "avg" [ "int4" ] "numeric"
+>        , CatCreateAggregate "avg" [ "int2" ] "numeric"
+>        , CatCreateAggregate "avg" [ "numeric" ] "numeric"
+>        , CatCreateAggregate "avg" [ "float4" ] "float8"
+>        , CatCreateAggregate "avg" [ "float8" ] "float8"
+>        , CatCreateAggregate "avg" [ "interval" ] "interval"
+>        , CatCreateAggregate "bit_and" [ "int2" ] "int2"
+>        , CatCreateAggregate "bit_and" [ "int4" ] "int4"
+>        , CatCreateAggregate "bit_and" [ "int8" ] "int8"
+>        , CatCreateAggregate "bit_and" [ "bit" ] "bit"
+>        , CatCreateAggregate "bit_or" [ "int2" ] "int2"
+>        , CatCreateAggregate "bit_or" [ "int4" ] "int4"
+>        , CatCreateAggregate "bit_or" [ "int8" ] "int8"
+>        , CatCreateAggregate "bit_or" [ "bit" ] "bit"
+>        , CatCreateAggregate "bool_and" [ "bool" ] "bool"
+>        , CatCreateAggregate "bool_or" [ "bool" ] "bool"
+>        , CatCreateAggregate "corr" [ "float8" , "float8" ] "float8"
+>        , CatCreateAggregate "count" [ "any" ] "int8"
+>        , CatCreateAggregate "covar_pop" [ "float8" , "float8" ] "float8"
+>        , CatCreateAggregate "covar_samp" [ "float8" , "float8" ] "float8"
+>        , CatCreateAggregate "every" [ "bool" ] "bool"
+>        , CatCreateAggregate "json_agg" [ "anyelement" ] "json"
+>        , CatCreateAggregate "json_object_agg" [ "any" , "any" ] "json"
+>        , CatCreateAggregate "max" [ "anyarray" ] "anyarray"
+>        , CatCreateAggregate "max" [ "int8" ] "int8"
+>        , CatCreateAggregate "max" [ "int4" ] "int4"
+>        , CatCreateAggregate "max" [ "int2" ] "int2"
+>        , CatCreateAggregate "max" [ "oid" ] "oid"
+>        , CatCreateAggregate "max" [ "float4" ] "float4"
+>        , CatCreateAggregate "max" [ "float8" ] "float8"
+>        , CatCreateAggregate "max" [ "abstime" ] "abstime"
+>        , CatCreateAggregate "max" [ "date" ] "date"
+>        , CatCreateAggregate "max" [ "time" ] "time"
+>        , CatCreateAggregate "max" [ "timetz" ] "timetz"
+>        , CatCreateAggregate "max" [ "money" ] "money"
+>        , CatCreateAggregate "max" [ "timestamp" ] "timestamp"
+>        , CatCreateAggregate "max" [ "timestamptz" ] "timestamptz"
+>        , CatCreateAggregate "max" [ "interval" ] "interval"
+>        , CatCreateAggregate "max" [ "text" ] "text"
+>        , CatCreateAggregate "max" [ "numeric" ] "numeric"
+>        , CatCreateAggregate "max" [ "bpchar" ] "bpchar"
+>        , CatCreateAggregate "max" [ "tid" ] "tid"
+>        , CatCreateAggregate "max" [ "anyenum" ] "anyenum"
+>        , CatCreateAggregate "min" [ "anyarray" ] "anyarray"
+>        , CatCreateAggregate "min" [ "int8" ] "int8"
+>        , CatCreateAggregate "min" [ "int4" ] "int4"
+>        , CatCreateAggregate "min" [ "int2" ] "int2"
+>        , CatCreateAggregate "min" [ "oid" ] "oid"
+>        , CatCreateAggregate "min" [ "float4" ] "float4"
+>        , CatCreateAggregate "min" [ "float8" ] "float8"
+>        , CatCreateAggregate "min" [ "abstime" ] "abstime"
+>        , CatCreateAggregate "min" [ "date" ] "date"
+>        , CatCreateAggregate "min" [ "time" ] "time"
+>        , CatCreateAggregate "min" [ "timetz" ] "timetz"
+>        , CatCreateAggregate "min" [ "money" ] "money"
+>        , CatCreateAggregate "min" [ "timestamp" ] "timestamp"
+>        , CatCreateAggregate "min" [ "timestamptz" ] "timestamptz"
+>        , CatCreateAggregate "min" [ "interval" ] "interval"
+>        , CatCreateAggregate "min" [ "text" ] "text"
+>        , CatCreateAggregate "min" [ "numeric" ] "numeric"
+>        , CatCreateAggregate "min" [ "bpchar" ] "bpchar"
+>        , CatCreateAggregate "min" [ "tid" ] "tid"
+>        , CatCreateAggregate "min" [ "anyenum" ] "anyenum"
+>        , CatCreateAggregate "mode" [ "anyelement" ] "anyelement"
+>        , CatCreateAggregate
+>            "percentile_cont" [ "float8" , "float8" ] "float8"
+>        , CatCreateAggregate
+>            "percentile_cont" [ "float8" , "interval" ] "interval"
+>        , CatCreateAggregate
+>            "percentile_cont" [ "float8" , "_float8" ] "_float8"
+>        , CatCreateAggregate
+>            "percentile_cont" [ "interval" , "_float8" ] "_interval"
+>        , CatCreateAggregate
+>            "percentile_disc" [ "float8" , "anyelement" ] "anyelement"
+>        , CatCreateAggregate
+>            "percentile_disc" [ "anyelement" , "_float8" ] "anyarray"
+>        , CatCreateAggregate "regr_avgx" [ "float8" , "float8" ] "float8"
+>        , CatCreateAggregate "regr_avgy" [ "float8" , "float8" ] "float8"
+>        , CatCreateAggregate "regr_count" [ "float8" , "float8" ] "int8"
+>        , CatCreateAggregate
+>            "regr_intercept" [ "float8" , "float8" ] "float8"
+>        , CatCreateAggregate "regr_r2" [ "float8" , "float8" ] "float8"
+>        , CatCreateAggregate "regr_slope" [ "float8" , "float8" ] "float8"
+>        , CatCreateAggregate "regr_sxx" [ "float8" , "float8" ] "float8"
+>        , CatCreateAggregate "regr_sxy" [ "float8" , "float8" ] "float8"
+>        , CatCreateAggregate "regr_syy" [ "float8" , "float8" ] "float8"
+>        , CatCreateAggregate "stddev" [ "int8" ] "numeric"
+>        , CatCreateAggregate "stddev" [ "int4" ] "numeric"
+>        , CatCreateAggregate "stddev" [ "int2" ] "numeric"
+>        , CatCreateAggregate "stddev" [ "float4" ] "float8"
+>        , CatCreateAggregate "stddev" [ "float8" ] "float8"
+>        , CatCreateAggregate "stddev" [ "numeric" ] "numeric"
+>        , CatCreateAggregate "stddev_pop" [ "int8" ] "numeric"
+>        , CatCreateAggregate "stddev_pop" [ "int4" ] "numeric"
+>        , CatCreateAggregate "stddev_pop" [ "int2" ] "numeric"
+>        , CatCreateAggregate "stddev_pop" [ "float4" ] "float8"
+>        , CatCreateAggregate "stddev_pop" [ "float8" ] "float8"
+>        , CatCreateAggregate "stddev_pop" [ "numeric" ] "numeric"
+>        , CatCreateAggregate "stddev_samp" [ "int8" ] "numeric"
+>        , CatCreateAggregate "stddev_samp" [ "int4" ] "numeric"
+>        , CatCreateAggregate "stddev_samp" [ "int2" ] "numeric"
+>        , CatCreateAggregate "stddev_samp" [ "float4" ] "float8"
+>        , CatCreateAggregate "stddev_samp" [ "float8" ] "float8"
+>        , CatCreateAggregate "stddev_samp" [ "numeric" ] "numeric"
+>        , CatCreateAggregate "string_agg" [ "text" , "text" ] "text"
+>        , CatCreateAggregate "string_agg" [ "bytea" , "bytea" ] "bytea"
+>        , CatCreateAggregate "sum" [ "int8" ] "numeric"
+>        , CatCreateAggregate "sum" [ "int4" ] "int8"
+>        , CatCreateAggregate "sum" [ "int2" ] "int8"
+>        , CatCreateAggregate "sum" [ "float4" ] "float4"
+>        , CatCreateAggregate "sum" [ "float8" ] "float8"
+>        , CatCreateAggregate "sum" [ "money" ] "money"
+>        , CatCreateAggregate "sum" [ "interval" ] "interval"
+>        , CatCreateAggregate "sum" [ "numeric" ] "numeric"
+>        , CatCreateAggregate "var_pop" [ "int8" ] "numeric"
+>        , CatCreateAggregate "var_pop" [ "int4" ] "numeric"
+>        , CatCreateAggregate "var_pop" [ "int2" ] "numeric"
+>        , CatCreateAggregate "var_pop" [ "float4" ] "float8"
+>        , CatCreateAggregate "var_pop" [ "float8" ] "float8"
+>        , CatCreateAggregate "var_pop" [ "numeric" ] "numeric"
+>        , CatCreateAggregate "var_samp" [ "int8" ] "numeric"
+>        , CatCreateAggregate "var_samp" [ "int4" ] "numeric"
+>        , CatCreateAggregate "var_samp" [ "int2" ] "numeric"
+>        , CatCreateAggregate "var_samp" [ "float4" ] "float8"
+>        , CatCreateAggregate "var_samp" [ "float8" ] "float8"
+>        , CatCreateAggregate "var_samp" [ "numeric" ] "numeric"
+>        , CatCreateAggregate "variance" [ "int8" ] "numeric"
+>        , CatCreateAggregate "variance" [ "int4" ] "numeric"
+>        , CatCreateAggregate "variance" [ "int2" ] "numeric"
+>        , CatCreateAggregate "variance" [ "float4" ] "float8"
+>        , CatCreateAggregate "variance" [ "float8" ] "float8"
+>        , CatCreateAggregate "variance" [ "numeric" ] "numeric"
+>        , CatCreateAggregate "xmlagg" [ "xml" ] "xml"
+>        , CatCreateCast "abstime" "date" AssignmentCastContext
+>        , CatCreateCast "abstime" "int4" ExplicitCastContext
+>        , CatCreateCast "abstime" "time" AssignmentCastContext
+>        , CatCreateCast "abstime" "timestamp" ImplicitCastContext
+>        , CatCreateCast "abstime" "timestamptz" ImplicitCastContext
+>        , CatCreateCast "bit" "bit" ImplicitCastContext
+>        , CatCreateCast "bit" "int4" ExplicitCastContext
+>        , CatCreateCast "bit" "int8" ExplicitCastContext
+>        , CatCreateCast "bit" "varbit" ImplicitCastContext
+>        , CatCreateCast "bool" "bpchar" AssignmentCastContext
+>        , CatCreateCast "bool" "int4" ExplicitCastContext
+>        , CatCreateCast "bool" "text" AssignmentCastContext
+>        , CatCreateCast "bool" "varchar" AssignmentCastContext
+>        , CatCreateCast "box" "circle" ExplicitCastContext
+>        , CatCreateCast "box" "lseg" ExplicitCastContext
+>        , CatCreateCast "box" "point" ExplicitCastContext
+>        , CatCreateCast "box" "polygon" AssignmentCastContext
+>        , CatCreateCast "bpchar" "bpchar" ImplicitCastContext
+>        , CatCreateCast "bpchar" "char" AssignmentCastContext
+>        , CatCreateCast "bpchar" "name" ImplicitCastContext
+>        , CatCreateCast "bpchar" "text" ImplicitCastContext
+>        , CatCreateCast "bpchar" "varchar" ImplicitCastContext
+>        , CatCreateCast "bpchar" "xml" ExplicitCastContext
+>        , CatCreateCast "char" "bpchar" AssignmentCastContext
+>        , CatCreateCast "char" "int4" ExplicitCastContext
+>        , CatCreateCast "char" "text" ImplicitCastContext
+>        , CatCreateCast "char" "varchar" AssignmentCastContext
+>        , CatCreateCast "cidr" "bpchar" AssignmentCastContext
+>        , CatCreateCast "cidr" "inet" ImplicitCastContext
+>        , CatCreateCast "cidr" "text" AssignmentCastContext
+>        , CatCreateCast "cidr" "varchar" AssignmentCastContext
+>        , CatCreateCast "circle" "box" ExplicitCastContext
+>        , CatCreateCast "circle" "point" ExplicitCastContext
+>        , CatCreateCast "circle" "polygon" ExplicitCastContext
+>        , CatCreateCast "date" "timestamp" ImplicitCastContext
+>        , CatCreateCast "date" "timestamptz" ImplicitCastContext
+>        , CatCreateCast "float4" "float8" ImplicitCastContext
+>        , CatCreateCast "float4" "int2" AssignmentCastContext
+>        , CatCreateCast "float4" "int4" AssignmentCastContext
+>        , CatCreateCast "float4" "int8" AssignmentCastContext
+>        , CatCreateCast "float4" "numeric" AssignmentCastContext
+>        , CatCreateCast "float8" "float4" AssignmentCastContext
+>        , CatCreateCast "float8" "int2" AssignmentCastContext
+>        , CatCreateCast "float8" "int4" AssignmentCastContext
+>        , CatCreateCast "float8" "int8" AssignmentCastContext
+>        , CatCreateCast "float8" "numeric" AssignmentCastContext
+>        , CatCreateCast "inet" "bpchar" AssignmentCastContext
+>        , CatCreateCast "inet" "cidr" AssignmentCastContext
+>        , CatCreateCast "inet" "text" AssignmentCastContext
+>        , CatCreateCast "inet" "varchar" AssignmentCastContext
+>        , CatCreateCast "int2" "float4" ImplicitCastContext
+>        , CatCreateCast "int2" "float8" ImplicitCastContext
+>        , CatCreateCast "int2" "int4" ImplicitCastContext
+>        , CatCreateCast "int2" "int8" ImplicitCastContext
+>        , CatCreateCast "int2" "numeric" ImplicitCastContext
+>        , CatCreateCast "int2" "oid" ImplicitCastContext
+>        , CatCreateCast "int2" "regclass" ImplicitCastContext
+>        , CatCreateCast "int2" "regconfig" ImplicitCastContext
+>        , CatCreateCast "int2" "regdictionary" ImplicitCastContext
+>        , CatCreateCast "int2" "regoper" ImplicitCastContext
+>        , CatCreateCast "int2" "regoperator" ImplicitCastContext
+>        , CatCreateCast "int2" "regproc" ImplicitCastContext
+>        , CatCreateCast "int2" "regprocedure" ImplicitCastContext
+>        , CatCreateCast "int2" "regtype" ImplicitCastContext
+>        , CatCreateCast "int4" "abstime" ExplicitCastContext
+>        , CatCreateCast "int4" "bit" ExplicitCastContext
+>        , CatCreateCast "int4" "bool" ExplicitCastContext
+>        , CatCreateCast "int4" "char" ExplicitCastContext
+>        , CatCreateCast "int4" "float4" ImplicitCastContext
+>        , CatCreateCast "int4" "float8" ImplicitCastContext
+>        , CatCreateCast "int4" "int2" AssignmentCastContext
+>        , CatCreateCast "int4" "int8" ImplicitCastContext
+>        , CatCreateCast "int4" "money" AssignmentCastContext
+>        , CatCreateCast "int4" "numeric" ImplicitCastContext
+>        , CatCreateCast "int4" "oid" ImplicitCastContext
+>        , CatCreateCast "int4" "regclass" ImplicitCastContext
+>        , CatCreateCast "int4" "regconfig" ImplicitCastContext
+>        , CatCreateCast "int4" "regdictionary" ImplicitCastContext
+>        , CatCreateCast "int4" "regoper" ImplicitCastContext
+>        , CatCreateCast "int4" "regoperator" ImplicitCastContext
+>        , CatCreateCast "int4" "regproc" ImplicitCastContext
+>        , CatCreateCast "int4" "regprocedure" ImplicitCastContext
+>        , CatCreateCast "int4" "regtype" ImplicitCastContext
+>        , CatCreateCast "int4" "reltime" ExplicitCastContext
+>        , CatCreateCast "int8" "bit" ExplicitCastContext
+>        , CatCreateCast "int8" "float4" ImplicitCastContext
+>        , CatCreateCast "int8" "float8" ImplicitCastContext
+>        , CatCreateCast "int8" "int2" AssignmentCastContext
+>        , CatCreateCast "int8" "int4" AssignmentCastContext
+>        , CatCreateCast "int8" "money" AssignmentCastContext
+>        , CatCreateCast "int8" "numeric" ImplicitCastContext
+>        , CatCreateCast "int8" "oid" ImplicitCastContext
+>        , CatCreateCast "int8" "regclass" ImplicitCastContext
+>        , CatCreateCast "int8" "regconfig" ImplicitCastContext
+>        , CatCreateCast "int8" "regdictionary" ImplicitCastContext
+>        , CatCreateCast "int8" "regoper" ImplicitCastContext
+>        , CatCreateCast "int8" "regoperator" ImplicitCastContext
+>        , CatCreateCast "int8" "regproc" ImplicitCastContext
+>        , CatCreateCast "int8" "regprocedure" ImplicitCastContext
+>        , CatCreateCast "int8" "regtype" ImplicitCastContext
+>        , CatCreateCast "interval" "interval" ImplicitCastContext
+>        , CatCreateCast "interval" "reltime" AssignmentCastContext
+>        , CatCreateCast "interval" "time" AssignmentCastContext
+>        , CatCreateCast "json" "jsonb" ExplicitCastContext
+>        , CatCreateCast "jsonb" "json" ExplicitCastContext
+>        , CatCreateCast "lseg" "point" ExplicitCastContext
+>        , CatCreateCast "money" "numeric" AssignmentCastContext
+>        , CatCreateCast "name" "bpchar" AssignmentCastContext
+>        , CatCreateCast "name" "text" ImplicitCastContext
+>        , CatCreateCast "name" "varchar" AssignmentCastContext
+>        , CatCreateCast "numeric" "float4" ImplicitCastContext
+>        , CatCreateCast "numeric" "float8" ImplicitCastContext
+>        , CatCreateCast "numeric" "int2" AssignmentCastContext
+>        , CatCreateCast "numeric" "int4" AssignmentCastContext
+>        , CatCreateCast "numeric" "int8" AssignmentCastContext
+>        , CatCreateCast "numeric" "money" AssignmentCastContext
+>        , CatCreateCast "numeric" "numeric" ImplicitCastContext
+>        , CatCreateCast "oid" "int4" AssignmentCastContext
+>        , CatCreateCast "oid" "int8" AssignmentCastContext
+>        , CatCreateCast "oid" "regclass" ImplicitCastContext
+>        , CatCreateCast "oid" "regconfig" ImplicitCastContext
+>        , CatCreateCast "oid" "regdictionary" ImplicitCastContext
+>        , CatCreateCast "oid" "regoper" ImplicitCastContext
+>        , CatCreateCast "oid" "regoperator" ImplicitCastContext
+>        , CatCreateCast "oid" "regproc" ImplicitCastContext
+>        , CatCreateCast "oid" "regprocedure" ImplicitCastContext
+>        , CatCreateCast "oid" "regtype" ImplicitCastContext
+>        , CatCreateCast "path" "point" ExplicitCastContext
+>        , CatCreateCast "path" "polygon" AssignmentCastContext
+>        , CatCreateCast "pg_node_tree" "text" ImplicitCastContext
+>        , CatCreateCast "polygon" "box" ExplicitCastContext
+>        , CatCreateCast "polygon" "circle" ExplicitCastContext
+>        , CatCreateCast "polygon" "path" AssignmentCastContext
+>        , CatCreateCast "polygon" "point" ExplicitCastContext
+>        , CatCreateCast "regclass" "int4" AssignmentCastContext
+>        , CatCreateCast "regclass" "int8" AssignmentCastContext
+>        , CatCreateCast "regclass" "oid" ImplicitCastContext
+>        , CatCreateCast "regconfig" "int4" AssignmentCastContext
+>        , CatCreateCast "regconfig" "int8" AssignmentCastContext
+>        , CatCreateCast "regconfig" "oid" ImplicitCastContext
+>        , CatCreateCast "regdictionary" "int4" AssignmentCastContext
+>        , CatCreateCast "regdictionary" "int8" AssignmentCastContext
+>        , CatCreateCast "regdictionary" "oid" ImplicitCastContext
+>        , CatCreateCast "regoper" "int4" AssignmentCastContext
+>        , CatCreateCast "regoper" "int8" AssignmentCastContext
+>        , CatCreateCast "regoper" "oid" ImplicitCastContext
+>        , CatCreateCast "regoper" "regoperator" ImplicitCastContext
+>        , CatCreateCast "regoperator" "int4" AssignmentCastContext
+>        , CatCreateCast "regoperator" "int8" AssignmentCastContext
+>        , CatCreateCast "regoperator" "oid" ImplicitCastContext
+>        , CatCreateCast "regoperator" "regoper" ImplicitCastContext
+>        , CatCreateCast "regproc" "int4" AssignmentCastContext
+>        , CatCreateCast "regproc" "int8" AssignmentCastContext
+>        , CatCreateCast "regproc" "oid" ImplicitCastContext
+>        , CatCreateCast "regproc" "regprocedure" ImplicitCastContext
+>        , CatCreateCast "regprocedure" "int4" AssignmentCastContext
+>        , CatCreateCast "regprocedure" "int8" AssignmentCastContext
+>        , CatCreateCast "regprocedure" "oid" ImplicitCastContext
+>        , CatCreateCast "regprocedure" "regproc" ImplicitCastContext
+>        , CatCreateCast "regtype" "int4" AssignmentCastContext
+>        , CatCreateCast "regtype" "int8" AssignmentCastContext
+>        , CatCreateCast "regtype" "oid" ImplicitCastContext
+>        , CatCreateCast "reltime" "int4" ExplicitCastContext
+>        , CatCreateCast "reltime" "interval" ImplicitCastContext
+>        , CatCreateCast "text" "bpchar" ImplicitCastContext
+>        , CatCreateCast "text" "char" AssignmentCastContext
+>        , CatCreateCast "text" "name" ImplicitCastContext
+>        , CatCreateCast "text" "regclass" ImplicitCastContext
+>        , CatCreateCast "text" "varchar" ImplicitCastContext
+>        , CatCreateCast "text" "xml" ExplicitCastContext
+>        , CatCreateCast "time" "interval" ImplicitCastContext
+>        , CatCreateCast "time" "time" ImplicitCastContext
+>        , CatCreateCast "time" "timetz" ImplicitCastContext
+>        , CatCreateCast "timestamp" "abstime" AssignmentCastContext
+>        , CatCreateCast "timestamp" "date" AssignmentCastContext
+>        , CatCreateCast "timestamp" "time" AssignmentCastContext
+>        , CatCreateCast "timestamp" "timestamp" ImplicitCastContext
+>        , CatCreateCast "timestamp" "timestamptz" ImplicitCastContext
+>        , CatCreateCast "timestamptz" "abstime" AssignmentCastContext
+>        , CatCreateCast "timestamptz" "date" AssignmentCastContext
+>        , CatCreateCast "timestamptz" "time" AssignmentCastContext
+>        , CatCreateCast "timestamptz" "timestamp" AssignmentCastContext
+>        , CatCreateCast "timestamptz" "timestamptz" ImplicitCastContext
+>        , CatCreateCast "timestamptz" "timetz" AssignmentCastContext
+>        , CatCreateCast "timetz" "time" AssignmentCastContext
+>        , CatCreateCast "timetz" "timetz" ImplicitCastContext
+>        , CatCreateCast "varbit" "bit" ImplicitCastContext
+>        , CatCreateCast "varbit" "varbit" ImplicitCastContext
+>        , CatCreateCast "varchar" "bpchar" ImplicitCastContext
+>        , CatCreateCast "varchar" "char" AssignmentCastContext
+>        , CatCreateCast "varchar" "name" ImplicitCastContext
+>        , CatCreateCast "varchar" "regclass" ImplicitCastContext
+>        , CatCreateCast "varchar" "text" ImplicitCastContext
+>        , CatCreateCast "varchar" "varchar" ImplicitCastContext
+>        , CatCreateCast "varchar" "xml" ExplicitCastContext
+>        , CatCreateCast "xml" "bpchar" AssignmentCastContext
+>        , CatCreateCast "xml" "text" AssignmentCastContext
+>        , CatCreateCast "xml" "varchar" AssignmentCastContext
+>        , CatCreateTypeCategoryEntry "abstime" ( "D" , False )
+>        , CatCreateTypeCategoryEntry "aclitem" ( "U" , False )
+>        , CatCreateTypeCategoryEntry "bit" ( "V" , False )
+>        , CatCreateTypeCategoryEntry "bool" ( "B" , True )
+>        , CatCreateTypeCategoryEntry "box" ( "G" , False )
+>        , CatCreateTypeCategoryEntry "bpchar" ( "S" , False )
+>        , CatCreateTypeCategoryEntry "bytea" ( "U" , False )
+>        , CatCreateTypeCategoryEntry "char" ( "S" , False )
+>        , CatCreateTypeCategoryEntry "cid" ( "U" , False )
+>        , CatCreateTypeCategoryEntry "cidr" ( "I" , False )
+>        , CatCreateTypeCategoryEntry "circle" ( "G" , False )
+>        , CatCreateTypeCategoryEntry "date" ( "D" , False )
+>        , CatCreateTypeCategoryEntry "float4" ( "N" , False )
+>        , CatCreateTypeCategoryEntry "float8" ( "N" , True )
+>        , CatCreateTypeCategoryEntry "gtsvector" ( "U" , False )
+>        , CatCreateTypeCategoryEntry "inet" ( "I" , True )
+>        , CatCreateTypeCategoryEntry "int2" ( "N" , False )
+>        , CatCreateTypeCategoryEntry "int2vector" ( "A" , False )
+>        , CatCreateTypeCategoryEntry "int4" ( "N" , False )
+>        , CatCreateTypeCategoryEntry "int8" ( "N" , False )
+>        , CatCreateTypeCategoryEntry "interval" ( "T" , True )
+>        , CatCreateTypeCategoryEntry "json" ( "U" , False )
+>        , CatCreateTypeCategoryEntry "jsonb" ( "U" , False )
+>        , CatCreateTypeCategoryEntry "line" ( "G" , False )
+>        , CatCreateTypeCategoryEntry "lseg" ( "G" , False )
+>        , CatCreateTypeCategoryEntry "macaddr" ( "U" , False )
+>        , CatCreateTypeCategoryEntry "money" ( "N" , False )
+>        , CatCreateTypeCategoryEntry "name" ( "S" , False )
+>        , CatCreateTypeCategoryEntry "numeric" ( "N" , False )
+>        , CatCreateTypeCategoryEntry "oid" ( "N" , True )
+>        , CatCreateTypeCategoryEntry "oidvector" ( "A" , False )
+>        , CatCreateTypeCategoryEntry "path" ( "G" , False )
+>        , CatCreateTypeCategoryEntry "pg_lsn" ( "U" , False )
+>        , CatCreateTypeCategoryEntry "point" ( "G" , False )
+>        , CatCreateTypeCategoryEntry "polygon" ( "G" , False )
+>        , CatCreateTypeCategoryEntry "refcursor" ( "U" , False )
+>        , CatCreateTypeCategoryEntry "regclass" ( "N" , False )
+>        , CatCreateTypeCategoryEntry "regconfig" ( "N" , False )
+>        , CatCreateTypeCategoryEntry "regdictionary" ( "N" , False )
+>        , CatCreateTypeCategoryEntry "regoper" ( "N" , False )
+>        , CatCreateTypeCategoryEntry "regoperator" ( "N" , False )
+>        , CatCreateTypeCategoryEntry "regproc" ( "N" , False )
+>        , CatCreateTypeCategoryEntry "regprocedure" ( "N" , False )
+>        , CatCreateTypeCategoryEntry "regtype" ( "N" , False )
+>        , CatCreateTypeCategoryEntry "reltime" ( "T" , False )
+>        , CatCreateTypeCategoryEntry "text" ( "S" , True )
+>        , CatCreateTypeCategoryEntry "tid" ( "U" , False )
+>        , CatCreateTypeCategoryEntry "time" ( "D" , False )
+>        , CatCreateTypeCategoryEntry "timestamp" ( "D" , False )
+>        , CatCreateTypeCategoryEntry "timestamptz" ( "D" , True )
+>        , CatCreateTypeCategoryEntry "timetz" ( "D" , False )
+>        , CatCreateTypeCategoryEntry "tinterval" ( "T" , False )
+>        , CatCreateTypeCategoryEntry "tsquery" ( "U" , False )
+>        , CatCreateTypeCategoryEntry "tsvector" ( "U" , False )
+>        , CatCreateTypeCategoryEntry "txid_snapshot" ( "U" , False )
+>        , CatCreateTypeCategoryEntry "uuid" ( "U" , False )
+>        , CatCreateTypeCategoryEntry "varbit" ( "V" , True )
+>        , CatCreateTypeCategoryEntry "varchar" ( "S" , False )
+>        , CatCreateTypeCategoryEntry "xid" ( "U" , False )
+>        , CatCreateTypeCategoryEntry "xml" ( "U" , False )
+>        ]
+
+
diff --git a/src/Database/HsSqlPpp/Dialects/OdbcCatalog.lhs b/src/Database/HsSqlPpp/Dialects/OdbcCatalog.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Dialects/OdbcCatalog.lhs
@@ -0,0 +1,629 @@
+
+This is the catalog for the odbc scalar functions.
+
+https://msdn.microsoft.com/en-us/library/ms711813(v=vs.85).aspx
+
+TODO: this needs finishing
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Dialects.OdbcCatalog
+>      (odbcCatalog,odbcConvertTypes,odbcIntervalTypes) where
+>
+> --import Database.HsSqlPpp.Internals.Catalog.CatalogInternal
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+
+todo: refactor this so we only have the names in this file and get rid
+of the leakage of Type into here.
+
+> import Database.HsSqlPpp.Internals.TypesInternal
+> --import Database.HsSqlPpp.Internals.TypesInternal
+
+todo: we have to add odbc on top of different dialects, do some tests
+then figure out how to handle e.g. the canonical type names being
+different in different dialects.
+
+> typeBigInt,typeFloat8,typeChar,typeNumeric,typeFloat4,
+>   typeSmallInt,typeInt,typeDate,typeTimestamp,typeVarChar :: Type
+> typeBigInt = ScalarType "int8"
+> typeFloat8 = ScalarType "float8"
+> typeChar = ScalarType "char"
+> typeNumeric = ScalarType "numeric"
+> typeFloat4 = ScalarType "float4"
+> typeSmallInt = ScalarType "int2"
+> typeInt = ScalarType "int4"
+> typeDate = ScalarType "date"
+> typeTimestamp = ScalarType "timestamp"
+> typeVarChar = ScalarType "varchar"
+
+> -- | The odbc catalog contains the odbc specific functions
+> -- if you want to type check sql with odbc specific functions, you
+> -- can add these catalog updates to your catalog and then it should
+> -- work
+> odbcCatalog :: [CatalogUpdate]
+> odbcCatalog = [
+
+string functions
+
+ASCII(string_exp) (ODBC 1.0)
+Returns the ASCII code value of the leftmost character of string_exp as an integer.
+
+>         CatCreateFunction "!odbc-ascii" ["text"] False "int4"
+>        ,CatCreateFunction "!odbc-ascii" ["char"] False "int4"
+>        ,CatCreateFunction "!odbc-ascii" ["varchar"] False "int4"
+
+BIT_LENGTH(string_exp) (ODBC 3.0)
+Returns the length in bits of the string expression.
+Does not work only for string data types, therefore will not implicitly convert string_exp to string but instead will return the (internal) size of whatever datatype it is given.
+
+>        ,CatCreateFunction "!odbc-bit_length" ["text"] False "int4"
+>        ,CatCreateFunction "!odbc-bit_length" ["char"] False "int4"
+>        ,CatCreateFunction "!odbc-bit_length" ["varchar"] False "int4"
+
+CHAR(code) (ODBC 1.0)
+Returns the character that has the ASCII code value specified by code. The value of code should be between 0 and 255; otherwise, the return value is data source–dependent.
+
+>        ,CatCreateFunction "!odbc-char" ["int4"] False "char"
+
+CHAR_LENGTH(string_exp) (ODBC 3.0)
+Returns the length in characters of the string expression, if the string expression is of a character data type; otherwise, returns the length in bytes of the string expression (the smallest integer not less than the number of bits divided by 8). (This function is the same as the CHARACTER_LENGTH function.)
+
+>        ,CatCreateFunction "!odbc-char_length" ["text"] False "int4"
+>        ,CatCreateFunction "!odbc-char_length" ["char"] False "int4"
+>        ,CatCreateFunction "!odbc-char_length" ["varchar"] False "int4"
+
+CHARACTER_LENGTH(string_exp) (ODBC 3.0)
+Returns the length in characters of the string expression, if the string expression is of a character data type; otherwise, returns the length in bytes of the string expression (the smallest integer not less tha the number of bits divided by 8). (This function is the same as the CHAR_LENGTH function.)
+
+>        ,CatCreateFunction "!odbc-character_length" ["text"] False "int4"
+>        ,CatCreateFunction "!odbc-character_length" ["char"] False "int4"
+>        ,CatCreateFunction "!odbc-character_length" ["varchar"] False "int4"
+
+CONCAT(string_exp1,string_exp2) (ODBC 1.0)
+Returns a character string that is the result of concatenating string_exp2 to string_exp1. The resulting string is DBMS-dependent. For example, if the column represented by string_exp1 contained a NULL value, DB2 would return NULL but SQL Server would return the non-NULL string.
+
+concat not in pg
+
+>       ,CatCreateFunction "!odbc-concat" ["text","text"] False "text"
+>       ,CatCreateFunction "!odbc-concat" ["char","char"] False "char"
+>       ,CatCreateFunction "!odbc-concat" ["varchar","varchar"] False "varchar"
+
+DIFFERENCE(string_exp1,string_exp2) (ODBC 2.0)
+Returns an integer value that indicates the difference between the values returned by the SOUNDEX function for string_exp1 and string_exp2.
+
+difference not in pg
+
+>       ,CatCreateFunction "!odbc-difference" ["text","text"] False "int4"
+>       ,CatCreateFunction "!odbc-difference" ["char","char"] False "int4"
+>       ,CatCreateFunction "!odbc-difference" ["varchar","varchar"] False "int4"
+
+INSERT(string_exp1, start, length, string_exp2) (ODBC 1.0)
+Returns a character string where length characters have been deleted from string_exp1, beginning at start, and where string_exp2 has been inserted into string_exp, beginning at start.
+
+insert not in pg
+
+>       ,CatCreateFunction "!odbc-insert" ["text","int4","int4","text"] False "text"
+>       ,CatCreateFunction "!odbc-insert" ["char","int4","int4","char"] False "char"
+>       ,CatCreateFunction "!odbc-insert" ["varchar","int4","int4","varchar"] False "varchar"
+
+lcase not in pg
+
+LCASE(string_exp) (ODBC 1.0)
+Returns a string equal to that in string_exp, with all uppercase characters converted to lowercase.
+
+>       ,CatCreateFunction "!odbc-lcase" ["text"] False "text"
+>       ,CatCreateFunction "!odbc-lcase" ["char"] False "char"
+>       ,CatCreateFunction "!odbc-lcase" ["varchar"] False "varchar"
+
+left is opposite in pg
+
+LEFT(string_exp, count) (ODBC 1.0)
+Returns the leftmost count characters of string_exp.
+
+>       ,CatCreateFunction "!odbc-left" ["text","int4"] False "text"
+>       ,CatCreateFunction "!odbc-left" ["char","int4"] False "char"
+>       ,CatCreateFunction "!odbc-left" ["varchar","int4"] False "varchar"
+
+LENGTH(string_exp) (ODBC 1.0)
+Returns the number of characters in string_exp, excluding trailing blanks.
+LENGTH only accepts strings. Therefore will implicitly convert string_exp to a string, and return the length of this string (not the internal size of the datatype).
+
+TODO: we don't support the custom implicit conversion to string unless
+there is a standard implicit conversion usable.
+
+>       ,CatCreateFunction "!odbc-length" ["text"] False "text"
+>       ,CatCreateFunction "!odbc-length" ["char"] False "char"
+>       ,CatCreateFunction "!odbc-length" ["varchar"] False "varchar"
+
+
+LOCATE(string_exp1, string_exp2[, start])  (ODBC 1.0)
+Returns the starting position of the first occurrence of string_exp1 within string_exp2. The search for the first occurrence of string_exp1 begins with the first character position in string_exp2 unless the optional argument, start, is specified. If start is specified, the search begins with the character position indicated by the value of start. The first character position in string_exp2 is indicated by the value 1. If string_exp1 is not found within string_exp2, the value 0 is returned.
+If an application can call the LOCATE scalar function with the string_exp1, string_exp2, and start arguments, the driver returns SQL_FN_STR_LOCATE when SQLGetInfo is called with an Option of SQL_STRING_FUNCTIONS. If the application can call the LOCATE scalar function with only the string_exp1 and string_exp2 arguments, the driver returns SQL_FN_STR_LOCATE_2 when SQLGetInfo is called with an Option of SQL_STRING_FUNCTIONS. Drivers that support calling the LOCATE function with either two or three arguments return both SQL_FN_STR_LOCATE and SQL_FN_STR_LOCATE_2.
+
+>       ,CatCreateFunction "!odbc-locate" ["text","text"] False "int4"
+>       ,CatCreateFunction "!odbc-locate" ["text","text","int4"] False "int4"
+>       ,CatCreateFunction "!odbc-locate" ["char","char"] False "int4"
+>       ,CatCreateFunction "!odbc-locate" ["char","char","int4"] False "int4"
+>       ,CatCreateFunction "!odbc-locate" ["varchar","varchar"] False "int4"
+>       ,CatCreateFunction "!odbc-locate" ["varchar","varchar","int4"] False "int4"
+
+LTRIM(string_exp) (ODBC 1.0)
+Returns the characters of string_exp, with leading blanks removed.
+
+>       ,CatCreateFunction "!odbc-ltrim" ["text"] False "text"
+>       ,CatCreateFunction "!odbc-ltrim" ["char"] False "char"
+>       ,CatCreateFunction "!odbc-ltrim" ["varchar"] False "varchar"
+
+
+OCTET_LENGTH(string_exp) (ODBC 3.0)
+Returns the length in bytes of the string expression. The result is the smallest integer not less than the number of bits divided by 8.
+Does not work only for string data types, therefore will not implicitly convert string_exp to string but instead will return the (internal) size of whatever datatype it is given.
+
+>       ,CatCreateFunction "!odbc-octet_length" ["text"] False "int4"
+>       ,CatCreateFunction "!odbc-octet_length" ["char"] False "int4"
+>       ,CatCreateFunction "!odbc-octet_length" ["varchar"] False "int4"
+
+POSITION(character_exp IN character_exp) (ODBC 3.0)
+Returns the position of the first character expression in the second character expression. The result is an exact numeric with an implementation-defined precision and a scale of 0.
+
+we don't support position for now since we this is a ansi sql syntax
+which we also don't currently support
+
+REPEAT(string_exp, count) (ODBC 1.0)
+Returns a character string composed of string_exp repeated count times.
+
+>       ,CatCreateFunction "!odbc-repeat" ["text","int4"] False "text"
+>       ,CatCreateFunction "!odbc-repeat" ["char","int4"] False "char"
+>       ,CatCreateFunction "!odbc-repeat" ["varchar","int4"] False "varchar"
+
+REPLACE(string_exp1, string_exp2, string_exp3) (ODBC 1.0)
+Search string_exp1 foroccurrences of string_exp2, and replace with string_exp3.
+
+>       ,CatCreateFunction "!odbc-replace" ["text","text","text"] False "text"
+>       ,CatCreateFunction "!odbc-replace" ["char","char","char"] False "char"
+>       ,CatCreateFunction "!odbc-replace" ["varchar","varchar","varchar"] False "varchar"
+
+RIGHT(string_exp, count) (ODBC 1.0)
+Returns the rightmost count characters of string_exp.
+
+>       ,CatCreateFunction "!odbc-right" ["text","int4"] False "text"
+>       ,CatCreateFunction "!odbc-right" ["char","int4"] False "char"
+>       ,CatCreateFunction "!odbc-right" ["varchar","int4"] False "varchar"
+
+
+RTRIM(string_exp) (ODBC 1.0)
+Returns the characters of string_exp with trailing blanks removed.
+
+>       ,CatCreateFunction "!odbc-rtrim" ["text"] False "text"
+>       ,CatCreateFunction "!odbc-rtrim" ["char"] False "char"
+>       ,CatCreateFunction "!odbc-rtrim" ["varchar"] False "varchar"
+
+SOUNDEX(string_exp) (ODBC 2.0)
+Returns a data source–dependent character string representing the sound of the words in string_exp. For example, SQL Server returns a 4-digit SOUNDEX code; Oracle returns a phonetic representation of each word.
+
+>       ,CatCreateFunction "!odbc-soundex" ["text"] False "text"
+>       ,CatCreateFunction "!odbc-soundex" ["char"] False "char"
+>       ,CatCreateFunction "!odbc-soundex" ["varchar"] False "varchar"
+
+
+SPACE(count) (ODBC 2.0)
+Returns a character string consisting of count spaces.
+
+>       ,CatCreateFunction "!odbc-space" ["int4"] False "char"
+
+SUBSTRING(string_exp, start, length) (ODBC 1.0)
+Returns a character string that is derived from string_exp, beginning at the character position specified by start for length characters.
+
+>       ,CatCreateFunction "!odbc-substring" ["text","int4","int4"] False "text"
+>       ,CatCreateFunction "!odbc-substring" ["char","int4","int4"] False "char"
+>       ,CatCreateFunction "!odbc-substring" ["varchar","int4","int4"] False "varchar"
+
+UCASE(string_exp) (ODBC 1.0)
+Returns a string equal to that in string_exp, with all lowercase characters converted to uppercase.
+
+>       ,CatCreateFunction "!odbc-ucase" ["text"] False "text"
+>       ,CatCreateFunction "!odbc-ucase" ["char"] False "char"
+>       ,CatCreateFunction "!odbc-ucase" ["varchar"] False "varchar"
+
+numeric functions
+
+>       ]
+
+ABS(numeric_exp) (ODBC 1.0)
+Returns the absolute value of numeric_exp.
+
+>        ++ [CatCreateFunction "!odbc-abs" [n] False n  | n <- numTypes]
+
+ACOS(float_exp) (ODBC 1.0)
+Returns the arccosine of float_exp as an angle, expressed in radians.
+
+>        ++ [CatCreateFunction "!odbc-acos" [n] False n  | n <- floatTypes]
+
+ASIN(float_exp) (ODBC 1.0)
+Returns the arcsine of float_exp as an angle, expressed in radians.
+
+>        ++ [CatCreateFunction "!odbc-asin" [n] False n  | n <- floatTypes]
+
+ATAN(float_exp) (ODBC 1.0)
+Returns the arctangent of float_exp as an angle, expressed in radians.
+
+>        ++ [CatCreateFunction "!odbc-atan" [n] False n  | n <- floatTypes]
+
+ATAN2(float_exp1, float_exp2) (ODBC 2.0)
+Returns the arctangent of the x and y coordinates, specified by float_exp1 and float_exp2, respectively, as an angle, expressed in radians.
+
+>        ++ [CatCreateFunction "!odbc-atan2" [n] False n  | n <- floatTypes]
+
+CEILING(numeric_exp) (ODBC 1.0)
+Returns the smallest integer greater than or equal to numeric_exp. The return value is of the same data type as the input parameter.
+
+>        ++ [CatCreateFunction "!odbc-ceiling" [n] False n  | n <- numTypes]
+
+COS(float_exp) (ODBC 1.0)
+Returns the cosine of float_exp, where float_exp is an angle expressed in radians.
+
+>        ++ [CatCreateFunction "!odbc-cos" [n] False n  | n <- floatTypes]
+
+COT(float_exp) (ODBC 1.0)
+Returns the cotangent of float_exp, where float_exp is an angle expressed in radians.
+
+>        ++ [CatCreateFunction "!odbc-cot" [n] False n  | n <- floatTypes]
+
+DEGREES(numeric_exp) (ODBC 2.0)
+Returns the number of degrees converted from numeric_exp radians.
+
+>        ++ [CatCreateFunction "!odbc-degrees" [n] False n  | n <- numTypes]
+
+EXP(float_exp) (ODBC 1.0)
+Returns the exponential value of float_exp.
+
+>        ++ [CatCreateFunction "!odbc-exp" [n] False n  | n <- floatTypes]
+
+FLOOR(numeric_exp) (ODBC 1.0)
+Returns the largest integer less than or equal to numeric_exp. The return value is of the same data type as the input parameter.
+
+>        ++ [CatCreateFunction "!odbc-floor" [n] False n  | n <- numTypes]
+
+LOG(float_exp) (ODBC 1.0)
+Returns the natural logarithm of float_exp.
+
+>        ++ [CatCreateFunction "!odbc-log" [n] False n  | n <- floatTypes]
+
+LOG10(float_exp) (ODBC 2.0)
+Returns the base 10 logarithm of float_exp.
+
+>        ++ [CatCreateFunction "!odbc-log10" [n] False n  | n <- floatTypes]
+
+MOD(integer_exp1, integer_exp2) (ODBC 1.0)
+Returns the remainder (modulus) of integer_exp1 divided by integer_exp2.
+
+>        ++ [CatCreateFunction "!odbc-mod" [n] False n  | n <- intTypes]
+
+PI( ) (ODBC 1.0)
+Returns the constant value of pi as a floating-point value.
+
+>        ++ [CatCreateFunction "!odbc-pi" [] False "float8"]
+
+POWER(numeric_exp, integer_exp) (ODBC 2.0)
+Returns the value of numeric_exp to the power of integer_exp.
+
+>        ++ [CatCreateFunction "!odbc-power" [n,m] False n | n <- numTypes, m <- intTypes]
+
+RADIANS(numeric_exp) (ODBC 2.0)
+Returns the number of radians converted from numeric_exp degrees.
+
+>        ++ [CatCreateFunction "!odbc-radians" [n] False n | n <- numTypes]
+
+RAND([integer_exp]) (ODBC 1.0)
+Returns a random floating-point value using integer_exp as the optional seed value.
+
+>        ++ [CatCreateFunction "!odbc-rand" [n] False n | n <- intTypes]
+
+ROUND(numeric_exp, integer_exp) (ODBC 2.0)
+Returns numeric_exp rounded to integer_exp places right of the decimal point. If integer_exp is negative, numeric_exp is rounded to |integer_exp| places to the left of the decimal point.
+
+>        ++ [CatCreateFunction "!odbc-round" [n,m] False n | n <- numTypes, m <- intTypes]
+
+SIGN(numeric_exp) (ODBC 1.0)
+Returns an indicator of the sign of numeric_exp. If numeric_exp is less than zero, –1 is returned. If numeric_exp equals zero, 0 is returned. If numeric_exp is greater than zero, 1 is returned.
+
+>        ++ [CatCreateFunction "!odbc-sign" [n] False n  | n <- numTypes]
+
+SIN(float_exp) (ODBC 1.0)
+Returns the sine of float_exp, where float_exp is an angle expressed in radians.
+
+>        ++ [CatCreateFunction "!odbc-sin" [n] False n  | n <- floatTypes]
+
+SQRT(float_exp) (ODBC 1.0)
+Returns the square root of float_exp.
+
+>        ++ [CatCreateFunction "!odbc-sqrt" [n] False n  | n <- floatTypes]
+
+TAN(float_exp) (ODBC 1.0)
+Returns the tangent of float_exp, where float_exp is an angle expressed in radians.
+
+>        ++ [CatCreateFunction "!odbc-tan" [n] False n  | n <- floatTypes]
+
+TRUNCATE(numeric_exp, integer_exp) (ODBC 2.0)
+Returns numeric_exp truncated to integer_exp places right of the decimal point. If integer_exp is negative, numeric_exp is truncated to |integer_exp| places to the left of the decimal point.
+
+>        ++ [CatCreateFunction "!odbc-log10" [n,m] False n  | n <- numTypes, m <- intTypes]
+
+>        ++ [
+
+time
+
+CURRENT_DATE( ) (ODBC 3.0)
+Returns the current date.
+
+>        CatCreateFunction "!odbc-current_date" [] False "date"
+
+CURRENT_TIME[(time-precision)] (ODBC 3.0)
+Returns the current local time. The time-precision argument determines the seconds precision of the returned value.
+
+>       ,CatCreateFunction "!odbc-current_time" [] False "time"
+
+CURRENT_TIMESTAMP [(timestamp-precision)] (ODBC 3.0)
+Returns the current local date and local time as a timestamp value. The timestamp-precision argument determines the seconds precision of the returned timestamp.
+
+>       ,CatCreateFunction "!odbc-current_timestamp" [] False "timestamp"
+
+CURDATE( ) (ODBC 1.0)
+Returns the current date.
+
+>       ,CatCreateFunction "!odbc-curdate" [] False "date"
+
+CURTIME( ) (ODBC 1.0)
+Returns the current local time.
+
+>       ,CatCreateFunction "!odbc-curtime" [] False "time"]
+
+DAYNAME(date_exp) (ODBC 2.0)
+Returns a character string containing the data source–specific name of the day (for example, Sunday through Saturday or Sun. through Sat. for a data source that uses English, or Sonntag through Samstag for a data source that uses German) for the day portion of date_exp.
+
+>       ++ [CatCreateFunction "!odbc-dayname" [d] False "varchar" | d <- dateTypes]
+
+DAYOFMONTH(date_exp) (ODBC 1.0)
+Returns the day of the month based on the month field in date_exp as an integer value in the range of 1–31.
+
+>       ++ [CatCreateFunction "!odbc-dayofmonth" [d] False "int4" | d <- dateTypes]
+
+DAYOFWEEK(date_exp) (ODBC 1.0)
+Returns the day of the week based on the week field in date_exp as an integer value in the range of 1–7, where 1 represents Sunday.
+
+>       ++ [CatCreateFunction "!odbc-dayofweek" [d] False "int4" | d <- dateTypes]
+
+DAYOFYEAR(date_exp) (ODBC 1.0)
+Returns the day of the year based on the year field in date_exp as an integer value in the range of 1–366.
+
+>       ++ [CatCreateFunction "!odbc-dayofyear" [d] False "int4" | d <- dateTypes]
+
+EXTRACT(extract-field FROM extract-source) (ODBC 3.0)
+Returns the extract-field portion of the extract-source. The extract-source argument is a datetime or interval expression. The extract-field argument can be one of the following keywords:
+YEAR MONTH DAY HOUR MINUTE SECOND
+The precision of the returned value is implementation-defined. The scale is 0 unless SECOND is specified, in which case the scale is not less than the fractional seconds precision of the extract-source field.
+
+This is a special case and handled purely in the typechecker
+
+HOUR(time_exp) (ODBC 1.0)
+Returns the hour based on the hour field in time_exp as an integer value in the range of 0–23.
+
+>       ++ [CatCreateFunction "!odbc-hour" [d] False "int4" | d <- timeTypes]
+
+MINUTE(time_exp) (ODBC 1.0)
+Returns the minute based on the minute field in time_exp as an integer value in the range of 0–59.
+
+>       ++ [CatCreateFunction "!odbc-minute" [d] False "int4" | d <- timeTypes]
+
+MONTH(date_exp) (ODBC 1.0)
+Returns the month based on the month field in date_exp as an integer value in the range of 1–12.
+
+>       ++ [CatCreateFunction "!odbc-month" [d] False "int4" | d <- dateTypes]
+
+MONTHNAME(date_exp) (ODBC 2.0)
+Returns a character string containing the data source–specific name of the month (for example, January through December or Jan. through Dec. for a data source that uses English, or Januar through Dezember for a data source that uses German) for the month portion of date_exp.
+
+>       ++ [CatCreateFunction "!odbc-monthname" [d] False "varchar" | d <- dateTypes]
+
+NOW( ) (ODBC 1.0)
+Returns current date and time as a timestamp value.
+
+>       ++ [CatCreateFunction "!odbc-now" [] False "timestamp"]
+
+QUARTER(date_exp) (ODBC 1.0)
+Returns the quarter in date_exp as an integer value in the range of 1–4, where 1 represents January 1 through March 31.
+
+>       ++ [CatCreateFunction "!odbc-quarter" [d] False "int4" | d <- dateTypes]
+
+SECOND(time_exp) (ODBC 1.0)
+Returns the second based on the second field in time_exp as an integer value in the range of 0–59.
+
+>       ++ [CatCreateFunction "!odbc-second" [d] False "int4" | d <- timeTypes]
+
+TIMESTAMPADD(interval, integer_exp, timestamp_exp) (ODBC 2.0)
+Returns the timestamp calculated by adding integer_exp intervals of type interval to timestamp_exp. Valid values of interval are the following keywords:
+SQL_TSI_FRAC_SECOND
+SQL_TSI_SECOND
+SQL_TSI_MINUTE
+SQL_TSI_HOUR
+SQL_TSI_DAY
+SQL_TSI_WEEK
+SQL_TSI_MONTH
+SQL_TSI_QUARTER
+SQL_TSI_YEAR
+where fractional seconds are expressed in billionths of a second. For example, the following SQL statement returns the name of each employee and his or her one-year anniversary date:
+SELECT NAME, {fn TIMESTAMPADD(SQL_TSI_YEAR, 1, HIRE_DATE)} FROM EMPLOYEES
+If timestamp_exp is a time value and interval specifies days, weeks, months, quarters, or years, the date portion of timestamp_exp is set to the current date before calculating the resulting timestamp.
+If timestamp_exp is a date value and interval specifies fractional seconds, seconds, minutes, or hours, the time portion of timestamp_exp is set to 0 before calculating the resulting timestamp.
+An application determines which intervals a data source supports by calling SQLGetInfo with the SQL_TIMEDATE_ADD_INTERVALS option.
+
+>        ++ [CatCreateFunction "!odbc-timestampadd" ["int4","int4","date"] False "date"
+>       ,CatCreateFunction "!odbc-timestampadd" ["int4","int4","time"] False "time"
+>       ,CatCreateFunction "!odbc-timestampadd" ["int4","int4","timestamp"] False "timestamp"
+
+TIMESTAMPDIFF(interval, timestamp_exp1, timestamp_exp2) (ODBC 2.0)
+Returns the integer number of intervals of type interval by which timestamp_exp2 is greater than timestamp_exp1. Valid values of interval are the following keywords:
+SQL_TSI_FRAC_SECOND
+SQL_TSI_SECOND
+SQL_TSI_MINUTE
+SQL_TSI_HOUR
+SQL_TSI_DAY
+SQL_TSI_WEEK
+SQL_TSI_MONTH
+SQL_TSI_QUARTER
+SQL_TSI_YEAR
+where fractional seconds are expressed in billionths of a second. For example, the following SQL statement returns the name of each employee and the number of years he or she has been employed:
+SELECT NAME, {fn TIMESTAMPDIFF(SQL_TSI_YEAR, {fn CURDATE()}, HIRE_DATE)} FROM EMPLOYEES
+If either timestamp expression is a time value and interval specifies days, weeks, months, quarters, or years, the date portion of that timestamp is set to the current date before calculating the difference between the timestamps.
+If either timestamp expression is a date value and interval specifies fractional seconds, seconds, minutes, or hours, the time portion of that timestamp is set to 0 before calculating the difference between the timestamps.
+An application determines which intervals a data source supports by calling SQLGetInfo with the SQL_TIMEDATE_DIFF_INTERVALS option.
+
+>       ,CatCreateFunction "!odbc-timestampdiff" ["int4","time","time"] False "int4"
+>       ,CatCreateFunction "!odbc-timestampdiff" ["int4","date","date"] False "int4"
+>       ,CatCreateFunction "!odbc-timestampdiff" ["int4","timestamp","timestamp"] False "int4"]
+
+
+WEEK(date_exp) (ODBC 1.0)
+Returns the week of the year based on the week field in date_exp as an integer value in the range of 1–53.
+
+>       ++ [CatCreateFunction "!odbc-week" [d] False "int4" | d <- dateTypes]
+
+YEAR(date_exp) (ODBC 1.0)
+Returns the year based on the year field in date_exp as an integer value. The range is data source–dependent.
+
+>       ++ [CatCreateFunction "!odbc-year" [d] False "int4" | d <- dateTypes]
+
+system
+
+DATABASE( ) (ODBC 1.0)
+Returns the name of the database corresponding to the connection handle. (The name of the database is also available by calling SQLGetConnectOption with the SQL_CURRENT_QUALIFIER connection option.)
+
+>       ++ [CatCreateFunction "!odbc-database" [] False "varchar"]
+
+IFNULL(exp,value) (ODBC 1.0)
+If exp is null, value is returned. If exp is not null, exp is returned. The possible data type or types of value must be compatible with the data type of exp.
+
+>       ++ [CatCreateFunction "!odbc-ifnull" [t,t] False t | t <- allTypes]
+
+USER( ) (ODBC 1.0)
+Returns the user name in the DBMS. (The user name is also available by way of SQLGetInfo by specifying the information type: SQL_USER_NAME.) This can be different than the login name.
+
+>       ++ [CatCreateFunction "!odbc-user" [] False "varchar"]
+
+conversion function
+
+CONVERT(value_exp, data_type)
+The function returns the value specified by value_exp converted to the specified data_type, where data_type is one of the following keywords:
+SQL_BIGINT
+SQL_INTERVAL_HOUR_TO_MINUTE
+SQL_BINARY
+SQL_INTERVAL_HOUR_TO_SECOND
+SQL_BIT
+SQL_INTERVAL_MINUTE_TO_SECOND
+SQL_CHAR
+SQL_LONGVARBINARY
+SQL_DECIMAL
+SQL_LONGVARCHAR
+SQL_DOUBLE
+SQL_NUMERIC
+SQL_FLOAT
+SQL_REAL
+SQL_GUID
+SQL_SMALLINT
+SQL_INTEGER
+SQL_DATE
+SQL_INTERVAL_MONTH
+SQL_TIME
+SQL_INTERVAL_YEAR
+SQL_TIMESTAMP
+SQL_INTERVAL_YEAR_TO_MONTH
+SQL_TINYINT
+SQL_INTERVAL_DAY
+SQL_VARBINARY
+SQL_INTERVAL_HOUR
+SQL_VARCHAR
+SQL_INTERVAL_MINUTE
+SQL_WCHAR
+SQL_INTERVAL_SECOND
+SQL_WLONGVARCHAR
+SQL_INTERVAL_DAY_TO_HOUR
+SQL_WVARCHAR
+SQL_INTERVAL_DAY_TO_MINUTE
+ 
+SQL_INTERVAL_DAY_TO_SECOND
+
+
+>    ++ [CatCreateFunction "!odbc-convert" [t,"int4"] False t
+>       | t <- ["int2","int4","int8", "float4", "float8", "numeric"
+>              ,"date","time","timestamp","char","varchar","text"
+>              ,"bool"]
+>       ]
+>    where
+>      floatTypes = ["float4","float8"]
+>      numTypes = ["int2","int4","int8", "float4", "float8", "numeric"]
+>      -- if a numeric with a fraction part is used, then maybe
+>      -- it is a runtime error, or maybe the typechecker can understand this
+>      -- most of the time and give a compile error, or maybe
+>      -- it should cast it?
+>      intTypes = ["int2","int4","int8", "numeric"]
+>      timeTypes = ["time","timestamp"]
+>      dateTypes = ["date","timestamp"]
+>      allTypes = ["int2","int4","int8", "float4", "float8", "numeric"
+>                 ,"date","time","timestamp","char","varchar","text"
+>                 ,"bool"]
+
+TODO : all the weird ones are commented out. I couldn't find a clear
+reference on what the correspondence between the convert enum
+identifiers and sql types are. The interval ones are the most likely
+to be needed out of the commented out ones. Maybe they return smallint
+or int or something.
+
+> odbcConvertTypes :: [(String,Type)]
+> odbcConvertTypes = [("sql_bigint", typeBigInt)
+>                    ,("sql_float", typeFloat8)
+>                    --,("sql_interval_hour_to_minute", typeFloat8)
+>                    --,("sql_binary", $ ScalarType "unknown")
+>                    --,("sql_interval_hour_to_second", typeFloat8)
+>                    --,("sql_bit", $ ScalarType "unknown")
+>                    --,("sql_interval_minute_to_second", typeFloat8)
+>                    ,("sql_char", typeChar)
+>                    --,("sql_longvarbinary", $ ScalarType "unknown")
+>                    ,("sql_decimal", typeNumeric)
+>                    --,("sql_longvarchar", typeVarChar)
+>                    ,("sql_double", typeFloat8)
+>                    ,("sql_numeric", typeNumeric)
+>                    ,("sql_float", typeFloat8)
+>                    ,("sql_real", typeFloat4)
+>                    --,("sql_guid", $ ScalarType "unknown")
+>                    ,("sql_smallint", typeSmallInt)
+>                    ,("sql_integer", typeInt)
+>                    ,("sql_date", typeDate)
+>                    --,("sql_interval_month", typeFloat8)
+>                    ,("sql_time", ScalarType "time")
+>                    --,("sql_interval_year", typeFloat8)
+>                    ,("sql_timestamp", typeTimestamp)
+>                    --,("sql_interval_year_to_month", typeFloat8)
+>                    --,("sql_tinyint", $ ScalarType "unknown")
+>                    --,("sql_interval_day", typeFloat8)
+>                    --,("sql_varbinary", $ ScalarType "unknown")
+>                    --,("sql_interval_hour", typeFloat8)
+>                    ,("sql_varchar", typeVarChar)
+>                    --,("sql_interval_minute", typeFloat8)
+>                    --,("sql_wchar", $ ScalarType "unknown")
+>                    --,("sql_interval_second", typeFloat8)
+>                    --,("sql_wlongvarchar", typeVarChar)
+>                    --,("sql_interval_day_to_hour", typeFloat8)
+>                    --,("sql_wvarchar", $ ScalarType "unknown")
+>                    --,("sql_interval_day_to_minute", typeFloat8)
+>                    --,("sql_interval_day_to_second", typeFloat8)
+>                    ]
+
+> odbcIntervalTypes :: [String]
+> odbcIntervalTypes = ["sql_tsi_frac_second"
+>                     ,"sql_tsi_second"
+>                     ,"sql_tsi_minute"
+>                     ,"sql_tsi_hour"
+>                     ,"sql_tsi_day"
+>                     ,"sql_tsi_week"
+>                     ,"sql_tsi_month"
+>                     ,"sql_tsi_quarter"
+>                     ,"sql_tsi_year"]
diff --git a/src/Database/HsSqlPpp/Dialects/Oracle.lhs b/src/Database/HsSqlPpp/Dialects/Oracle.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Dialects/Oracle.lhs
@@ -0,0 +1,47 @@
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Dialects.Oracle (oracleDialect) where
+
+> import Database.HsSqlPpp.Internals.Dialect
+> import Database.HsSqlPpp.Dialects.Postgres
+
+Oracle is a very small hack based on postgres. This should be fixed
+after adding some more tests. It is particularly bad since we don't
+use oracle style 'numeric' for ints, so it is not very compatible with
+oracle (there are lots of other standard oracle types missing, which
+is probably the biggest issue at the moment.
+
+> oracleDialect :: Dialect
+> oracleDialect = Dialect
+>     {diName = "oracle"
+>     ,diSyntaxFlavour = Oracle
+>     ,diCanonicalTypeNames =  [("timestamp", ["datetime"])
+>                              -- todo: temp before sqlserver dialect is done properly
+>                              -- this hack should probably move to the ansi dialect first
+>                              ,("int1", ["tinyint"])
+>                              ,("int2", ["smallint"])
+>                              ,("int4", ["integer","int"])
+>                              ,("int8", ["bigint"])
+>                              ,("numeric", ["decimal"])
+>                              ,("float4", ["real"])
+>                              ,("float8", ["double precision","float","double"])
+>                              -- probably some missing here
+>                              ,("varchar", ["character varying"])
+>                              ,("char", ["character"])
+>                              ,("bool", ["boolean"])]
+>     ,diTextTypes = ["char","varchar","text"]
+>     ,diDatetimeTypes = ["date","time","timestamp","interval"]
+>     ,diNumberTypes = ["int2","int4","int8","numeric","float4","float8"]
+>     ,namesForAnsiTypes = [("char","char")
+>                          ,("varchar","varchar")
+>                          ,("bigint","int8")
+>                          ,("boolean","bool")
+>                          ,("numeric","numeric")
+>                          ,("int","int4")
+>                          ,("date","date")
+>                          ,("time","time")
+>                          ,("timestamp","timestamp")
+>                          ] -- todo: these are postgres names
+>     ,diDefaultCatalog = diDefaultCatalog postgresDialect
+>     }
+
diff --git a/src/Database/HsSqlPpp/Dialects/Postgres.lhs b/src/Database/HsSqlPpp/Dialects/Postgres.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Dialects/Postgres.lhs
@@ -0,0 +1,83 @@
+
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Dialects.Postgres (postgresDialect) where
+
+> import Database.HsSqlPpp.Internals.Dialect
+> import Database.HsSqlPpp.Dialects.GeneratedPostgres
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+> import Database.HsSqlPpp.Internals.Catalog.CatalogBuilder
+> import Database.HsSqlPpp.Dialects.OdbcCatalog
+> import Database.HsSqlPpp.Dialects.BaseCatalog
+
+> postgresDialect :: Dialect
+> postgresDialect = Dialect
+>     {diName = "postgres"
+>     ,diSyntaxFlavour = Postgres
+>     ,diCanonicalTypeNames =  [("timestamp", ["datetime"])
+>                              -- todo: temp before sqlserver dialect is done properly
+>                              -- this hack should probably move to the ansi dialect first
+>                              ,("int1", ["tinyint"])
+>                              ,("int2", ["smallint"])
+>                              ,("int4", ["integer","int"])
+>                              ,("int8", ["bigint"])
+>                              ,("numeric", ["decimal"])
+>                              ,("float4", ["real"])
+>                              ,("float8", ["double precision","float","double"])
+>                              -- probably some missing here
+>                              ,("varchar", ["character varying"])
+>                              ,("char", ["character"])
+>                              ,("bool", ["boolean"])]
+>     ,diTextTypes = ["char","varchar","text"]
+>     ,diDatetimeTypes = ["date","time","timestamp","interval"]
+>     ,diNumberTypes = ["int2","int4","int8","numeric","float4","float8"]
+>     ,namesForAnsiTypes = [("char","char")
+>                          ,("varchar","varchar")
+>                          ,("bigint","int8")
+>                          ,("boolean","bool")
+>                          ,("numeric","numeric")
+>                          ,("int","int4")
+>                          ,("date","date")
+>                          ,("time","time")
+>                          ,("timestamp","timestamp")
+>                          ] -- todo: finish this
+>     ,diDefaultCatalog = postgresCatalog
+>     }
+
+built in range types in postgresql
+
+todo: maybe these are in the catalog somewhere and should come from
+postgres?
+
+> postgresCatalog :: Catalog
+> postgresCatalog =
+>     (\l -> case l of
+>              Left x -> error $ show x
+>              Right e -> e) $
+>      flip updateCatalog emptyCatalog (
+>           nonSpecialPseudoTypes ++ rangeTypes ++ generatedPostgresCatalogEntries
+>           ++ extraDefs
+>           ++ baseCatalog "bool" "int4" ["char", "varchar", "text"]
+>           ++ odbcCatalog)
+>   where
+>      extraDefs = [CatCreateBinaryOp "=" "anyelement" "anyelement" "bool"
+>                  ,CatCreateVariadicFunction "arrayctor" ["anyelement"] False "anyarray"
+>                  ,CatCreateFunction "arraysub" ["anyarray","int4"] False "anyelement"
+>                  ,CatCreateVariadicFunction "greatest" ["anyelement"] False "anyelement"
+>                  ,CatCreateVariadicFunction "least" ["anyelement"] False "anyelement"
+>                  ] ++ concat [ [CatCreateBinaryOp "rlike" t t "bool"
+>                                ,CatCreateBinaryOp "notrlike" t t "bool"]
+>                                | t <- ["char", "varchar", "text"] ]
+>      rangeTypes = map CatCreateScalarType
+>                   ["int4range", "int8range"
+>                   ,"numrange","daterange"
+>                   ,"tsrange","tstzrange"]
+>      nonSpecialPseudoTypes = map CatCreateScalarType
+>                              ["cstring"
+>                              ,"trigger"
+>                              ,"event_trigger"
+>                              ,"_cstring"
+>                              ,"internal"
+>                              ,"language_handler"
+>                              ,"opaque"
+>                              ,"fdw_handler"]
diff --git a/src/Database/HsSqlPpp/Dialects/SqlServer.lhs b/src/Database/HsSqlPpp/Dialects/SqlServer.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Dialects/SqlServer.lhs
@@ -0,0 +1,161 @@
+
+> {-# LANGUAGE OverloadedStrings,ScopedTypeVariables #-}
+> module Database.HsSqlPpp.Dialects.SqlServer (sqlServerDialect) where
+
+> import Database.HsSqlPpp.Internals.Dialect
+> import Database.HsSqlPpp.Internals.Catalog.CatalogBuilder
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+> --import Database.HsSqlPpp.Dialects.BaseCatalog
+> import Database.HsSqlPpp.Dialects.Postgres
+> --import Database.HsSqlPpp.Internals.Dialect
+> --import Data.List
+> import Data.Generics.Uniplate.Data
+
+The sql server dialect is a crap modification to the postgresql
+dialect at the moment.  After a bunch more tests are written, it
+should be reimplemented separately from scratch
+
+> sqlServerDialect :: Dialect
+> sqlServerDialect = Dialect
+>     {diName = "sqlServer"
+>     ,diSyntaxFlavour = SqlServer
+>     ,diCanonicalTypeNames =  [("timestamp", ["datetime"])
+>                              -- todo: temp before sqlserver dialect is done properly
+>                              -- this hack should probably move to the ansi dialect first
+>                              ,("int1", ["tinyint"])
+>                              ,("int2", ["smallint"])
+>                              ,("int4", ["integer","int"])
+>                              ,("int8", ["bigint"])
+>                              ,("float4", ["real"])
+>                              ,("float8", ["double precision","float","double"])
+>                              -- probably some missing here
+>                              ,("varchar", ["character varying"])
+>                              ,("char", ["character"])
+>                              ,("bool", ["boolean"])]
+>     ,diTextTypes = ["char","varchar", "nvarchar"]
+>     ,diDatetimeTypes = ["date","time","timestamp","interval"]
+>     ,diNumberTypes = ["int2","int4","int8","numeric","float4","float8"]
+>     ,namesForAnsiTypes = [("char","char")
+>                          ,("varchar","varchar")
+>                          ,("nvarchar","nvarchar")
+>                          ,("bigint","int8")
+>                          ,("boolean","bool")
+>                          ,("numeric","numeric")
+>                          ,("int","int4")
+>                          ,("date","date")
+>                          ,("time","time")
+>                          ,("timestamp","timestamp")
+>                          ] -- todo: these are postgres names
+>     ,diDefaultCatalog = tsqlCatalog
+>     }
+
+> tsqlCatalog :: Catalog
+> tsqlCatalog = either (error . show) id catr
+>   where
+>     catr = updateCatalog
+>               (alterUpdates (deconstructCatalog
+>                              (diDefaultCatalog postgresDialect)
+>                              ++ additionalEntries))
+>               emptyCatalog
+>     -- change the counts to return int instead of long
+>     alterUpdates = map $ \u -> case u of
+>         CatCreateAggregate "count" ["any"] "int8" ->
+>             CatCreateAggregate "count" ["any"] "int4"
+>         CatCreateAggregate f [e] _ | f `elem` ["sum","avg"]
+>                                    , e `elem` ["int1"
+>                                               ,"int2"
+>                                               ,"int4"] ->
+>             CatCreateAggregate f [e] "int4"
+>         CatCreateAggregate f ["float4"] _ | f `elem` ["sum","avg"] ->
+>             CatCreateAggregate f ["float4"] "float8"
+>         CatCreateAggregate f ["int8"] _ | f `elem` ["sum","avg"] ->
+>             CatCreateAggregate f ["int8"] "int8"
+>         _ -> u
+
+>     additionalEntries =
+>         int1fns ++
+>         int12fns ++
+>         [CatCreateScalarType "nvarchar"
+>         ,CatCreateTypeCategoryEntry "nvarchar" ("S", False)
+>         ,CatCreateBinaryOp "+" "varchar" "varchar" "varchar"
+>         ,CatCreateFunction "getdate" [] False "timestamp"
+>         ,CatCreateFunction "isnumeric" ["anyelement"] False "int4"
+>         ,CatCreateFunction "grt_lengthconv" ["int4"] False "int4"
+>         ,CatCreateFunction "isnull" ["anyelement","anyelement"] False "anyelement"
+>         -- put these in to stop use the text only version and a bunch of casts
+>         ,CatCreateFunction "replace" ["char", "char", "char"] False "char"
+>         ,CatCreateFunction "replace" ["varchar", "varchar", "varchar"] False "varchar"
+>         ,CatCreateFunction "replace" ["nvarchar", "nvarchar", "nvarchar"] False "nvarchar"
+>         ,CatCreateFunction "patindex" ["char","char"] False "int4"
+>         ,CatCreateFunction "patindex" ["varchar","varchar"] False "int4"
+>         ,CatCreateFunction "patindex" ["nvarchar","nvarchar"] False "int4"
+>         ,CatCreateFunction "isdate" ["varchar"] False "bool"
+>         ,CatCreateFunction "isdate" ["char"] False "int4"
+>         ,CatCreateFunction "isdate" ["nvarchar"] False "int4"
+>         ,CatCreateFunction "len" ["nvarchar"] False "int4"
+>         ,CatCreateFunction "len" ["varchar"] False "int4"
+>         ,CatCreateAggregate "count_big" ["any"] "int8"
+>         ,CatCreateFunction "datediff" ["int4","date","date"] False "int4"
+>         ,CatCreateFunction "datediff" ["int4","timestamp","timestamp"] False "int4"
+>         ,CatCreateFunction "dateadd" ["int4","int4","date"] False "date"
+>         ,CatCreateFunction "dateadd" ["int4","int4","timestamp"] False "timestamp"
+>         ,CatCreateFunction "datepart" ["int4","date"] False "int4"
+>         ,CatCreateFunction "datepart" ["int4","timestamp"] False "int4"
+>         ,CatCreateFunction "trunc" ["timestamp"] False "timestamp"
+>         ,CatCreateCast "char" "varchar" ImplicitCastContext
+
+>         ,CatCreateFunction "substring" ["nvarchar","int4","int4"] False "nvarchar"
+>         ,CatCreateFunction "like" [ "nvarchar" , "nvarchar" ] False "bool"
+
+postponed until we have better design
+  example of a problem: in "float4 < int4", both arguments are cast to text,
+  because it has higher priority (see CatCreateTypeCategoryEntry)
+
+>         --,CatCreateCast "int1" "varchar" ImplicitCastContext
+>         --,CatCreateCast "int2" "varchar" ImplicitCastContext
+>         --,CatCreateCast "int4" "varchar" ImplicitCastContext
+>         --,CatCreateCast "int8" "varchar" ImplicitCastContext
+>         --,CatCreateCast "float4" "varchar" ImplicitCastContext
+>         --,CatCreateCast "float8" "varchar" ImplicitCastContext
+>         --,CatCreateCast "int1" "text" ImplicitCastContext
+>         --,CatCreateCast "int2" "text" ImplicitCastContext
+>         --,CatCreateCast "int4" "text" ImplicitCastContext
+>         --,CatCreateCast "int8" "text" ImplicitCastContext
+>         --,CatCreateCast "float4" "text" ImplicitCastContext
+>         --,CatCreateCast "float8" "text" ImplicitCastContext
+>         ]
+>     -- find all the functions on int2 and replace int2 with int1
+>     -- then find all the functions with int2 and int4, and
+>     -- replace int2 with int1 and int4 with int2
+>     -- really hacky
+>     int1fns = let s = filter (\x -> replaceItp x && hasInt2 x)
+>                              (deconstructCatalog (diDefaultCatalog postgresDialect))
+>               in flip transformBi s $ \x -> case (x :: CatName) of
+>                                        "int2" -> "int1"
+>                                        _ -> x
+>     int12fns = let s = filter (\x -> replaceItp x && hasInt2Int4 x)
+>                               (deconstructCatalog (diDefaultCatalog postgresDialect))
+>                in flip transformBi s $ \x -> case (x :: CatName) of
+>                                        "int2" -> "int1"
+>                                        "int4" -> "int2"
+>                                        _ -> x
+>     hasInt2 x = not $ null [() | ("int2" :: CatName) <- universeBi x]
+>     hasInt2Int4 x = not $ null [() | ("int2" :: CatName) <- universeBi x
+>                                    , ("int4" :: CatName) <- universeBi x]
+>     replaceItp x = case x of
+>                      CatCreateScalarType {} -> True
+>                      CatCreateArrayType {} -> True
+>                      CatCreatePrefixOp {} -> True
+>                      CatCreateBinaryOp {} -> True
+>                      CatCreateFunction f _ _ _ | f `elem` ["abs","float4","float8","int2","int4","mod","numeric"] -> True
+>                      CatCreateAggregate f _ _ | f `elem` ["avg","max","min","sum"] -> True
+>                      CatCreateCast a b _ | a == "int2" || b == "int2" -> True
+>                      CatCreateTypeCategoryEntry {} -> True
+>                      _ -> False
+
+comparisons with all ints
+abs
+cast functions
+avg to numeric max min sum
+catcreatecast: float4,float8, int4,int8,numeric, from
+
diff --git a/src/Database/HsSqlPpp/Internals/AnnotationUtils.lhs b/src/Database/HsSqlPpp/Internals/AnnotationUtils.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Internals/AnnotationUtils.lhs
+++ /dev/null
@@ -1,28 +0,0 @@
-
-This module contains some utilities and generic code for working with
-asts and annotations which depend on the ast types.
-
-> {-# LANGUAGE ScopedTypeVariables #-}
->
-> module Database.HsSqlPpp.Internals.AnnotationUtils
->     (
->      getStatementAnnotations
->     ,resetAnnotations
->     ) where
->
-> import Data.Data
-> import Data.Generics.Uniplate.Data
->
-> import Database.HsSqlPpp.Internals.AstInternal
-> import Database.HsSqlPpp.Internals.AstAnnotation
->
-> -- | Run through the ast and return all the annotations attached to
-> --   a Statement node.
-> getStatementAnnotations :: Data a => a -> [Annotation]
-> getStatementAnnotations st =
->     [getAnnotation s | (s::Statement) <- universeBi st]
-
-> -- | Set all the annotations in a tree to be 'emptyAnnotation'.
-> resetAnnotations :: Data a => a -> a
-> resetAnnotations =
->     updateAnnotations (const emptyAnnotation)
diff --git a/src/Database/HsSqlPpp/Internals/AstAnnotation.lhs b/src/Database/HsSqlPpp/Internals/AstAnnotation.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Internals/AstAnnotation.lhs
+++ /dev/null
@@ -1,193 +0,0 @@
-
-The annotation data types and utilities for working with them.
-
-Annotations are used to store source positions, types, errors,
-warnings, catalog deltas, information, and other stuff a client might
-want to use when looking at an ast. Internal annotations which are
-used in the type-checking/ annotation process use the attribute
-grammar code and aren't exposed.
-
-> {-# LANGUAGE DeriveDataTypeable,ScopedTypeVariables  #-}
->
-> module Database.HsSqlPpp.Internals.AstAnnotation
->     (
->      Annotation(..)
->     ,SourcePosition
->     ,ParameterizedStatementType
->     ,getAnnotation
->     ,updateAnnotations
->     ,getAnnotations
->     ,emptyAnnotation
->     ,getTypeAnnotation
->     ,updateAnnotation
->     ) where
->
-> import Data.Generics
-> ---import Control.Arrow
-> import Data.Generics.Uniplate.Data
-> --import Debug.Trace
->
-> import Database.HsSqlPpp.Internals.TypeType
-> import Database.HsSqlPpp.Internals.Catalog.CatalogInternal
-> --import Database.HsSqlPpp.Utils.Utils
->
-> -- | Represents a source file position, usually set by the parser.
-> type SourcePosition = (String,Int,Int)
-> -- | Statement type is used for getting type information for a parameterized statement.
-> type ParameterizedStatementType = ([Type],[(String,Type)])
-
-> -- | Annotation type - one of these is attached to most of the
-> -- data types used in the ast.
-> data Annotation = Annotation { -- | source position for this node
->                               asrc :: Maybe SourcePosition
->                                -- | type of the node, 'Nothing' if the tree hasn't been typechecked or if a type error prevents determining the type
->                              ,atype :: Maybe Type
->                                -- | any type errors
->                              ,errs :: [TypeError]
->                                -- | used for getting the in and out types of a parameterized statement
->                              ,stType :: Maybe ParameterizedStatementType
->                                -- | any catalog updates that a ddl statement produces
->                              ,catUpd :: [CatalogUpdate]
->                                -- | the matched function prototype for a funcall
->                              ,fnProt :: Maybe FunctionPrototype
->                                -- | 'inferred' type - fake type inference used for getting the type of ? placeholders in parameterized statements
->                              ,infType :: Maybe Type}
->                   deriving (Eq, Show,Typeable,Data)
->
-> -- | An annotation value with no information.
-> emptyAnnotation :: Annotation
-> emptyAnnotation = Annotation Nothing Nothing [] Nothing [] Nothing Nothing
-
-> -- | get the annotation for the root element of the tree passed
-> getAnnotation :: Data a => a -> Annotation
-> getAnnotation = head . childrenBi
-
-> -- | get all the annotations from a tree
-> getAnnotations :: Data a => a -> [Annotation]
-> getAnnotations = universeBi -- st --[x | x <- universeBi st]
-
-> -- | update all the annotations in a tree
-> updateAnnotations :: Data a => (Annotation -> Annotation) -> a -> a
-> updateAnnotations = transformBi
-
-> getTypeAnnotation :: Data a => a -> Maybe Type
-> getTypeAnnotation = atype . getAnnotation
-
-
-
-
-
-Use syb/uniplate to pull annotation values from an ast.
-
-I like to cut and paste code from the internet which I don't
-understand, then keep changing it till it compiles and passes the tests.
-
-> {- -- | run through the ast, and pull the type annotation from each
-> -- of the top level items.
-> getTypeAnnotation :: (Show a, Data a) => a -> Type
-> getTypeAnnotation st =
->     typeAnnot $ getTopLevelAnnotation st
->     where
->       typeAnnot :: Annotation -> Type
->       typeAnnot (x:xs) = case x of
->                                 TypeAnnotation t -> t
->                                 _ -> typeAnnot xs
->       typeAnnot [] = TypeCheckFailed -- error "couldn't find type annotation"
->
-> -- | Run through the ast given and return a list of statementtypes
-> -- from the top level items.
-> getTopLevelInfos :: Data a => [a] -> [Maybe StatementType]
-> getTopLevelInfos = map (getSIAnnotation . getTopLevelAnnotation)
->
-> getTopLevelCatUpdates ::  Data a => [a] -> [[CatalogUpdate]]
-> getTopLevelCatUpdates = map (getEuAnnotation . getTopLevelAnnotation)
->
-
-> -- | runs through the ast given and returns a list of all the type errors
-> -- in the ast. Recurses into all ast nodes to find type errors.
-> -- This is the function to use to see if an ast has passed the type checking process.
-> -- Returns a Maybe SourcePos and the list of type errors for each node which has one or
-> -- more type errors.
-> getTypeErrors :: (Data a) => a -> [(Maybe AnnotationElement,[TypeError])]
-> getTypeErrors sts =
->     filter (\(_,te) -> not $ null te) $ map (gtsp &&& gte) $ getAnnotations sts
->     where
->       gte (a:as) = case a of
->                     TypeErrorA e -> e:gte as
->                     _ -> gte as
->       gte _ = []
->       gtsp (a:as) = case a of
->                     s@(SourcePos _ _ _) -> Just s
->                     _ -> gtsp as
->       gtsp _ = Nothing
-
-~~~~
-question:
-if a node has no source position e.g. the all in select all or select
-   distinct may correspond to a token or may be synthesized as the
-   default if neither all or distinct is present. Should this have the
-   source position of where the token would have appeared, should it
-   inherit it from its parent, should there be a separate ctor to
-   represent a fake node with no source position?
-
-~~~~
-
-hack job, often not interested in the source positions when testing
-the asts produced, so this function will reset all the source
-positions to empty ("", 0, 0) so you can compare them for equality, etc.
-without having to get the positions correct.
-
-> -}
-
- > -- | strip all the annotations from a tree. E.g. can be used to compare
- > -- two asts are the same, ignoring any source position annotation differences.
- > stripAnnotations :: Data a => a -> a
- > stripAnnotations = filterAnnotations (const False)
- >
-
- > filterAnnotations :: Data a => (Annotation -> Bool) -> a -> a
- > filterAnnotations f = transformBi (filter f)
-
->
-> -- | Update the first annotation in a tree using the function supplied
-> updateAnnotation :: Data a => (Annotation -> Annotation) -> a -> a
-> updateAnnotation f = gmapT (mkT f)
->
-
-
- >   case gmapQ (mkQ [] f) a of
- >     an:_ -> an
- >     [] -> []
- >   where
- >     f :: Annotation -> Annotation
- >     f = id
- >
-
- >
- > getAnnotations :: Data a => a -> [Annotation]
- > getAnnotations = listifyWholeLists (\(_::Annotation) -> True)
- >
-
-> {-getSIAnnotation :: Annotation -> Maybe StatementType
-> getSIAnnotation (x:xs) = case x of
->                                 StatementTypeA t -> Just t
->                                 _ -> getSIAnnotation xs
-> getSIAnnotation []  = Nothing
->
-> getEuAnnotation :: Annotation -> [CatalogUpdate]
-> getEuAnnotation (x:xs) = case x of
->                                 CatUpdates t -> t
->                                 _ -> getEuAnnotation xs
-> getEuAnnotation [] = []-}
-
--------------------------------------------------------------------------------
-
-utils
-
- > listifyWholeLists :: Typeable b => ([b] -> Bool) -> GenericQ [[b]]
- > listifyWholeLists blp = flip (synthesize id (.) (mkQ id (\bl _ -> if blp bl then (bl:) else id))) []
-
-this might need to be maybe and change head?
-
- > getTopLevelAnnotation :: Data a => a -> Annotation
- > getTopLevelAnnotation st = head $ childrenBi st
diff --git a/src/Database/HsSqlPpp/Internals/AstInternal.hs b/src/Database/HsSqlPpp/Internals/AstInternal.hs
--- a/src/Database/HsSqlPpp/Internals/AstInternal.hs
+++ b/src/Database/HsSqlPpp/Internals/AstInternal.hs
@@ -1,15347 +1,29957 @@
 
 
--- UUAGC 0.9.39.1 (src/Database/HsSqlPpp/Internals/AstInternal.ag)
-{-# LANGUAGE DeriveDataTypeable,ScopedTypeVariables #-}
-module Database.HsSqlPpp.Internals.AstInternal(
-    --from the ag files:
-    --ast nodes
-    Statement (..)
-   ,QueryExpr (..)
-   ,WithQueryList
-   ,WithQuery(..)
-   ,FnBody (..)
-   ,SetClause (..)
-   ,SetClauseList
-   ,TableRef (..)
-   ,TableAlias(..)
-   ,JoinExpr (..)
-   ,JoinType (..)
-   ,SelectList (..)
-   ,SelectItem (..)
-   ,CopySource (..)
-   ,AttributeDef (..)
-   ,RowConstraint (..)
-   ,AlterTableAction(..)
-   ,Constraint (..)
-   ,TypeAttributeDef (..)
-   ,ParamDef (..)
-   ,VarDef (..)
-   ,RaiseType (..)
-   ,CombineType (..)
-   ,Volatility (..)
-   ,Language (..)
-   ,TypeName (..)
-   ,DropType (..)
-   ,Cascade (..)
-   ,Direction (..)
-   ,Distinct (..)
-   ,Natural (..)
-   ,IfExists (..)
-   ,Replace(..)
-   ,RestartIdentity (..)
-   ,ScalarExpr (..)
-   ,Name(..)
-   ,NameComponent(..)
-   ,ncStr
-   ,IntervalField(..)
-   ,ExtractField(..)
-   ,FrameClause(..)
-   ,InList (..)
-   ,LiftFlavour(..)
-   ,TriggerWhen(..)
-   ,TriggerEvent(..)
-   ,TriggerFire(..)
-   ,StatementList
-   ,ScalarExprListStatementListPairList
-   ,ScalarExprListStatementListPair
-   ,ScalarExprList
-   ,ParamDefList
-   ,AttributeDefList
-   ,ConstraintList
-   ,TypeAttributeDefList
-   ,TypeNameList
-   ,NameTypeNameListPair
-   ,NameTypeNameListPairList
-   ,ScalarExprStatementListPairList
-   --,SetClauseList
-   ,CaseScalarExprListScalarExprPairList
-   ,MaybeScalarExpr
-   ,TableRefList
-   ,ScalarExprListList
-   ,SelectItemList
-   ,OnExpr
-   ,RowConstraintList
-   ,VarDefList
-   ,ScalarExprStatementListPair
-   ,CaseScalarExprListScalarExprPair
-   ,ScalarExprDirectionPair
-   ,ScalarExprDirectionPairList
-   ,MaybeBoolExpr
-   ,MaybeSelectList
-   ,SetValue(..)
-   ,AlterTableActionList
-   ,NameComponentList
-   ,MaybeNameComponentList
-   -- typechecking
-   ,typeCheckStatements
-   ,typeCheckParameterizedStatement
-   ,typeCheckScalarExpr
-   ,typeCheckQueryExpr
-   ,fixUpIdentifiers
-   ,fixUpIdentifiersQE
-   ,fixUpIdentifiersSE
-) where
-
-import Data.Maybe
-import Data.Either
-import Data.List
-import Control.Applicative
-import Data.Data
-import Data.Char
-import Control.Monad.State
-import Control.Arrow
-
-import Data.Generics.Uniplate.Data
-import Debug.Trace
---import Text.Groom
-
-
-import Database.HsSqlPpp.Internals.TypeType
-import Database.HsSqlPpp.Internals.TypeChecking.TypeConversion
-import Database.HsSqlPpp.Internals.AstAnnotation
-import Database.HsSqlPpp.Internals.Catalog.CatalogInternal
-import Database.HsSqlPpp.Internals.TypeChecking.LocalBindings
-import Database.HsSqlPpp.Internals.TypeChecking.ErrorUtils
-import Database.HsSqlPpp.Utils.Utils
-import Database.HsSqlPpp.Internals.TypeChecking.IDEnv
-
-
-
-data NameComponent = Nmc String
-                   | QNmc String -- quoted
-                     deriving (Data,Eq,Show,Typeable)
--- this is a transition function
--- it should be removed when ready, since all the code
--- should be working with NameComponents directly
-ncStr :: NameComponent -> String
-ncStr (Nmc n) = n
-ncStr (QNmc n) = n
-
-
-data JoinType = Inner | LeftOuter| RightOuter | FullOuter | Cross
-                deriving (Show,Eq,Typeable,Data)
-
-
-data CopySource = CopyFilename String
-                | Stdin
-                  deriving (Show,Eq,Typeable,Data)
-
-
-data SetValue
-    = SetStr Annotation String
-    | SetId Annotation String
-    | SetNum Annotation Double
-      deriving (Show,Eq,Typeable,Data)
-
-
-data TriggerWhen = TriggerBefore | TriggerAfter
-                   deriving (Show,Eq,Typeable,Data)
-data TriggerEvent = TInsert| TUpdate | TDelete | AntiTriggerEvent String
-                    deriving (Show,Eq,Typeable,Data)
-data TriggerFire = EachRow | EachStatement
-                   deriving (Show,Eq,Typeable,Data)
-
-
-data RaiseType = RNotice | RException | RError
-                 deriving (Show,Eq,Typeable,Data)
-
-data CombineType = Except | Union | Intersect | UnionAll
-                   deriving (Show,Eq,Typeable,Data)
-
-data Volatility = Volatile | Stable | Immutable
-                  deriving (Show,Eq,Typeable,Data)
-
-data Language = Sql | Plpgsql
-                deriving (Show,Eq,Typeable,Data)
-
-
-data DropType = Table
-              | Domain
-              | View
-              | Type
-                deriving (Show,Eq,Typeable,Data)
-
-data Cascade = Cascade | Restrict
-               deriving (Show,Eq,Typeable,Data)
-
-data Direction = Asc | Desc
-                 deriving (Show,Eq,Typeable,Data)
-
-data Distinct = Distinct | Dupes
-                deriving (Show,Eq,Typeable,Data)
-
-data Natural = Natural | Unnatural
-               deriving (Show,Eq,Typeable,Data)
-
-data IfExists = Require | IfExists
-                deriving (Show,Eq,Typeable,Data)
-
-data Replace = Replace | NoReplace
-               deriving (Show,Eq,Typeable,Data)
-
-data RestartIdentity = RestartIdentity | ContinueIdentity
-                       deriving (Show,Eq,Typeable,Data)
-
-
-
-data LiftFlavour = LiftAny | LiftAll
-                   deriving (Show,Eq,Typeable,Data)
-
-data IntervalField = IntervalYear
-                   | IntervalMonth
-                   | IntervalDay
-                   | IntervalHour
-                   | IntervalMinute
-                   | IntervalSecond
-                   | IntervalYearToMonth
-                   | IntervalDayToHour
-                   | IntervalDayToMinute
-                   | IntervalDayToSecond
-                   | IntervalHourToMinute
-                   | IntervalHourToSecond
-                   | IntervalMinuteToSecond
-                     deriving (Show,Eq,Typeable,Data)
-
-data ExtractField = ExtractCentury
-                  | ExtractDay
-                  | ExtractDecade
-                  | ExtractDow
-                  | ExtractDoy
-                  | ExtractEpoch
-                  | ExtractHour
-                  | ExtractIsodow
-                  | ExtractIsoyear
-                  | ExtractMicroseconds
-                  | ExtractMillennium
-                  | ExtractMilliseconds
-                  | ExtractMinute
-                  | ExtractMonth
-                  | ExtractQuarter
-                  | ExtractSecond
-                  | ExtractTimezone
-                  | ExtractTimezoneHour
-                  | ExtractTimezoneMinute
-                  | ExtractWeek
-                  | ExtractYear
-                    deriving (Show,Eq,Typeable,Data)
-
-
-
-data FrameClause = FrameUnboundedPreceding
-                 | FrameUnboundedFull
-                 | FrameRowsUnboundedPreceding
-                   deriving (Show,Eq,Typeable,Data)
-
-
--- | Takes an ast, checks against catalog passed, and adds
---   annotations, including types, type errors, and statement info.
---   Returns the updated catalog as well as the annotated ast.
-typeCheckStatements :: Catalog -> [Statement] -> (Catalog,[Statement])
-typeCheckStatements cat sts =
-    let t = sem_Root (Root $ fixUpIdentifiers cat sts)
-        ta = wrap_Root t Inh_Root {cat_Inh_Root = cat
-                                  ,lib_Inh_Root = emptyBindings
-                                  ,idenv_Inh_Root = emptyIDEnv "tcs"}
-        tl = annotatedTree_Syn_Root ta
-        cat1 = producedCat_Syn_Root ta
-    in case tl of
-         Root r -> (cat1,r)
-
-typeCheckQueryExpr :: Catalog -> QueryExpr -> QueryExpr
-typeCheckQueryExpr cat qe =
-   let (_,[QueryStatement _ qe']) = typeCheckStatements cat [QueryStatement emptyAnnotation qe]
-   in qe'
-
--- | Unfinished version of type check which can type check an
--- individual statement with ? or positional arg placeholders in
--- it. Will error if the statement isn't select, update, insert or
--- delete. For use in type checking embedded parameterized
--- statements. Does all typechecking and annotation that the regular
--- typecheck does.
-typeCheckParameterizedStatement :: Catalog -> Statement -> Either String Statement
-typeCheckParameterizedStatement cat st =
-    case st of
-      QueryStatement _ _ -> tc
-      Insert _ _ _ _ _ -> tc
-      Update _ _ _ _ _ _ -> tc
-      Delete _ _ _ _ _ -> tc
-      _ -> Left "requires select, update, insert or delete statement"
-    where
-      tc = let t = sem_Root (Root $ fixUpIdentifiers cat [st])
-               ta = wrap_Root t Inh_Root {cat_Inh_Root = cat
-                                         ,lib_Inh_Root = emptyBindings
-                                         ,idenv_Inh_Root = emptyIDEnv "tsps"}
-               tl = annotatedTree_Syn_Root ta
-               --cat1 = producedCat_Syn_Root ta
-           in case tl of
-                Root [st1] -> Right st1
-                _ -> error "impossible happened in typeCheckPS!"
-
-
--- | Testing utility, mainly used to check an expression for type errors
--- or to get its type.
-typeCheckScalarExpr :: Catalog -> ScalarExpr -> ScalarExpr
-typeCheckScalarExpr cat ex =
-    let t = sem_ScalarExprRoot (ScalarExprRoot $ fixUpIdentifiersSE cat ex)
-        rt = (annotatedTree_Syn_ScalarExprRoot
-              (wrap_ScalarExprRoot t Inh_ScalarExprRoot {cat_Inh_ScalarExprRoot = cat
-                                                        ,lib_Inh_ScalarExprRoot = emptyBindings
-                                                        ,idenv_Inh_ScalarExprRoot = emptyIDEnv "tcse"}))
-    in case rt of
-         ScalarExprRoot e -> e
-
-
-
-{-
-
-get alias: want to return the fullest alias possible at each stage
-if all the columns have the same qualifier, then this is a full alias
-if they don't, then has to be no alias
-
--}
-getEnvAlias :: IDEnv -> TableAlias
-getEnvAlias i =
-  case expandStar i Nothing of
-       Just is'@((q,_):_) | all (==q) $ map fst is' ->
-            FullAlias emptyAnnotation (Nmc q) $ map (Nmc . snd) is'
-       _ -> NoAlias emptyAnnotation
-
-
-aliasEnv :: TableAlias -> IDEnv -> IDEnv
-aliasEnv (NoAlias _) ids = ids
-aliasEnv (TableAlias _ t) ids = TableAliasIDEnv (ncStr t) ids
-aliasEnv (FullAlias _ t cs) ids = FullAliasIDEnv (ncStr t) (map ncStr cs) ids
-
-
-getTableTrefEnv :: Catalog -> Name -> IDEnv
-getTableTrefEnv cat si =
-    let tn = getTName si
-        (pus,pvs) = either (const ([],[])) id
-                    $ catCompositeAttrsPair cat relationComposites tn
-    in TrefIDEnv tn (map fst pus) (map fst pvs)
-
-
-
-
-makeSelExps :: Annotation -> Annotation -> Annotation -> [(String,String)] -> [SelectItem]
-makeSelExps sea a0 a1 is =
-  flip map is $ \(q,c) -> addSIAlias $ SelExp sea $ QIdentifier a0 [Nmc q,Nmc c]
-
-addSIAlias :: SelectItem -> SelectItem
-addSIAlias s@(SelectItem _ _ _) = s
-addSIAlias (SelExp ann ex) = SelectItem ann ex $ getColName ex
-  where
-    getColName :: ScalarExpr -> NameComponent
-    getColName (Identifier _ i) = i
-    getColName (QIdentifier _ is) = last is
-    getColName (FunCall _ f@(Name _ ncs) _) | not (isOperatorName $ getTName f) = last ncs
-    getColName (Cast _ _ (SimpleTypeName _ tn)) = QNmc tn
-    getColName (WindowFn _ (FunCall _ f@(Name _ ncs) _) _ _ _) = last ncs
-    getColName (AggregateFn _ _ (FunCall _ f@(Name _ ncs) _) _) = last ncs
-    getColName _ = QNmc "?column?"
-
-
-
-
-
-
-
-
--- | transform the tree by converting * to explicit lists of columns and adding qualifiers to all column references
-fixUpIdentifiers :: Catalog -> [Statement] -> [Statement]
-fixUpIdentifiers cat sts =
-    let t = sem_Root (Root sts)
-        ta = wrap_Root t Inh_Root {cat_Inh_Root = cat
-                                  ,lib_Inh_Root = emptyBindings
-                                  ,idenv_Inh_Root = emptyIDEnv "fixupidentifiers [st]"}
-        tl = fixedUpIdentifiersTree_Syn_Root ta
-    in case tl of
-         Root r -> countHack r
-
-fixUpIdentifiersSE :: Catalog -> ScalarExpr -> ScalarExpr
-fixUpIdentifiersSE cat sts =
-    let t = sem_ScalarExprRoot (ScalarExprRoot sts)
-        ta = wrap_ScalarExprRoot t Inh_ScalarExprRoot {cat_Inh_ScalarExprRoot = cat
-                                  ,lib_Inh_ScalarExprRoot = emptyBindings
-                                  ,idenv_Inh_ScalarExprRoot = emptyIDEnv "fixupidentifiers se"}
-        tl = fixedUpIdentifiersTree_Syn_ScalarExprRoot ta
-    in case tl of
-         ScalarExprRoot r -> countHack r
-
-fixUpIdentifiersQE :: Catalog -> QueryExpr -> QueryExpr
-fixUpIdentifiersQE cat qe =
-    let [QueryStatement _ qe'] = fixUpIdentifiers cat [QueryStatement emptyAnnotation qe]
-    in countHack qe'
-
-{-
-
-small hack to convert count(*) into count(True).
-
-The fix is: when typechecking, just use a hack to typecheck an
-aggregate call with a single * as the argument as if it had no
-arguments.
-
--}
-countHack :: Data a => a -> a
-countHack = transformBi $ \x -> case x of
-              FunCall a f [Star ia] | getTName f == "count"->
-                FunCall a f [BooleanLit ia True]
-              x1 -> x1
-
-
-
-showit :: Show a => String -> a -> a
-showit a t = trace (a ++ show t ++ "\n\n") t
-
-
-getUnqual :: [NameComponent] -> String
-getUnqual [] = error $ "empty name component"
-getUnqual x = ncStr $ last x
-
-
-
-addTypeErrors :: Data a => [TypeError] -> a -> a
-addTypeErrors es el = updateAnnotation u el
-                      where
-                        u a = a {errs = errs a ++ es}
-
-setTypeAddErrors :: Data a => Et -> a -> a
-setTypeAddErrors et el = updateAnnotation (setTypeAddErrorsA et) el
-
-setTypeAddErrorsA :: Et -> Annotation -> Annotation
-setTypeAddErrorsA et a =
-    let a1 = a {errs = errs a ++ tes et}
-    in case atype a1 of
-         Just _ -> a1 {errs = errs a
-                             ++ [InternalError $ "tried to set type a second time - " ++ show (etmt et)]}
-         Nothing -> a1 {atype = etmt et}
-
-allJust :: [Maybe a] -> Maybe [a]
-allJust ts = sequence ts
-
--- bit dogdy, needs some thought
--- this is just to convert the new approach of using "." as an operator
--- to construct names, with the old approach which stuck the whole lot
--- in a string
-getName :: ScalarExpr -> String
-getName (Identifier _ i) = ncStr i
-getName (FunCall _ f [Identifier _ _,Identifier _ i]) | getTName f == "." = ncStr i
-getName (FunCall _ f [_,a]) | getTName f == "." = getName a
-getName x = error $ "internal error getName called on: " ++ show x
-
-getTName :: Name -> String
-getTName (Name _ n) = getUnqual n
---getTName x = error $ "internal error getName called on: " ++ show x
-
-
-unwrapLookup :: (String,[String],Type) -> Type
-unwrapLookup (_,_,t) = t
-
-allAtts :: ([(String,Type)],[(String,Type)]) -> [(String,Type)]
-allAtts (a,b) = a ++ b
-
-
-
-typeCheckValuesExpr :: Catalog -> [[Maybe Type]] -> Either [TypeError] Type
-typeCheckValuesExpr cat rowsTs = do
-        rts <- lmt $ allJust $ map allJust rowsTs
-        let colNames = zipWith (++)
-                           (repeat "column")
-                           (map show [1..length $ head rowsTs])
-        unionRelTypes cat rts colNames
-
-
-typeCheckCombineSelect :: Catalog -> Type -> Type -> Either [TypeError] Type
-typeCheckCombineSelect cat v1 v2 = do
-    u1 <- unwrapSetOfComposite v1
-    let colNames = map fst u1
-    u2 <- unwrapSetOfComposite v2
-    let colTypes1 = map snd u1
-    let colTypes2 = map snd u2
-    unionRelTypes cat [colTypes1,colTypes2] colNames
-
-unionRelTypes :: Catalog -> [[Type]] -> [String] -> Either [TypeError] Type
-unionRelTypes cat rowsTs colNames =
-  let lengths = map length rowsTs
-  in case () of
-             _ | null rowsTs ->
-                   Left [NoRowsGivenForValues]
-               | not (all (==head lengths) lengths) ->
-                   Left [ValuesListsMustBeSameLength]
-               | otherwise ->
-                   --i don't think this propagates all the errors, just the first set
-                   mapM (resolveResultSetType cat) (transpose rowsTs) >>=
-                     (return . SetOfType . CompositeType . zip colNames)
-
-
-
-
-
-
-{-
-convert a function call into a [String,[(string,type)]] list for use
-in a tableref context
-first consideration is the alias: if there is an alias in the select,
-e.g. select * from generate_series(1,2) x;  (alias is x)
-we use that, otherwise you use the name of the function
-second consideration is the attributes coming out, roughly speaking
-we have to convert an arbitrary type to a relation type
-if you have a relation valued function, we don't need to do anything
-if you have a setof non composite, we lift the single type to an
-attribute, using the function name for the attribute name
-if you have a non setof, we lift the single type to an attribute and
-then relation, using the function name for the attribute name
-need to check to see what should happen with arrayof
-
--}
-
- -- @lhs.cat @alias.originalTree @fn.annotatedTree @fn.uType
--- should always get full alias
-
-funIdens :: Catalog -> TableAlias -> ScalarExpr -> Maybe Type -> Either [TypeError] (String,[(String,Type)])
-funIdens cat (FullAlias _ t cs) (FunCall _ fnName _) ft = do
-   {-errorWhen (case fnVal of
-                FunCall _ _ _ -> False
-                _ -> True)
-             [ContextError "FunCall"]
-   let (FunCall _ fnName _) = fnVal
-       cn = if alias /= ""
-                           then alias
-                           else fnName-}
-   attrs <- do
-     fnt <- lmt ft
-     case fnt of
-       SetOfType (NamedCompositeType t) -> do
-          x <- catCompositePublicAttrs cat [] t
-          let aliaslen = length cs
-              gotlen = length x
-          if aliaslen == gotlen
-            then return $ zip cs $ map snd x
-            else Left [WrongNumberOfAliasCols gotlen aliaslen]
-
-       SetOfType x | [c] <- cs -> return [(c,x)]
-                   | otherwise -> Left [WrongNumberOfAliasCols 1 $ length cs]
-       x | [c] <- cs -> return [(c,x)]
-         | otherwise -> Left [WrongNumberOfAliasCols 1 $ length cs]
-   return (ncStr t, map (first ncStr) attrs)
-
-getAlias :: String -> TableAlias -> String
-getAlias def alias =
-  case alias of
-    NoAlias _ -> def
-    TableAlias _ t -> ncStr t
-    FullAlias _ t _ -> ncStr t
-
-
-
-{-data SiType = SiType (String,Maybe Type)
-            | SiStarType [(String,Maybe Type)]-}
-
-
---unwrapSetofs :: [(String,Type)] -> [(String,Type)]
---unwrapSetofs = map (\(n,t) -> (n, unwrapSetof t))
-
-unwrapSetof :: Type -> Type
-unwrapSetof (SetOfType u) = u
-unwrapSetof v = v
-
-
-
-makeTrefLib :: Catalog
-            -> Name
-            -> Maybe ([(String,Type)],[(String,Type)])
-            -> E LocalBindings
-makeTrefLib cat si tbUType = Right $ createLocalBindings $ do
-             let n = getTName si
-             -- public and pg internal fields
-             (pu,pr) <- tbUType
-             return [(n,map (second Just) pu)
-                    ,(n,map (second Just) pr)]
-
-
-
-defaultSystemColumns :: [(String,Type)]
-defaultSystemColumns = [("tableoid", ScalarType "oid")
-                       ,("cmax", ScalarType "cid")
-                       ,("xmax", ScalarType "xid")
-                       ,("cmin", ScalarType "cid")
-                       ,("xmin", ScalarType "xid")
-                       ,("ctid", ScalarType "tid")]
-
-
-data ParamName = NamedParam Int String
-               | UnnamedParam Int
-
-
-getPlaceholderTypes :: Data a => a -> [Maybe Type]
-getPlaceholderTypes ex =
-    [infType (getAnnotation x) | x <- universeBi ex
-                               , isPlaceholder x]
-    where
-      isPlaceholder e = case e of
-                          PositionalArg _ _ -> True
-                          Placeholder _ -> True
-                          _ -> False
-
--- AlterTableAction --------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative AddConstraint:
-         child ann            : {Annotation}
-         child con            : Constraint 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative AlterColumnDefault:
-         child ann            : {Annotation}
-         child nm             : {NameComponent}
-         child def            : ScalarExpr 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data AlterTableAction  = AddConstraint (Annotation) (Constraint ) 
-                       | AlterColumnDefault (Annotation) (NameComponent) (ScalarExpr ) 
-                       deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_AlterTableAction :: AlterTableAction  ->
-                        T_AlterTableAction 
-sem_AlterTableAction (AddConstraint _ann _con )  =
-    (sem_AlterTableAction_AddConstraint _ann (sem_Constraint _con ) )
-sem_AlterTableAction (AlterColumnDefault _ann _nm _def )  =
-    (sem_AlterTableAction_AlterColumnDefault _ann _nm (sem_ScalarExpr _def ) )
--- semantic domain
-type T_AlterTableAction  = Catalog ->
-                           IDEnv ->
-                           LocalBindings ->
-                           ( AlterTableAction ,AlterTableAction ,AlterTableAction )
-data Inh_AlterTableAction  = Inh_AlterTableAction {cat_Inh_AlterTableAction :: Catalog,idenv_Inh_AlterTableAction :: IDEnv,lib_Inh_AlterTableAction :: LocalBindings}
-data Syn_AlterTableAction  = Syn_AlterTableAction {annotatedTree_Syn_AlterTableAction :: AlterTableAction ,fixedUpIdentifiersTree_Syn_AlterTableAction :: AlterTableAction ,originalTree_Syn_AlterTableAction :: AlterTableAction }
-wrap_AlterTableAction :: T_AlterTableAction  ->
-                         Inh_AlterTableAction  ->
-                         Syn_AlterTableAction 
-wrap_AlterTableAction sem (Inh_AlterTableAction _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_AlterTableAction _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_AlterTableAction_AddConstraint :: Annotation ->
-                                      T_Constraint  ->
-                                      T_AlterTableAction 
-sem_AlterTableAction_AddConstraint ann_ con_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: AlterTableAction 
-              _lhsOfixedUpIdentifiersTree :: AlterTableAction 
-              _lhsOoriginalTree :: AlterTableAction 
-              _conOcat :: Catalog
-              _conOidenv :: IDEnv
-              _conOlib :: LocalBindings
-              _conIannotatedTree :: Constraint 
-              _conIfixedUpIdentifiersTree :: Constraint 
-              _conIoriginalTree :: Constraint 
-              -- self rule
-              _annotatedTree =
-                  AddConstraint ann_ _conIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  AddConstraint ann_ _conIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  AddConstraint ann_ _conIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _conOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _conOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _conOlib =
-                  _lhsIlib
-              ( _conIannotatedTree,_conIfixedUpIdentifiersTree,_conIoriginalTree) =
-                  con_ _conOcat _conOidenv _conOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_AlterTableAction_AlterColumnDefault :: Annotation ->
-                                           NameComponent ->
-                                           T_ScalarExpr  ->
-                                           T_AlterTableAction 
-sem_AlterTableAction_AlterColumnDefault ann_ nm_ def_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _defOexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: AlterTableAction 
-              _lhsOfixedUpIdentifiersTree :: AlterTableAction 
-              _lhsOoriginalTree :: AlterTableAction 
-              _defOcat :: Catalog
-              _defOidenv :: IDEnv
-              _defOlib :: LocalBindings
-              _defIannotatedTree :: ScalarExpr 
-              _defIfixedUpIdentifiersTree :: ScalarExpr 
-              _defIoriginalTree :: ScalarExpr 
-              _defIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 72, column 26)
-              _defOexpectedType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  AlterColumnDefault ann_ nm_ _defIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  AlterColumnDefault ann_ nm_ _defIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  AlterColumnDefault ann_ nm_ _defIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _defOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _defOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _defOlib =
-                  _lhsIlib
-              ( _defIannotatedTree,_defIfixedUpIdentifiersTree,_defIoriginalTree,_defIuType) =
-                  def_ _defOcat _defOexpectedType _defOidenv _defOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- AlterTableActionList ----------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative Cons:
-         child hd             : AlterTableAction 
-         child tl             : AlterTableActionList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type AlterTableActionList  = [AlterTableAction ]
--- cata
-sem_AlterTableActionList :: AlterTableActionList  ->
-                            T_AlterTableActionList 
-sem_AlterTableActionList list  =
-    (Prelude.foldr sem_AlterTableActionList_Cons sem_AlterTableActionList_Nil (Prelude.map sem_AlterTableAction list) )
--- semantic domain
-type T_AlterTableActionList  = Catalog ->
-                               IDEnv ->
-                               LocalBindings ->
-                               ( AlterTableActionList ,AlterTableActionList ,AlterTableActionList )
-data Inh_AlterTableActionList  = Inh_AlterTableActionList {cat_Inh_AlterTableActionList :: Catalog,idenv_Inh_AlterTableActionList :: IDEnv,lib_Inh_AlterTableActionList :: LocalBindings}
-data Syn_AlterTableActionList  = Syn_AlterTableActionList {annotatedTree_Syn_AlterTableActionList :: AlterTableActionList ,fixedUpIdentifiersTree_Syn_AlterTableActionList :: AlterTableActionList ,originalTree_Syn_AlterTableActionList :: AlterTableActionList }
-wrap_AlterTableActionList :: T_AlterTableActionList  ->
-                             Inh_AlterTableActionList  ->
-                             Syn_AlterTableActionList 
-wrap_AlterTableActionList sem (Inh_AlterTableActionList _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_AlterTableActionList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_AlterTableActionList_Cons :: T_AlterTableAction  ->
-                                 T_AlterTableActionList  ->
-                                 T_AlterTableActionList 
-sem_AlterTableActionList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: AlterTableActionList 
-              _lhsOfixedUpIdentifiersTree :: AlterTableActionList 
-              _lhsOoriginalTree :: AlterTableActionList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: AlterTableAction 
-              _hdIfixedUpIdentifiersTree :: AlterTableAction 
-              _hdIoriginalTree :: AlterTableAction 
-              _tlIannotatedTree :: AlterTableActionList 
-              _tlIfixedUpIdentifiersTree :: AlterTableActionList 
-              _tlIoriginalTree :: AlterTableActionList 
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIfixedUpIdentifiersTree,_hdIoriginalTree) =
-                  hd_ _hdOcat _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIfixedUpIdentifiersTree,_tlIoriginalTree) =
-                  tl_ _tlOcat _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_AlterTableActionList_Nil :: T_AlterTableActionList 
-sem_AlterTableActionList_Nil  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: AlterTableActionList 
-              _lhsOfixedUpIdentifiersTree :: AlterTableActionList 
-              _lhsOoriginalTree :: AlterTableActionList 
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- AttributeDef ------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         attrName             : String
-         fixedUpIdentifiersTree : SELF 
-         namedType            : Maybe Type
-         originalTree         : SELF 
-   alternatives:
-      alternative AttributeDef:
-         child ann            : {Annotation}
-         child name           : {NameComponent}
-         child typ            : TypeName 
-         child def            : MaybeScalarExpr 
-         child cons           : RowConstraintList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data AttributeDef  = AttributeDef (Annotation) (NameComponent) (TypeName ) (MaybeScalarExpr ) (RowConstraintList ) 
-                   deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_AttributeDef :: AttributeDef  ->
-                    T_AttributeDef 
-sem_AttributeDef (AttributeDef _ann _name _typ _def _cons )  =
-    (sem_AttributeDef_AttributeDef _ann _name (sem_TypeName _typ ) (sem_MaybeScalarExpr _def ) (sem_RowConstraintList _cons ) )
--- semantic domain
-type T_AttributeDef  = Catalog ->
-                       IDEnv ->
-                       LocalBindings ->
-                       ( AttributeDef ,String,AttributeDef ,(Maybe Type),AttributeDef )
-data Inh_AttributeDef  = Inh_AttributeDef {cat_Inh_AttributeDef :: Catalog,idenv_Inh_AttributeDef :: IDEnv,lib_Inh_AttributeDef :: LocalBindings}
-data Syn_AttributeDef  = Syn_AttributeDef {annotatedTree_Syn_AttributeDef :: AttributeDef ,attrName_Syn_AttributeDef :: String,fixedUpIdentifiersTree_Syn_AttributeDef :: AttributeDef ,namedType_Syn_AttributeDef :: (Maybe Type),originalTree_Syn_AttributeDef :: AttributeDef }
-wrap_AttributeDef :: T_AttributeDef  ->
-                     Inh_AttributeDef  ->
-                     Syn_AttributeDef 
-wrap_AttributeDef sem (Inh_AttributeDef _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOattrName,_lhsOfixedUpIdentifiersTree,_lhsOnamedType,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_AttributeDef _lhsOannotatedTree _lhsOattrName _lhsOfixedUpIdentifiersTree _lhsOnamedType _lhsOoriginalTree ))
-sem_AttributeDef_AttributeDef :: Annotation ->
-                                 NameComponent ->
-                                 T_TypeName  ->
-                                 T_MaybeScalarExpr  ->
-                                 T_RowConstraintList  ->
-                                 T_AttributeDef 
-sem_AttributeDef_AttributeDef ann_ name_ typ_ def_ cons_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOattrName :: String
-              _lhsOnamedType :: (Maybe Type)
-              _consOlib :: LocalBindings
-              _lhsOannotatedTree :: AttributeDef 
-              _lhsOfixedUpIdentifiersTree :: AttributeDef 
-              _lhsOoriginalTree :: AttributeDef 
-              _typOcat :: Catalog
-              _typOidenv :: IDEnv
-              _typOlib :: LocalBindings
-              _defOcat :: Catalog
-              _defOidenv :: IDEnv
-              _defOlib :: LocalBindings
-              _consOcat :: Catalog
-              _consOidenv :: IDEnv
-              _typIannotatedTree :: TypeName 
-              _typIfixedUpIdentifiersTree :: TypeName 
-              _typInamedType :: (Maybe Type)
-              _typIoriginalTree :: TypeName 
-              _defIannotatedTree :: MaybeScalarExpr 
-              _defIfixedUpIdentifiersTree :: MaybeScalarExpr 
-              _defIoriginalTree :: MaybeScalarExpr 
-              _defIuType :: (Maybe Type)
-              _consIannotatedTree :: RowConstraintList 
-              _consIfixedUpIdentifiersTree :: RowConstraintList 
-              _consIoriginalTree :: RowConstraintList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateTable.ag"(line 83, column 9)
-              _lhsOattrName =
-                  map toLower $ ncStr name_
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateTable.ag"(line 84, column 9)
-              _lhsOnamedType =
-                  _typInamedType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateTable.ag"(line 98, column 9)
-              _consOlib =
-                  either (const _lhsIlib) id $ do
-                  t <- lmt _typInamedType
-                  lbUpdate _lhsIcat
-                           (LBIds "attribute def" Nothing
-                                  [(ncStr name_, t)]) _lhsIlib
-              -- self rule
-              _annotatedTree =
-                  AttributeDef ann_ name_ _typIannotatedTree _defIannotatedTree _consIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  AttributeDef ann_ name_ _typIfixedUpIdentifiersTree _defIfixedUpIdentifiersTree _consIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  AttributeDef ann_ name_ _typIoriginalTree _defIoriginalTree _consIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _typOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _typOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _typOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _defOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _defOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _defOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _consOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _consOidenv =
-                  _lhsIidenv
-              ( _typIannotatedTree,_typIfixedUpIdentifiersTree,_typInamedType,_typIoriginalTree) =
-                  typ_ _typOcat _typOidenv _typOlib 
-              ( _defIannotatedTree,_defIfixedUpIdentifiersTree,_defIoriginalTree,_defIuType) =
-                  def_ _defOcat _defOidenv _defOlib 
-              ( _consIannotatedTree,_consIfixedUpIdentifiersTree,_consIoriginalTree) =
-                  cons_ _consOcat _consOidenv _consOlib 
-          in  ( _lhsOannotatedTree,_lhsOattrName,_lhsOfixedUpIdentifiersTree,_lhsOnamedType,_lhsOoriginalTree)))
--- AttributeDefList --------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         attrs                : [(String, Maybe Type)]
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative Cons:
-         child hd             : AttributeDef 
-         child tl             : AttributeDefList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type AttributeDefList  = [AttributeDef ]
--- cata
-sem_AttributeDefList :: AttributeDefList  ->
-                        T_AttributeDefList 
-sem_AttributeDefList list  =
-    (Prelude.foldr sem_AttributeDefList_Cons sem_AttributeDefList_Nil (Prelude.map sem_AttributeDef list) )
--- semantic domain
-type T_AttributeDefList  = Catalog ->
-                           IDEnv ->
-                           LocalBindings ->
-                           ( AttributeDefList ,([(String, Maybe Type)]),AttributeDefList ,AttributeDefList )
-data Inh_AttributeDefList  = Inh_AttributeDefList {cat_Inh_AttributeDefList :: Catalog,idenv_Inh_AttributeDefList :: IDEnv,lib_Inh_AttributeDefList :: LocalBindings}
-data Syn_AttributeDefList  = Syn_AttributeDefList {annotatedTree_Syn_AttributeDefList :: AttributeDefList ,attrs_Syn_AttributeDefList :: ([(String, Maybe Type)]),fixedUpIdentifiersTree_Syn_AttributeDefList :: AttributeDefList ,originalTree_Syn_AttributeDefList :: AttributeDefList }
-wrap_AttributeDefList :: T_AttributeDefList  ->
-                         Inh_AttributeDefList  ->
-                         Syn_AttributeDefList 
-wrap_AttributeDefList sem (Inh_AttributeDefList _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOattrs,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_AttributeDefList _lhsOannotatedTree _lhsOattrs _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_AttributeDefList_Cons :: T_AttributeDef  ->
-                             T_AttributeDefList  ->
-                             T_AttributeDefList 
-sem_AttributeDefList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOattrs :: ([(String, Maybe Type)])
-              _lhsOannotatedTree :: AttributeDefList 
-              _lhsOfixedUpIdentifiersTree :: AttributeDefList 
-              _lhsOoriginalTree :: AttributeDefList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: AttributeDef 
-              _hdIattrName :: String
-              _hdIfixedUpIdentifiersTree :: AttributeDef 
-              _hdInamedType :: (Maybe Type)
-              _hdIoriginalTree :: AttributeDef 
-              _tlIannotatedTree :: AttributeDefList 
-              _tlIattrs :: ([(String, Maybe Type)])
-              _tlIfixedUpIdentifiersTree :: AttributeDefList 
-              _tlIoriginalTree :: AttributeDefList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateTable.ag"(line 88, column 12)
-              _lhsOattrs =
-                  (_hdIattrName, _hdInamedType) : _tlIattrs
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIattrName,_hdIfixedUpIdentifiersTree,_hdInamedType,_hdIoriginalTree) =
-                  hd_ _hdOcat _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIattrs,_tlIfixedUpIdentifiersTree,_tlIoriginalTree) =
-                  tl_ _tlOcat _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOattrs,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_AttributeDefList_Nil :: T_AttributeDefList 
-sem_AttributeDefList_Nil  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOattrs :: ([(String, Maybe Type)])
-              _lhsOannotatedTree :: AttributeDefList 
-              _lhsOfixedUpIdentifiersTree :: AttributeDefList 
-              _lhsOoriginalTree :: AttributeDefList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateTable.ag"(line 89, column 11)
-              _lhsOattrs =
-                  []
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOattrs,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- CaseScalarExprListScalarExprPair ----------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-         thenType             : Maybe Type
-         whenTypes            : [Maybe Type]
-   alternatives:
-      alternative Tuple:
-         child x1             : ScalarExprList 
-         child x2             : ScalarExpr 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type CaseScalarExprListScalarExprPair  = ( ScalarExprList ,ScalarExpr )
--- cata
-sem_CaseScalarExprListScalarExprPair :: CaseScalarExprListScalarExprPair  ->
-                                        T_CaseScalarExprListScalarExprPair 
-sem_CaseScalarExprListScalarExprPair ( x1,x2)  =
-    (sem_CaseScalarExprListScalarExprPair_Tuple (sem_ScalarExprList x1 ) (sem_ScalarExpr x2 ) )
--- semantic domain
-type T_CaseScalarExprListScalarExprPair  = Catalog ->
-                                           IDEnv ->
-                                           LocalBindings ->
-                                           ( CaseScalarExprListScalarExprPair ,CaseScalarExprListScalarExprPair ,CaseScalarExprListScalarExprPair ,(Maybe Type),([Maybe Type]))
-data Inh_CaseScalarExprListScalarExprPair  = Inh_CaseScalarExprListScalarExprPair {cat_Inh_CaseScalarExprListScalarExprPair :: Catalog,idenv_Inh_CaseScalarExprListScalarExprPair :: IDEnv,lib_Inh_CaseScalarExprListScalarExprPair :: LocalBindings}
-data Syn_CaseScalarExprListScalarExprPair  = Syn_CaseScalarExprListScalarExprPair {annotatedTree_Syn_CaseScalarExprListScalarExprPair :: CaseScalarExprListScalarExprPair ,fixedUpIdentifiersTree_Syn_CaseScalarExprListScalarExprPair :: CaseScalarExprListScalarExprPair ,originalTree_Syn_CaseScalarExprListScalarExprPair :: CaseScalarExprListScalarExprPair ,thenType_Syn_CaseScalarExprListScalarExprPair :: (Maybe Type),whenTypes_Syn_CaseScalarExprListScalarExprPair :: ([Maybe Type])}
-wrap_CaseScalarExprListScalarExprPair :: T_CaseScalarExprListScalarExprPair  ->
-                                         Inh_CaseScalarExprListScalarExprPair  ->
-                                         Syn_CaseScalarExprListScalarExprPair 
-wrap_CaseScalarExprListScalarExprPair sem (Inh_CaseScalarExprListScalarExprPair _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOthenType,_lhsOwhenTypes) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_CaseScalarExprListScalarExprPair _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree _lhsOthenType _lhsOwhenTypes ))
-sem_CaseScalarExprListScalarExprPair_Tuple :: T_ScalarExprList  ->
-                                              T_ScalarExpr  ->
-                                              T_CaseScalarExprListScalarExprPair 
-sem_CaseScalarExprListScalarExprPair_Tuple x1_ x2_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOwhenTypes :: ([Maybe Type])
-              _lhsOthenType :: (Maybe Type)
-              _x1OexpectedTypes :: ([Maybe Type])
-              _x2OexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: CaseScalarExprListScalarExprPair 
-              _lhsOfixedUpIdentifiersTree :: CaseScalarExprListScalarExprPair 
-              _lhsOoriginalTree :: CaseScalarExprListScalarExprPair 
-              _x1Ocat :: Catalog
-              _x1Oidenv :: IDEnv
-              _x1Olib :: LocalBindings
-              _x2Ocat :: Catalog
-              _x2Oidenv :: IDEnv
-              _x2Olib :: LocalBindings
-              _x1IannotatedTree :: ScalarExprList 
-              _x1IfixedUpIdentifiersTree :: ScalarExprList 
-              _x1IoriginalTree :: ScalarExprList 
-              _x1IuType :: ([Maybe Type])
-              _x2IannotatedTree :: ScalarExpr 
-              _x2IfixedUpIdentifiersTree :: ScalarExpr 
-              _x2IoriginalTree :: ScalarExpr 
-              _x2IuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 276, column 13)
-              _lhsOwhenTypes =
-                  _x1IuType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 277, column 13)
-              _lhsOthenType =
-                  _x2IuType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 76, column 13)
-              _x1OexpectedTypes =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 77, column 13)
-              _x2OexpectedType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  (_x1IannotatedTree,_x2IannotatedTree)
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (_x1IfixedUpIdentifiersTree,_x2IfixedUpIdentifiersTree)
-              -- self rule
-              _originalTree =
-                  (_x1IoriginalTree,_x2IoriginalTree)
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _x1Ocat =
-                  _lhsIcat
-              -- copy rule (down)
-              _x1Oidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _x1Olib =
-                  _lhsIlib
-              -- copy rule (down)
-              _x2Ocat =
-                  _lhsIcat
-              -- copy rule (down)
-              _x2Oidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _x2Olib =
-                  _lhsIlib
-              ( _x1IannotatedTree,_x1IfixedUpIdentifiersTree,_x1IoriginalTree,_x1IuType) =
-                  x1_ _x1Ocat _x1OexpectedTypes _x1Oidenv _x1Olib 
-              ( _x2IannotatedTree,_x2IfixedUpIdentifiersTree,_x2IoriginalTree,_x2IuType) =
-                  x2_ _x2Ocat _x2OexpectedType _x2Oidenv _x2Olib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOthenType,_lhsOwhenTypes)))
--- CaseScalarExprListScalarExprPairList ------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-         thenTypes            : [Maybe Type]
-         whenTypes            : [[Maybe Type]]
-   alternatives:
-      alternative Cons:
-         child hd             : CaseScalarExprListScalarExprPair 
-         child tl             : CaseScalarExprListScalarExprPairList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type CaseScalarExprListScalarExprPairList  = [CaseScalarExprListScalarExprPair ]
--- cata
-sem_CaseScalarExprListScalarExprPairList :: CaseScalarExprListScalarExprPairList  ->
-                                            T_CaseScalarExprListScalarExprPairList 
-sem_CaseScalarExprListScalarExprPairList list  =
-    (Prelude.foldr sem_CaseScalarExprListScalarExprPairList_Cons sem_CaseScalarExprListScalarExprPairList_Nil (Prelude.map sem_CaseScalarExprListScalarExprPair list) )
--- semantic domain
-type T_CaseScalarExprListScalarExprPairList  = Catalog ->
-                                               IDEnv ->
-                                               LocalBindings ->
-                                               ( CaseScalarExprListScalarExprPairList ,CaseScalarExprListScalarExprPairList ,CaseScalarExprListScalarExprPairList ,([Maybe Type]),([[Maybe Type]]))
-data Inh_CaseScalarExprListScalarExprPairList  = Inh_CaseScalarExprListScalarExprPairList {cat_Inh_CaseScalarExprListScalarExprPairList :: Catalog,idenv_Inh_CaseScalarExprListScalarExprPairList :: IDEnv,lib_Inh_CaseScalarExprListScalarExprPairList :: LocalBindings}
-data Syn_CaseScalarExprListScalarExprPairList  = Syn_CaseScalarExprListScalarExprPairList {annotatedTree_Syn_CaseScalarExprListScalarExprPairList :: CaseScalarExprListScalarExprPairList ,fixedUpIdentifiersTree_Syn_CaseScalarExprListScalarExprPairList :: CaseScalarExprListScalarExprPairList ,originalTree_Syn_CaseScalarExprListScalarExprPairList :: CaseScalarExprListScalarExprPairList ,thenTypes_Syn_CaseScalarExprListScalarExprPairList :: ([Maybe Type]),whenTypes_Syn_CaseScalarExprListScalarExprPairList :: ([[Maybe Type]])}
-wrap_CaseScalarExprListScalarExprPairList :: T_CaseScalarExprListScalarExprPairList  ->
-                                             Inh_CaseScalarExprListScalarExprPairList  ->
-                                             Syn_CaseScalarExprListScalarExprPairList 
-wrap_CaseScalarExprListScalarExprPairList sem (Inh_CaseScalarExprListScalarExprPairList _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOthenTypes,_lhsOwhenTypes) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_CaseScalarExprListScalarExprPairList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree _lhsOthenTypes _lhsOwhenTypes ))
-sem_CaseScalarExprListScalarExprPairList_Cons :: T_CaseScalarExprListScalarExprPair  ->
-                                                 T_CaseScalarExprListScalarExprPairList  ->
-                                                 T_CaseScalarExprListScalarExprPairList 
-sem_CaseScalarExprListScalarExprPairList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOwhenTypes :: ([[Maybe Type]])
-              _lhsOthenTypes :: ([Maybe Type])
-              _lhsOannotatedTree :: CaseScalarExprListScalarExprPairList 
-              _lhsOfixedUpIdentifiersTree :: CaseScalarExprListScalarExprPairList 
-              _lhsOoriginalTree :: CaseScalarExprListScalarExprPairList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: CaseScalarExprListScalarExprPair 
-              _hdIfixedUpIdentifiersTree :: CaseScalarExprListScalarExprPair 
-              _hdIoriginalTree :: CaseScalarExprListScalarExprPair 
-              _hdIthenType :: (Maybe Type)
-              _hdIwhenTypes :: ([Maybe Type])
-              _tlIannotatedTree :: CaseScalarExprListScalarExprPairList 
-              _tlIfixedUpIdentifiersTree :: CaseScalarExprListScalarExprPairList 
-              _tlIoriginalTree :: CaseScalarExprListScalarExprPairList 
-              _tlIthenTypes :: ([Maybe Type])
-              _tlIwhenTypes :: ([[Maybe Type]])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 267, column 10)
-              _lhsOwhenTypes =
-                  _hdIwhenTypes : _tlIwhenTypes
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 268, column 10)
-              _lhsOthenTypes =
-                  _hdIthenType : _tlIthenTypes
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIfixedUpIdentifiersTree,_hdIoriginalTree,_hdIthenType,_hdIwhenTypes) =
-                  hd_ _hdOcat _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIfixedUpIdentifiersTree,_tlIoriginalTree,_tlIthenTypes,_tlIwhenTypes) =
-                  tl_ _tlOcat _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOthenTypes,_lhsOwhenTypes)))
-sem_CaseScalarExprListScalarExprPairList_Nil :: T_CaseScalarExprListScalarExprPairList 
-sem_CaseScalarExprListScalarExprPairList_Nil  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOwhenTypes :: ([[Maybe Type]])
-              _lhsOthenTypes :: ([Maybe Type])
-              _lhsOannotatedTree :: CaseScalarExprListScalarExprPairList 
-              _lhsOfixedUpIdentifiersTree :: CaseScalarExprListScalarExprPairList 
-              _lhsOoriginalTree :: CaseScalarExprListScalarExprPairList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 269, column 9)
-              _lhsOwhenTypes =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 270, column 9)
-              _lhsOthenTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOthenTypes,_lhsOwhenTypes)))
--- Constraint --------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative CheckConstraint:
-         child ann            : {Annotation}
-         child name           : {String}
-         child expr           : ScalarExpr 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative PrimaryKeyConstraint:
-         child ann            : {Annotation}
-         child name           : {String}
-         child x              : {[NameComponent]}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative ReferenceConstraint:
-         child ann            : {Annotation}
-         child name           : {String}
-         child atts           : {[NameComponent]}
-         child table          : Name 
-         child tableAtts      : {[NameComponent]}
-         child onUpdate       : {Cascade}
-         child onDelete       : {Cascade}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative UniqueConstraint:
-         child ann            : {Annotation}
-         child name           : {String}
-         child x              : {[NameComponent]}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data Constraint  = CheckConstraint (Annotation) (String) (ScalarExpr ) 
-                 | PrimaryKeyConstraint (Annotation) (String) (([NameComponent])) 
-                 | ReferenceConstraint (Annotation) (String) (([NameComponent])) (Name ) (([NameComponent])) (Cascade) (Cascade) 
-                 | UniqueConstraint (Annotation) (String) (([NameComponent])) 
-                 deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_Constraint :: Constraint  ->
-                  T_Constraint 
-sem_Constraint (CheckConstraint _ann _name _expr )  =
-    (sem_Constraint_CheckConstraint _ann _name (sem_ScalarExpr _expr ) )
-sem_Constraint (PrimaryKeyConstraint _ann _name _x )  =
-    (sem_Constraint_PrimaryKeyConstraint _ann _name _x )
-sem_Constraint (ReferenceConstraint _ann _name _atts _table _tableAtts _onUpdate _onDelete )  =
-    (sem_Constraint_ReferenceConstraint _ann _name _atts (sem_Name _table ) _tableAtts _onUpdate _onDelete )
-sem_Constraint (UniqueConstraint _ann _name _x )  =
-    (sem_Constraint_UniqueConstraint _ann _name _x )
--- semantic domain
-type T_Constraint  = Catalog ->
-                     IDEnv ->
-                     LocalBindings ->
-                     ( Constraint ,Constraint ,Constraint )
-data Inh_Constraint  = Inh_Constraint {cat_Inh_Constraint :: Catalog,idenv_Inh_Constraint :: IDEnv,lib_Inh_Constraint :: LocalBindings}
-data Syn_Constraint  = Syn_Constraint {annotatedTree_Syn_Constraint :: Constraint ,fixedUpIdentifiersTree_Syn_Constraint :: Constraint ,originalTree_Syn_Constraint :: Constraint }
-wrap_Constraint :: T_Constraint  ->
-                   Inh_Constraint  ->
-                   Syn_Constraint 
-wrap_Constraint sem (Inh_Constraint _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_Constraint _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_Constraint_CheckConstraint :: Annotation ->
-                                  String ->
-                                  T_ScalarExpr  ->
-                                  T_Constraint 
-sem_Constraint_CheckConstraint ann_ name_ expr_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _exprOexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: Constraint 
-              _lhsOfixedUpIdentifiersTree :: Constraint 
-              _lhsOoriginalTree :: Constraint 
-              _exprOcat :: Catalog
-              _exprOidenv :: IDEnv
-              _exprOlib :: LocalBindings
-              _exprIannotatedTree :: ScalarExpr 
-              _exprIfixedUpIdentifiersTree :: ScalarExpr 
-              _exprIoriginalTree :: ScalarExpr 
-              _exprIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 80, column 23)
-              _exprOexpectedType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  CheckConstraint ann_ name_ _exprIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  CheckConstraint ann_ name_ _exprIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  CheckConstraint ann_ name_ _exprIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _exprOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exprOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exprOlib =
-                  _lhsIlib
-              ( _exprIannotatedTree,_exprIfixedUpIdentifiersTree,_exprIoriginalTree,_exprIuType) =
-                  expr_ _exprOcat _exprOexpectedType _exprOidenv _exprOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_Constraint_PrimaryKeyConstraint :: Annotation ->
-                                       String ->
-                                       ([NameComponent]) ->
-                                       T_Constraint 
-sem_Constraint_PrimaryKeyConstraint ann_ name_ x_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: Constraint 
-              _lhsOfixedUpIdentifiersTree :: Constraint 
-              _lhsOoriginalTree :: Constraint 
-              -- self rule
-              _annotatedTree =
-                  PrimaryKeyConstraint ann_ name_ x_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  PrimaryKeyConstraint ann_ name_ x_
-              -- self rule
-              _originalTree =
-                  PrimaryKeyConstraint ann_ name_ x_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_Constraint_ReferenceConstraint :: Annotation ->
-                                      String ->
-                                      ([NameComponent]) ->
-                                      T_Name  ->
-                                      ([NameComponent]) ->
-                                      Cascade ->
-                                      Cascade ->
-                                      T_Constraint 
-sem_Constraint_ReferenceConstraint ann_ name_ atts_ table_ tableAtts_ onUpdate_ onDelete_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: Constraint 
-              _lhsOfixedUpIdentifiersTree :: Constraint 
-              _lhsOoriginalTree :: Constraint 
-              _tableOcat :: Catalog
-              _tableOidenv :: IDEnv
-              _tableOlib :: LocalBindings
-              _tableIannotatedTree :: Name 
-              _tableIfixedUpIdentifiersTree :: Name 
-              _tableIoriginalTree :: Name 
-              _tableItbAnnotatedTree :: Name 
-              _tableItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              -- self rule
-              _annotatedTree =
-                  ReferenceConstraint ann_ name_ atts_ _tableIannotatedTree tableAtts_ onUpdate_ onDelete_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  ReferenceConstraint ann_ name_ atts_ _tableIfixedUpIdentifiersTree tableAtts_ onUpdate_ onDelete_
-              -- self rule
-              _originalTree =
-                  ReferenceConstraint ann_ name_ atts_ _tableIoriginalTree tableAtts_ onUpdate_ onDelete_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _tableOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tableOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tableOlib =
-                  _lhsIlib
-              ( _tableIannotatedTree,_tableIfixedUpIdentifiersTree,_tableIoriginalTree,_tableItbAnnotatedTree,_tableItbUType) =
-                  table_ _tableOcat _tableOidenv _tableOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_Constraint_UniqueConstraint :: Annotation ->
-                                   String ->
-                                   ([NameComponent]) ->
-                                   T_Constraint 
-sem_Constraint_UniqueConstraint ann_ name_ x_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: Constraint 
-              _lhsOfixedUpIdentifiersTree :: Constraint 
-              _lhsOoriginalTree :: Constraint 
-              -- self rule
-              _annotatedTree =
-                  UniqueConstraint ann_ name_ x_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  UniqueConstraint ann_ name_ x_
-              -- self rule
-              _originalTree =
-                  UniqueConstraint ann_ name_ x_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- ConstraintList ----------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative Cons:
-         child hd             : Constraint 
-         child tl             : ConstraintList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type ConstraintList  = [Constraint ]
--- cata
-sem_ConstraintList :: ConstraintList  ->
-                      T_ConstraintList 
-sem_ConstraintList list  =
-    (Prelude.foldr sem_ConstraintList_Cons sem_ConstraintList_Nil (Prelude.map sem_Constraint list) )
--- semantic domain
-type T_ConstraintList  = Catalog ->
-                         IDEnv ->
-                         LocalBindings ->
-                         ( ConstraintList ,ConstraintList ,ConstraintList )
-data Inh_ConstraintList  = Inh_ConstraintList {cat_Inh_ConstraintList :: Catalog,idenv_Inh_ConstraintList :: IDEnv,lib_Inh_ConstraintList :: LocalBindings}
-data Syn_ConstraintList  = Syn_ConstraintList {annotatedTree_Syn_ConstraintList :: ConstraintList ,fixedUpIdentifiersTree_Syn_ConstraintList :: ConstraintList ,originalTree_Syn_ConstraintList :: ConstraintList }
-wrap_ConstraintList :: T_ConstraintList  ->
-                       Inh_ConstraintList  ->
-                       Syn_ConstraintList 
-wrap_ConstraintList sem (Inh_ConstraintList _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_ConstraintList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_ConstraintList_Cons :: T_Constraint  ->
-                           T_ConstraintList  ->
-                           T_ConstraintList 
-sem_ConstraintList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ConstraintList 
-              _lhsOfixedUpIdentifiersTree :: ConstraintList 
-              _lhsOoriginalTree :: ConstraintList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: Constraint 
-              _hdIfixedUpIdentifiersTree :: Constraint 
-              _hdIoriginalTree :: Constraint 
-              _tlIannotatedTree :: ConstraintList 
-              _tlIfixedUpIdentifiersTree :: ConstraintList 
-              _tlIoriginalTree :: ConstraintList 
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIfixedUpIdentifiersTree,_hdIoriginalTree) =
-                  hd_ _hdOcat _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIfixedUpIdentifiersTree,_tlIoriginalTree) =
-                  tl_ _tlOcat _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_ConstraintList_Nil :: T_ConstraintList 
-sem_ConstraintList_Nil  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ConstraintList 
-              _lhsOfixedUpIdentifiersTree :: ConstraintList 
-              _lhsOoriginalTree :: ConstraintList 
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- FnBody ------------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative PlpgsqlFnBody:
-         child ann            : {Annotation}
-         child blk            : Statement 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative SqlFnBody:
-         child ann            : {Annotation}
-         child sts            : StatementList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data FnBody  = PlpgsqlFnBody (Annotation) (Statement ) 
-             | SqlFnBody (Annotation) (StatementList ) 
-             deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_FnBody :: FnBody  ->
-              T_FnBody 
-sem_FnBody (PlpgsqlFnBody _ann _blk )  =
-    (sem_FnBody_PlpgsqlFnBody _ann (sem_Statement _blk ) )
-sem_FnBody (SqlFnBody _ann _sts )  =
-    (sem_FnBody_SqlFnBody _ann (sem_StatementList _sts ) )
--- semantic domain
-type T_FnBody  = Catalog ->
-                 IDEnv ->
-                 LocalBindings ->
-                 ( FnBody ,FnBody ,FnBody )
-data Inh_FnBody  = Inh_FnBody {cat_Inh_FnBody :: Catalog,idenv_Inh_FnBody :: IDEnv,lib_Inh_FnBody :: LocalBindings}
-data Syn_FnBody  = Syn_FnBody {annotatedTree_Syn_FnBody :: FnBody ,fixedUpIdentifiersTree_Syn_FnBody :: FnBody ,originalTree_Syn_FnBody :: FnBody }
-wrap_FnBody :: T_FnBody  ->
-               Inh_FnBody  ->
-               Syn_FnBody 
-wrap_FnBody sem (Inh_FnBody _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_FnBody _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_FnBody_PlpgsqlFnBody :: Annotation ->
-                            T_Statement  ->
-                            T_FnBody 
-sem_FnBody_PlpgsqlFnBody ann_ blk_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _blkOinProducedCat :: Catalog
-              _lhsOannotatedTree :: FnBody 
-              _lhsOfixedUpIdentifiersTree :: FnBody 
-              _lhsOoriginalTree :: FnBody 
-              _blkOcat :: Catalog
-              _blkOidenv :: IDEnv
-              _blkOlib :: LocalBindings
-              _blkIannotatedTree :: Statement 
-              _blkIcatUpdates :: ([CatalogUpdate])
-              _blkIfixedUpIdentifiersTree :: Statement 
-              _blkIlibUpdates :: ([LocalBindingsUpdate])
-              _blkIoriginalTree :: Statement 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 104, column 9)
-              _blkOinProducedCat =
-                  emptyCatalog
-              -- self rule
-              _annotatedTree =
-                  PlpgsqlFnBody ann_ _blkIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  PlpgsqlFnBody ann_ _blkIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  PlpgsqlFnBody ann_ _blkIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _blkOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _blkOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _blkOlib =
-                  _lhsIlib
-              ( _blkIannotatedTree,_blkIcatUpdates,_blkIfixedUpIdentifiersTree,_blkIlibUpdates,_blkIoriginalTree) =
-                  blk_ _blkOcat _blkOidenv _blkOinProducedCat _blkOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_FnBody_SqlFnBody :: Annotation ->
-                        T_StatementList  ->
-                        T_FnBody 
-sem_FnBody_SqlFnBody ann_ sts_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _stsOcatUpdates :: ([CatalogUpdate])
-              _stsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: FnBody 
-              _lhsOfixedUpIdentifiersTree :: FnBody 
-              _lhsOoriginalTree :: FnBody 
-              _stsOcat :: Catalog
-              _stsOidenv :: IDEnv
-              _stsOlib :: LocalBindings
-              _stsIannotatedTree :: StatementList 
-              _stsIfixedUpIdentifiersTree :: StatementList 
-              _stsIoriginalTree :: StatementList 
-              _stsIproducedCat :: Catalog
-              _stsIproducedLib :: LocalBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 129, column 9)
-              _stsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 130, column 9)
-              _stsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  SqlFnBody ann_ _stsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  SqlFnBody ann_ _stsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  SqlFnBody ann_ _stsIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _stsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _stsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _stsOlib =
-                  _lhsIlib
-              ( _stsIannotatedTree,_stsIfixedUpIdentifiersTree,_stsIoriginalTree,_stsIproducedCat,_stsIproducedLib) =
-                  sts_ _stsOcat _stsOcatUpdates _stsOidenv _stsOlib _stsOlibUpdates 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- InList ------------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         expectedType         : Maybe Type
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         listType             : Either [TypeError] Type
-         originalTree         : SELF 
-   alternatives:
-      alternative InList:
-         child ann            : {Annotation}
-         child exprs          : ScalarExprList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative InQueryExpr:
-         child ann            : {Annotation}
-         child sel            : QueryExpr 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data InList  = InList (Annotation) (ScalarExprList ) 
-             | InQueryExpr (Annotation) (QueryExpr ) 
-             deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_InList :: InList  ->
-              T_InList 
-sem_InList (InList _ann _exprs )  =
-    (sem_InList_InList _ann (sem_ScalarExprList _exprs ) )
-sem_InList (InQueryExpr _ann _sel )  =
-    (sem_InList_InQueryExpr _ann (sem_QueryExpr _sel ) )
--- semantic domain
-type T_InList  = Catalog ->
-                 (Maybe Type) ->
-                 IDEnv ->
-                 LocalBindings ->
-                 ( InList ,InList ,(Either [TypeError] Type),InList )
-data Inh_InList  = Inh_InList {cat_Inh_InList :: Catalog,expectedType_Inh_InList :: (Maybe Type),idenv_Inh_InList :: IDEnv,lib_Inh_InList :: LocalBindings}
-data Syn_InList  = Syn_InList {annotatedTree_Syn_InList :: InList ,fixedUpIdentifiersTree_Syn_InList :: InList ,listType_Syn_InList :: (Either [TypeError] Type),originalTree_Syn_InList :: InList }
-wrap_InList :: T_InList  ->
-               Inh_InList  ->
-               Syn_InList 
-wrap_InList sem (Inh_InList _lhsIcat _lhsIexpectedType _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlistType,_lhsOoriginalTree) = sem _lhsIcat _lhsIexpectedType _lhsIidenv _lhsIlib 
-     in  (Syn_InList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOlistType _lhsOoriginalTree ))
-sem_InList_InList :: Annotation ->
-                     T_ScalarExprList  ->
-                     T_InList 
-sem_InList_InList ann_ exprs_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOlistType :: (Either [TypeError] Type)
-              _exprsOexpectedTypes :: ([Maybe Type])
-              _lhsOannotatedTree :: InList 
-              _lhsOfixedUpIdentifiersTree :: InList 
-              _lhsOoriginalTree :: InList 
-              _exprsOcat :: Catalog
-              _exprsOidenv :: IDEnv
-              _exprsOlib :: LocalBindings
-              _exprsIannotatedTree :: ScalarExprList 
-              _exprsIfixedUpIdentifiersTree :: ScalarExprList 
-              _exprsIoriginalTree :: ScalarExprList 
-              _exprsIuType :: ([Maybe Type])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 420, column 9)
-              _lhsOlistType =
-                  mapM lmt _exprsIuType >>= resolveResultSetType _lhsIcat
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 421, column 9)
-              _exprsOexpectedTypes =
-                  repeat _lhsIexpectedType
-              -- self rule
-              _annotatedTree =
-                  InList ann_ _exprsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  InList ann_ _exprsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  InList ann_ _exprsIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _exprsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exprsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exprsOlib =
-                  _lhsIlib
-              ( _exprsIannotatedTree,_exprsIfixedUpIdentifiersTree,_exprsIoriginalTree,_exprsIuType) =
-                  exprs_ _exprsOcat _exprsOexpectedTypes _exprsOidenv _exprsOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlistType,_lhsOoriginalTree)))
-sem_InList_InQueryExpr :: Annotation ->
-                          T_QueryExpr  ->
-                          T_InList 
-sem_InList_InQueryExpr ann_ sel_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOlistType :: (Either [TypeError] Type)
-              _selOcsql :: LocalBindings
-              _selOexpectedTypes :: ([Maybe Type])
-              _lhsOannotatedTree :: InList 
-              _lhsOfixedUpIdentifiersTree :: InList 
-              _lhsOoriginalTree :: InList 
-              _selOcat :: Catalog
-              _selOidenv :: IDEnv
-              _selOlib :: LocalBindings
-              _selIannotatedTree :: QueryExpr 
-              _selIcidenv :: IDEnv
-              _selIfixedUpIdentifiersTree :: QueryExpr 
-              _selIlibUpdates :: ([LocalBindingsUpdate])
-              _selIoriginalTree :: QueryExpr 
-              _selIuType :: (Maybe [(String,Type)])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 424, column 9)
-              _lhsOlistType =
-                  do
-                  st <- lmt (map snd <$> _selIuType)
-                  case length st of
-                            0 -> Left [InternalError
-                                       "got subquery with no columns? in inselect"]
-                            1 -> Right $ head st
-                            _ -> Right $ AnonymousRecordType st
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 120, column 19)
-              _selOcsql =
-                  emptyBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 171, column 19)
-              _selOexpectedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  InQueryExpr ann_ _selIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  InQueryExpr ann_ _selIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  InQueryExpr ann_ _selIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _selOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _selOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _selOlib =
-                  _lhsIlib
-              ( _selIannotatedTree,_selIcidenv,_selIfixedUpIdentifiersTree,_selIlibUpdates,_selIoriginalTree,_selIuType) =
-                  sel_ _selOcat _selOcsql _selOexpectedTypes _selOidenv _selOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlistType,_lhsOoriginalTree)))
--- JoinExpr ----------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative JoinOn:
-         child ann            : {Annotation}
-         child expr           : ScalarExpr 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative JoinUsing:
-         child ann            : {Annotation}
-         child x              : {[NameComponent]}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data JoinExpr  = JoinOn (Annotation) (ScalarExpr ) 
-               | JoinUsing (Annotation) (([NameComponent])) 
-               deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_JoinExpr :: JoinExpr  ->
-                T_JoinExpr 
-sem_JoinExpr (JoinOn _ann _expr )  =
-    (sem_JoinExpr_JoinOn _ann (sem_ScalarExpr _expr ) )
-sem_JoinExpr (JoinUsing _ann _x )  =
-    (sem_JoinExpr_JoinUsing _ann _x )
--- semantic domain
-type T_JoinExpr  = Catalog ->
-                   IDEnv ->
-                   LocalBindings ->
-                   ( JoinExpr ,JoinExpr ,JoinExpr )
-data Inh_JoinExpr  = Inh_JoinExpr {cat_Inh_JoinExpr :: Catalog,idenv_Inh_JoinExpr :: IDEnv,lib_Inh_JoinExpr :: LocalBindings}
-data Syn_JoinExpr  = Syn_JoinExpr {annotatedTree_Syn_JoinExpr :: JoinExpr ,fixedUpIdentifiersTree_Syn_JoinExpr :: JoinExpr ,originalTree_Syn_JoinExpr :: JoinExpr }
-wrap_JoinExpr :: T_JoinExpr  ->
-                 Inh_JoinExpr  ->
-                 Syn_JoinExpr 
-wrap_JoinExpr sem (Inh_JoinExpr _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_JoinExpr _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_JoinExpr_JoinOn :: Annotation ->
-                       T_ScalarExpr  ->
-                       T_JoinExpr 
-sem_JoinExpr_JoinOn ann_ expr_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _exprOexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: JoinExpr 
-              _lhsOfixedUpIdentifiersTree :: JoinExpr 
-              _lhsOoriginalTree :: JoinExpr 
-              _exprOcat :: Catalog
-              _exprOidenv :: IDEnv
-              _exprOlib :: LocalBindings
-              _exprIannotatedTree :: ScalarExpr 
-              _exprIfixedUpIdentifiersTree :: ScalarExpr 
-              _exprIoriginalTree :: ScalarExpr 
-              _exprIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 94, column 14)
-              _exprOexpectedType =
-                  Just typeBool
-              -- self rule
-              _annotatedTree =
-                  JoinOn ann_ _exprIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  JoinOn ann_ _exprIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  JoinOn ann_ _exprIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _exprOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exprOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exprOlib =
-                  _lhsIlib
-              ( _exprIannotatedTree,_exprIfixedUpIdentifiersTree,_exprIoriginalTree,_exprIuType) =
-                  expr_ _exprOcat _exprOexpectedType _exprOidenv _exprOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_JoinExpr_JoinUsing :: Annotation ->
-                          ([NameComponent]) ->
-                          T_JoinExpr 
-sem_JoinExpr_JoinUsing ann_ x_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: JoinExpr 
-              _lhsOfixedUpIdentifiersTree :: JoinExpr 
-              _lhsOoriginalTree :: JoinExpr 
-              -- self rule
-              _annotatedTree =
-                  JoinUsing ann_ x_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  JoinUsing ann_ x_
-              -- self rule
-              _originalTree =
-                  JoinUsing ann_ x_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- MaybeBoolExpr -----------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative Just:
-         child just           : ScalarExpr 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nothing:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type MaybeBoolExpr  = Maybe ScalarExpr 
--- cata
-sem_MaybeBoolExpr :: MaybeBoolExpr  ->
-                     T_MaybeBoolExpr 
-sem_MaybeBoolExpr (Prelude.Just x )  =
-    (sem_MaybeBoolExpr_Just (sem_ScalarExpr x ) )
-sem_MaybeBoolExpr Prelude.Nothing  =
-    sem_MaybeBoolExpr_Nothing
--- semantic domain
-type T_MaybeBoolExpr  = Catalog ->
-                        IDEnv ->
-                        LocalBindings ->
-                        ( MaybeBoolExpr ,MaybeBoolExpr ,MaybeBoolExpr )
-data Inh_MaybeBoolExpr  = Inh_MaybeBoolExpr {cat_Inh_MaybeBoolExpr :: Catalog,idenv_Inh_MaybeBoolExpr :: IDEnv,lib_Inh_MaybeBoolExpr :: LocalBindings}
-data Syn_MaybeBoolExpr  = Syn_MaybeBoolExpr {annotatedTree_Syn_MaybeBoolExpr :: MaybeBoolExpr ,fixedUpIdentifiersTree_Syn_MaybeBoolExpr :: MaybeBoolExpr ,originalTree_Syn_MaybeBoolExpr :: MaybeBoolExpr }
-wrap_MaybeBoolExpr :: T_MaybeBoolExpr  ->
-                      Inh_MaybeBoolExpr  ->
-                      Syn_MaybeBoolExpr 
-wrap_MaybeBoolExpr sem (Inh_MaybeBoolExpr _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_MaybeBoolExpr _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_MaybeBoolExpr_Just :: T_ScalarExpr  ->
-                          T_MaybeBoolExpr 
-sem_MaybeBoolExpr_Just just_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: MaybeBoolExpr 
-              _justOexpectedType :: (Maybe Type)
-              _lhsOfixedUpIdentifiersTree :: MaybeBoolExpr 
-              _lhsOoriginalTree :: MaybeBoolExpr 
-              _justOcat :: Catalog
-              _justOidenv :: IDEnv
-              _justOlib :: LocalBindings
-              _justIannotatedTree :: ScalarExpr 
-              _justIfixedUpIdentifiersTree :: ScalarExpr 
-              _justIoriginalTree :: ScalarExpr 
-              _justIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 139, column 9)
-              _lhsOannotatedTree =
-                  let t = _justIuType
-                  in if t `elem` [Nothing,Just typeBool]
-                     then Just _justIannotatedTree
-                     else Just $ addTypeErrors [ExpressionMustBeBool] _justIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 97, column 12)
-              _justOexpectedType =
-                  Just typeBool
-              -- self rule
-              _annotatedTree =
-                  Just _justIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Just _justIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Just _justIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _justOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _justOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _justOlib =
-                  _lhsIlib
-              ( _justIannotatedTree,_justIfixedUpIdentifiersTree,_justIoriginalTree,_justIuType) =
-                  just_ _justOcat _justOexpectedType _justOidenv _justOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_MaybeBoolExpr_Nothing :: T_MaybeBoolExpr 
-sem_MaybeBoolExpr_Nothing  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: MaybeBoolExpr 
-              _lhsOfixedUpIdentifiersTree :: MaybeBoolExpr 
-              _lhsOoriginalTree :: MaybeBoolExpr 
-              -- self rule
-              _annotatedTree =
-                  Nothing
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Nothing
-              -- self rule
-              _originalTree =
-                  Nothing
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- MaybeNameComponentList --------------------------------------
-{-
-   alternatives:
-      alternative Just:
-         child just           : NameComponentList 
-      alternative Nothing:
--}
-type MaybeNameComponentList  = Maybe NameComponentList 
--- cata
-sem_MaybeNameComponentList :: MaybeNameComponentList  ->
-                              T_MaybeNameComponentList 
-sem_MaybeNameComponentList (Prelude.Just x )  =
-    (sem_MaybeNameComponentList_Just (sem_NameComponentList x ) )
-sem_MaybeNameComponentList Prelude.Nothing  =
-    sem_MaybeNameComponentList_Nothing
--- semantic domain
-type T_MaybeNameComponentList  = ( )
-data Inh_MaybeNameComponentList  = Inh_MaybeNameComponentList {}
-data Syn_MaybeNameComponentList  = Syn_MaybeNameComponentList {}
-wrap_MaybeNameComponentList :: T_MaybeNameComponentList  ->
-                               Inh_MaybeNameComponentList  ->
-                               Syn_MaybeNameComponentList 
-wrap_MaybeNameComponentList sem (Inh_MaybeNameComponentList )  =
-    (let ( ) = sem 
-     in  (Syn_MaybeNameComponentList ))
-sem_MaybeNameComponentList_Just :: T_NameComponentList  ->
-                                   T_MaybeNameComponentList 
-sem_MaybeNameComponentList_Just just_  =
-    (let 
-     in  ( ))
-sem_MaybeNameComponentList_Nothing :: T_MaybeNameComponentList 
-sem_MaybeNameComponentList_Nothing  =
-    (let 
-     in  ( ))
--- MaybeScalarExpr ---------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-         uType                : Maybe Type
-   alternatives:
-      alternative Just:
-         child just           : ScalarExpr 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nothing:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type MaybeScalarExpr  = Maybe ScalarExpr 
--- cata
-sem_MaybeScalarExpr :: MaybeScalarExpr  ->
-                       T_MaybeScalarExpr 
-sem_MaybeScalarExpr (Prelude.Just x )  =
-    (sem_MaybeScalarExpr_Just (sem_ScalarExpr x ) )
-sem_MaybeScalarExpr Prelude.Nothing  =
-    sem_MaybeScalarExpr_Nothing
--- semantic domain
-type T_MaybeScalarExpr  = Catalog ->
-                          IDEnv ->
-                          LocalBindings ->
-                          ( MaybeScalarExpr ,MaybeScalarExpr ,MaybeScalarExpr ,(Maybe Type))
-data Inh_MaybeScalarExpr  = Inh_MaybeScalarExpr {cat_Inh_MaybeScalarExpr :: Catalog,idenv_Inh_MaybeScalarExpr :: IDEnv,lib_Inh_MaybeScalarExpr :: LocalBindings}
-data Syn_MaybeScalarExpr  = Syn_MaybeScalarExpr {annotatedTree_Syn_MaybeScalarExpr :: MaybeScalarExpr ,fixedUpIdentifiersTree_Syn_MaybeScalarExpr :: MaybeScalarExpr ,originalTree_Syn_MaybeScalarExpr :: MaybeScalarExpr ,uType_Syn_MaybeScalarExpr :: (Maybe Type)}
-wrap_MaybeScalarExpr :: T_MaybeScalarExpr  ->
-                        Inh_MaybeScalarExpr  ->
-                        Syn_MaybeScalarExpr 
-wrap_MaybeScalarExpr sem (Inh_MaybeScalarExpr _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_MaybeScalarExpr _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree _lhsOuType ))
-sem_MaybeScalarExpr_Just :: T_ScalarExpr  ->
-                            T_MaybeScalarExpr 
-sem_MaybeScalarExpr_Just just_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOuType :: (Maybe Type)
-              _justOexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: MaybeScalarExpr 
-              _lhsOfixedUpIdentifiersTree :: MaybeScalarExpr 
-              _lhsOoriginalTree :: MaybeScalarExpr 
-              _justOcat :: Catalog
-              _justOidenv :: IDEnv
-              _justOlib :: LocalBindings
-              _justIannotatedTree :: ScalarExpr 
-              _justIfixedUpIdentifiersTree :: ScalarExpr 
-              _justIoriginalTree :: ScalarExpr 
-              _justIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 131, column 12)
-              _lhsOuType =
-                  _justIuType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 100, column 12)
-              _justOexpectedType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  Just _justIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Just _justIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Just _justIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _justOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _justOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _justOlib =
-                  _lhsIlib
-              ( _justIannotatedTree,_justIfixedUpIdentifiersTree,_justIoriginalTree,_justIuType) =
-                  just_ _justOcat _justOexpectedType _justOidenv _justOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_MaybeScalarExpr_Nothing :: T_MaybeScalarExpr 
-sem_MaybeScalarExpr_Nothing  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOuType :: (Maybe Type)
-              _lhsOannotatedTree :: MaybeScalarExpr 
-              _lhsOfixedUpIdentifiersTree :: MaybeScalarExpr 
-              _lhsOoriginalTree :: MaybeScalarExpr 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 132, column 15)
-              _lhsOuType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  Nothing
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Nothing
-              -- self rule
-              _originalTree =
-                  Nothing
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
--- MaybeSelectList ---------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         listType             : [(String,Maybe Type)]
-         originalTree         : SELF 
-   alternatives:
-      alternative Just:
-         child just           : SelectList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nothing:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type MaybeSelectList  = Maybe SelectList 
--- cata
-sem_MaybeSelectList :: MaybeSelectList  ->
-                       T_MaybeSelectList 
-sem_MaybeSelectList (Prelude.Just x )  =
-    (sem_MaybeSelectList_Just (sem_SelectList x ) )
-sem_MaybeSelectList Prelude.Nothing  =
-    sem_MaybeSelectList_Nothing
--- semantic domain
-type T_MaybeSelectList  = Catalog ->
-                          IDEnv ->
-                          LocalBindings ->
-                          ( MaybeSelectList ,MaybeSelectList ,([(String,Maybe Type)]),MaybeSelectList )
-data Inh_MaybeSelectList  = Inh_MaybeSelectList {cat_Inh_MaybeSelectList :: Catalog,idenv_Inh_MaybeSelectList :: IDEnv,lib_Inh_MaybeSelectList :: LocalBindings}
-data Syn_MaybeSelectList  = Syn_MaybeSelectList {annotatedTree_Syn_MaybeSelectList :: MaybeSelectList ,fixedUpIdentifiersTree_Syn_MaybeSelectList :: MaybeSelectList ,listType_Syn_MaybeSelectList :: ([(String,Maybe Type)]),originalTree_Syn_MaybeSelectList :: MaybeSelectList }
-wrap_MaybeSelectList :: T_MaybeSelectList  ->
-                        Inh_MaybeSelectList  ->
-                        Syn_MaybeSelectList 
-wrap_MaybeSelectList sem (Inh_MaybeSelectList _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlistType,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_MaybeSelectList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOlistType _lhsOoriginalTree ))
-sem_MaybeSelectList_Just :: T_SelectList  ->
-                            T_MaybeSelectList 
-sem_MaybeSelectList_Just just_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOlistType :: ([(String,Maybe Type)])
-              _lhsOannotatedTree :: MaybeSelectList 
-              _lhsOfixedUpIdentifiersTree :: MaybeSelectList 
-              _lhsOoriginalTree :: MaybeSelectList 
-              _justOcat :: Catalog
-              _justOidenv :: IDEnv
-              _justOlib :: LocalBindings
-              _justIannotatedTree :: SelectList 
-              _justIcidenv :: IDEnv
-              _justIfixedUpIdentifiersTree :: SelectList 
-              _justIlibUpdates :: ([LocalBindingsUpdate])
-              _justIlistType :: ([(String,Maybe Type)])
-              _justIoriginalTree :: SelectList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 38, column 12)
-              _lhsOlistType =
-                  _justIlistType
-              -- self rule
-              _annotatedTree =
-                  Just _justIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Just _justIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Just _justIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _justOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _justOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _justOlib =
-                  _lhsIlib
-              ( _justIannotatedTree,_justIcidenv,_justIfixedUpIdentifiersTree,_justIlibUpdates,_justIlistType,_justIoriginalTree) =
-                  just_ _justOcat _justOidenv _justOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlistType,_lhsOoriginalTree)))
-sem_MaybeSelectList_Nothing :: T_MaybeSelectList 
-sem_MaybeSelectList_Nothing  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOlistType :: ([(String,Maybe Type)])
-              _lhsOannotatedTree :: MaybeSelectList 
-              _lhsOfixedUpIdentifiersTree :: MaybeSelectList 
-              _lhsOoriginalTree :: MaybeSelectList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 39, column 15)
-              _lhsOlistType =
-                  []
-              -- self rule
-              _annotatedTree =
-                  Nothing
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Nothing
-              -- self rule
-              _originalTree =
-                  Nothing
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlistType,_lhsOoriginalTree)))
--- Name --------------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-         tbAnnotatedTree      : Name 
-         tbUType              : Maybe ([(String,Type)],[(String,Type)])
-   alternatives:
-      alternative Name:
-         child ann            : {Annotation}
-         child is             : {[NameComponent]}
-         visit 0:
-            local tpe         : {E ([(String,Type)],[(String,Type)])}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data Name  = Name (Annotation) (([NameComponent])) 
-           deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_Name :: Name  ->
-            T_Name 
-sem_Name (Name _ann _is )  =
-    (sem_Name_Name _ann _is )
--- semantic domain
-type T_Name  = Catalog ->
-               IDEnv ->
-               LocalBindings ->
-               ( Name ,Name ,Name ,Name ,(Maybe ([(String,Type)],[(String,Type)])))
-data Inh_Name  = Inh_Name {cat_Inh_Name :: Catalog,idenv_Inh_Name :: IDEnv,lib_Inh_Name :: LocalBindings}
-data Syn_Name  = Syn_Name {annotatedTree_Syn_Name :: Name ,fixedUpIdentifiersTree_Syn_Name :: Name ,originalTree_Syn_Name :: Name ,tbAnnotatedTree_Syn_Name :: Name ,tbUType_Syn_Name :: (Maybe ([(String,Type)],[(String,Type)]))}
-wrap_Name :: T_Name  ->
-             Inh_Name  ->
-             Syn_Name 
-wrap_Name sem (Inh_Name _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOtbAnnotatedTree,_lhsOtbUType) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_Name _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree _lhsOtbAnnotatedTree _lhsOtbUType ))
-sem_Name_Name :: Annotation ->
-                 ([NameComponent]) ->
-                 T_Name 
-sem_Name_Name ann_ is_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _tpe :: (E ([(String,Type)],[(String,Type)]))
-              _lhsOtbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _lhsOtbAnnotatedTree :: Name 
-              _lhsOannotatedTree :: Name 
-              _lhsOfixedUpIdentifiersTree :: Name 
-              _lhsOoriginalTree :: Name 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 67, column 9)
-              _tpe =
-                  catCompositeAttrsPair _lhsIcat relationComposites
-                     (getUnqual is_)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 69, column 9)
-              _lhsOtbUType =
-                  either (const Nothing) Just _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 70, column 9)
-              _lhsOtbAnnotatedTree =
-                  updateAnnotation
-                    (\a -> a {errs = errs a ++ tes _tpe    }) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 73, column 9)
-              _backTree =
-                  Name ann_ is_
-              -- self rule
-              _annotatedTree =
-                  Name ann_ is_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Name ann_ is_
-              -- self rule
-              _originalTree =
-                  Name ann_ is_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOtbAnnotatedTree,_lhsOtbUType)))
--- NameComponentList -------------------------------------------
-{-
-   alternatives:
-      alternative Cons:
-         child hd             : {NameComponent}
-         child tl             : NameComponentList 
-      alternative Nil:
--}
-type NameComponentList  = [(NameComponent)]
--- cata
-sem_NameComponentList :: NameComponentList  ->
-                         T_NameComponentList 
-sem_NameComponentList list  =
-    (Prelude.foldr sem_NameComponentList_Cons sem_NameComponentList_Nil list )
--- semantic domain
-type T_NameComponentList  = ( )
-data Inh_NameComponentList  = Inh_NameComponentList {}
-data Syn_NameComponentList  = Syn_NameComponentList {}
-wrap_NameComponentList :: T_NameComponentList  ->
-                          Inh_NameComponentList  ->
-                          Syn_NameComponentList 
-wrap_NameComponentList sem (Inh_NameComponentList )  =
-    (let ( ) = sem 
-     in  (Syn_NameComponentList ))
-sem_NameComponentList_Cons :: NameComponent ->
-                              T_NameComponentList  ->
-                              T_NameComponentList 
-sem_NameComponentList_Cons hd_ tl_  =
-    (let 
-     in  ( ))
-sem_NameComponentList_Nil :: T_NameComponentList 
-sem_NameComponentList_Nil  =
-    (let 
-     in  ( ))
--- NameTypeNameListPair ----------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         fnSig                : (Name,[Maybe Type])
-         originalTree         : SELF 
-   alternatives:
-      alternative Tuple:
-         child x1             : Name 
-         child x2             : TypeNameList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type NameTypeNameListPair  = ( Name ,TypeNameList )
--- cata
-sem_NameTypeNameListPair :: NameTypeNameListPair  ->
-                            T_NameTypeNameListPair 
-sem_NameTypeNameListPair ( x1,x2)  =
-    (sem_NameTypeNameListPair_Tuple (sem_Name x1 ) (sem_TypeNameList x2 ) )
--- semantic domain
-type T_NameTypeNameListPair  = Catalog ->
-                               IDEnv ->
-                               LocalBindings ->
-                               ( NameTypeNameListPair ,NameTypeNameListPair ,((Name,[Maybe Type])),NameTypeNameListPair )
-data Inh_NameTypeNameListPair  = Inh_NameTypeNameListPair {cat_Inh_NameTypeNameListPair :: Catalog,idenv_Inh_NameTypeNameListPair :: IDEnv,lib_Inh_NameTypeNameListPair :: LocalBindings}
-data Syn_NameTypeNameListPair  = Syn_NameTypeNameListPair {annotatedTree_Syn_NameTypeNameListPair :: NameTypeNameListPair ,fixedUpIdentifiersTree_Syn_NameTypeNameListPair :: NameTypeNameListPair ,fnSig_Syn_NameTypeNameListPair :: ((Name,[Maybe Type])),originalTree_Syn_NameTypeNameListPair :: NameTypeNameListPair }
-wrap_NameTypeNameListPair :: T_NameTypeNameListPair  ->
-                             Inh_NameTypeNameListPair  ->
-                             Syn_NameTypeNameListPair 
-wrap_NameTypeNameListPair sem (Inh_NameTypeNameListPair _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOfnSig,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_NameTypeNameListPair _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOfnSig _lhsOoriginalTree ))
-sem_NameTypeNameListPair_Tuple :: T_Name  ->
-                                  T_TypeNameList  ->
-                                  T_NameTypeNameListPair 
-sem_NameTypeNameListPair_Tuple x1_ x2_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOfnSig :: ((Name,[Maybe Type]))
-              _lhsOannotatedTree :: NameTypeNameListPair 
-              _lhsOfixedUpIdentifiersTree :: NameTypeNameListPair 
-              _lhsOoriginalTree :: NameTypeNameListPair 
-              _x1Ocat :: Catalog
-              _x1Oidenv :: IDEnv
-              _x1Olib :: LocalBindings
-              _x2Ocat :: Catalog
-              _x2Oidenv :: IDEnv
-              _x2Olib :: LocalBindings
-              _x1IannotatedTree :: Name 
-              _x1IfixedUpIdentifiersTree :: Name 
-              _x1IoriginalTree :: Name 
-              _x1ItbAnnotatedTree :: Name 
-              _x1ItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _x2IannotatedTree :: TypeNameList 
-              _x2IfixedUpIdentifiersTree :: TypeNameList 
-              _x2InamedTypes :: ([Maybe Type])
-              _x2IoriginalTree :: TypeNameList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/Drops.ag"(line 32, column 13)
-              _lhsOfnSig =
-                  (_x1IoriginalTree, _x2InamedTypes)
-              -- self rule
-              _annotatedTree =
-                  (_x1IannotatedTree,_x2IannotatedTree)
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (_x1IfixedUpIdentifiersTree,_x2IfixedUpIdentifiersTree)
-              -- self rule
-              _originalTree =
-                  (_x1IoriginalTree,_x2IoriginalTree)
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _x1Ocat =
-                  _lhsIcat
-              -- copy rule (down)
-              _x1Oidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _x1Olib =
-                  _lhsIlib
-              -- copy rule (down)
-              _x2Ocat =
-                  _lhsIcat
-              -- copy rule (down)
-              _x2Oidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _x2Olib =
-                  _lhsIlib
-              ( _x1IannotatedTree,_x1IfixedUpIdentifiersTree,_x1IoriginalTree,_x1ItbAnnotatedTree,_x1ItbUType) =
-                  x1_ _x1Ocat _x1Oidenv _x1Olib 
-              ( _x2IannotatedTree,_x2IfixedUpIdentifiersTree,_x2InamedTypes,_x2IoriginalTree) =
-                  x2_ _x2Ocat _x2Oidenv _x2Olib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOfnSig,_lhsOoriginalTree)))
--- NameTypeNameListPairList ------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         fnSigs               : [(Name,[Maybe Type])]
-         originalTree         : SELF 
-   alternatives:
-      alternative Cons:
-         child hd             : NameTypeNameListPair 
-         child tl             : NameTypeNameListPairList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type NameTypeNameListPairList  = [NameTypeNameListPair ]
--- cata
-sem_NameTypeNameListPairList :: NameTypeNameListPairList  ->
-                                T_NameTypeNameListPairList 
-sem_NameTypeNameListPairList list  =
-    (Prelude.foldr sem_NameTypeNameListPairList_Cons sem_NameTypeNameListPairList_Nil (Prelude.map sem_NameTypeNameListPair list) )
--- semantic domain
-type T_NameTypeNameListPairList  = Catalog ->
-                                   IDEnv ->
-                                   LocalBindings ->
-                                   ( NameTypeNameListPairList ,NameTypeNameListPairList ,([(Name,[Maybe Type])]),NameTypeNameListPairList )
-data Inh_NameTypeNameListPairList  = Inh_NameTypeNameListPairList {cat_Inh_NameTypeNameListPairList :: Catalog,idenv_Inh_NameTypeNameListPairList :: IDEnv,lib_Inh_NameTypeNameListPairList :: LocalBindings}
-data Syn_NameTypeNameListPairList  = Syn_NameTypeNameListPairList {annotatedTree_Syn_NameTypeNameListPairList :: NameTypeNameListPairList ,fixedUpIdentifiersTree_Syn_NameTypeNameListPairList :: NameTypeNameListPairList ,fnSigs_Syn_NameTypeNameListPairList :: ([(Name,[Maybe Type])]),originalTree_Syn_NameTypeNameListPairList :: NameTypeNameListPairList }
-wrap_NameTypeNameListPairList :: T_NameTypeNameListPairList  ->
-                                 Inh_NameTypeNameListPairList  ->
-                                 Syn_NameTypeNameListPairList 
-wrap_NameTypeNameListPairList sem (Inh_NameTypeNameListPairList _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOfnSigs,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_NameTypeNameListPairList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOfnSigs _lhsOoriginalTree ))
-sem_NameTypeNameListPairList_Cons :: T_NameTypeNameListPair  ->
-                                     T_NameTypeNameListPairList  ->
-                                     T_NameTypeNameListPairList 
-sem_NameTypeNameListPairList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOfnSigs :: ([(Name,[Maybe Type])])
-              _lhsOannotatedTree :: NameTypeNameListPairList 
-              _lhsOfixedUpIdentifiersTree :: NameTypeNameListPairList 
-              _lhsOoriginalTree :: NameTypeNameListPairList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: NameTypeNameListPair 
-              _hdIfixedUpIdentifiersTree :: NameTypeNameListPair 
-              _hdIfnSig :: ((Name,[Maybe Type]))
-              _hdIoriginalTree :: NameTypeNameListPair 
-              _tlIannotatedTree :: NameTypeNameListPairList 
-              _tlIfixedUpIdentifiersTree :: NameTypeNameListPairList 
-              _tlIfnSigs :: ([(Name,[Maybe Type])])
-              _tlIoriginalTree :: NameTypeNameListPairList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/Drops.ag"(line 27, column 12)
-              _lhsOfnSigs =
-                  _hdIfnSig : _tlIfnSigs
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIfixedUpIdentifiersTree,_hdIfnSig,_hdIoriginalTree) =
-                  hd_ _hdOcat _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIfixedUpIdentifiersTree,_tlIfnSigs,_tlIoriginalTree) =
-                  tl_ _tlOcat _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOfnSigs,_lhsOoriginalTree)))
-sem_NameTypeNameListPairList_Nil :: T_NameTypeNameListPairList 
-sem_NameTypeNameListPairList_Nil  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOfnSigs :: ([(Name,[Maybe Type])])
-              _lhsOannotatedTree :: NameTypeNameListPairList 
-              _lhsOfixedUpIdentifiersTree :: NameTypeNameListPairList 
-              _lhsOoriginalTree :: NameTypeNameListPairList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/Drops.ag"(line 28, column 11)
-              _lhsOfnSigs =
-                  []
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOfnSigs,_lhsOoriginalTree)))
--- OnExpr ------------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative Just:
-         child just           : JoinExpr 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nothing:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type OnExpr  = Maybe JoinExpr 
--- cata
-sem_OnExpr :: OnExpr  ->
-              T_OnExpr 
-sem_OnExpr (Prelude.Just x )  =
-    (sem_OnExpr_Just (sem_JoinExpr x ) )
-sem_OnExpr Prelude.Nothing  =
-    sem_OnExpr_Nothing
--- semantic domain
-type T_OnExpr  = Catalog ->
-                 IDEnv ->
-                 LocalBindings ->
-                 ( OnExpr ,OnExpr ,OnExpr )
-data Inh_OnExpr  = Inh_OnExpr {cat_Inh_OnExpr :: Catalog,idenv_Inh_OnExpr :: IDEnv,lib_Inh_OnExpr :: LocalBindings}
-data Syn_OnExpr  = Syn_OnExpr {annotatedTree_Syn_OnExpr :: OnExpr ,fixedUpIdentifiersTree_Syn_OnExpr :: OnExpr ,originalTree_Syn_OnExpr :: OnExpr }
-wrap_OnExpr :: T_OnExpr  ->
-               Inh_OnExpr  ->
-               Syn_OnExpr 
-wrap_OnExpr sem (Inh_OnExpr _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_OnExpr _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_OnExpr_Just :: T_JoinExpr  ->
-                   T_OnExpr 
-sem_OnExpr_Just just_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: OnExpr 
-              _lhsOfixedUpIdentifiersTree :: OnExpr 
-              _lhsOoriginalTree :: OnExpr 
-              _justOcat :: Catalog
-              _justOidenv :: IDEnv
-              _justOlib :: LocalBindings
-              _justIannotatedTree :: JoinExpr 
-              _justIfixedUpIdentifiersTree :: JoinExpr 
-              _justIoriginalTree :: JoinExpr 
-              -- self rule
-              _annotatedTree =
-                  Just _justIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Just _justIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Just _justIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _justOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _justOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _justOlib =
-                  _lhsIlib
-              ( _justIannotatedTree,_justIfixedUpIdentifiersTree,_justIoriginalTree) =
-                  just_ _justOcat _justOidenv _justOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_OnExpr_Nothing :: T_OnExpr 
-sem_OnExpr_Nothing  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: OnExpr 
-              _lhsOfixedUpIdentifiersTree :: OnExpr 
-              _lhsOoriginalTree :: OnExpr 
-              -- self rule
-              _annotatedTree =
-                  Nothing
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Nothing
-              -- self rule
-              _originalTree =
-                  Nothing
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- ParamDef ----------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-         pos                  : Int
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         namedType            : Maybe Type
-         originalTree         : SELF 
-         paramName            : ParamName
-   alternatives:
-      alternative ParamDef:
-         child ann            : {Annotation}
-         child name           : {NameComponent}
-         child typ            : TypeName 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative ParamDefTp:
-         child ann            : {Annotation}
-         child typ            : TypeName 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data ParamDef  = ParamDef (Annotation) (NameComponent) (TypeName ) 
-               | ParamDefTp (Annotation) (TypeName ) 
-               deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_ParamDef :: ParamDef  ->
-                T_ParamDef 
-sem_ParamDef (ParamDef _ann _name _typ )  =
-    (sem_ParamDef_ParamDef _ann _name (sem_TypeName _typ ) )
-sem_ParamDef (ParamDefTp _ann _typ )  =
-    (sem_ParamDef_ParamDefTp _ann (sem_TypeName _typ ) )
--- semantic domain
-type T_ParamDef  = Catalog ->
-                   IDEnv ->
-                   LocalBindings ->
-                   Int ->
-                   ( ParamDef ,ParamDef ,(Maybe Type),ParamDef ,ParamName)
-data Inh_ParamDef  = Inh_ParamDef {cat_Inh_ParamDef :: Catalog,idenv_Inh_ParamDef :: IDEnv,lib_Inh_ParamDef :: LocalBindings,pos_Inh_ParamDef :: Int}
-data Syn_ParamDef  = Syn_ParamDef {annotatedTree_Syn_ParamDef :: ParamDef ,fixedUpIdentifiersTree_Syn_ParamDef :: ParamDef ,namedType_Syn_ParamDef :: (Maybe Type),originalTree_Syn_ParamDef :: ParamDef ,paramName_Syn_ParamDef :: ParamName}
-wrap_ParamDef :: T_ParamDef  ->
-                 Inh_ParamDef  ->
-                 Syn_ParamDef 
-wrap_ParamDef sem (Inh_ParamDef _lhsIcat _lhsIidenv _lhsIlib _lhsIpos )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOnamedType,_lhsOoriginalTree,_lhsOparamName) = sem _lhsIcat _lhsIidenv _lhsIlib _lhsIpos 
-     in  (Syn_ParamDef _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOnamedType _lhsOoriginalTree _lhsOparamName ))
-sem_ParamDef_ParamDef :: Annotation ->
-                         NameComponent ->
-                         T_TypeName  ->
-                         T_ParamDef 
-sem_ParamDef_ParamDef ann_ name_ typ_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib
-       _lhsIpos ->
-         (let _lhsOnamedType :: (Maybe Type)
-              _lhsOparamName :: ParamName
-              _lhsOannotatedTree :: ParamDef 
-              _lhsOfixedUpIdentifiersTree :: ParamDef 
-              _lhsOoriginalTree :: ParamDef 
-              _typOcat :: Catalog
-              _typOidenv :: IDEnv
-              _typOlib :: LocalBindings
-              _typIannotatedTree :: TypeName 
-              _typIfixedUpIdentifiersTree :: TypeName 
-              _typInamedType :: (Maybe Type)
-              _typIoriginalTree :: TypeName 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateFunction.ag"(line 45, column 9)
-              _lhsOnamedType =
-                  _typInamedType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateFunction.ag"(line 47, column 9)
-              _lhsOparamName =
-                  NamedParam _lhsIpos (ncStr name_)
-              -- self rule
-              _annotatedTree =
-                  ParamDef ann_ name_ _typIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  ParamDef ann_ name_ _typIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  ParamDef ann_ name_ _typIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _typOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _typOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _typOlib =
-                  _lhsIlib
-              ( _typIannotatedTree,_typIfixedUpIdentifiersTree,_typInamedType,_typIoriginalTree) =
-                  typ_ _typOcat _typOidenv _typOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOnamedType,_lhsOoriginalTree,_lhsOparamName)))
-sem_ParamDef_ParamDefTp :: Annotation ->
-                           T_TypeName  ->
-                           T_ParamDef 
-sem_ParamDef_ParamDefTp ann_ typ_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib
-       _lhsIpos ->
-         (let _lhsOnamedType :: (Maybe Type)
-              _lhsOparamName :: ParamName
-              _lhsOannotatedTree :: ParamDef 
-              _lhsOfixedUpIdentifiersTree :: ParamDef 
-              _lhsOoriginalTree :: ParamDef 
-              _typOcat :: Catalog
-              _typOidenv :: IDEnv
-              _typOlib :: LocalBindings
-              _typIannotatedTree :: TypeName 
-              _typIfixedUpIdentifiersTree :: TypeName 
-              _typInamedType :: (Maybe Type)
-              _typIoriginalTree :: TypeName 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateFunction.ag"(line 45, column 9)
-              _lhsOnamedType =
-                  _typInamedType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateFunction.ag"(line 49, column 9)
-              _lhsOparamName =
-                  UnnamedParam _lhsIpos
-              -- self rule
-              _annotatedTree =
-                  ParamDefTp ann_ _typIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  ParamDefTp ann_ _typIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  ParamDefTp ann_ _typIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _typOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _typOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _typOlib =
-                  _lhsIlib
-              ( _typIannotatedTree,_typIfixedUpIdentifiersTree,_typInamedType,_typIoriginalTree) =
-                  typ_ _typOcat _typOidenv _typOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOnamedType,_lhsOoriginalTree,_lhsOparamName)))
--- ParamDefList ------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-         pos                  : Int
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-         params               : [(ParamName, Maybe Type)]
-   alternatives:
-      alternative Cons:
-         child hd             : ParamDef 
-         child tl             : ParamDefList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type ParamDefList  = [ParamDef ]
--- cata
-sem_ParamDefList :: ParamDefList  ->
-                    T_ParamDefList 
-sem_ParamDefList list  =
-    (Prelude.foldr sem_ParamDefList_Cons sem_ParamDefList_Nil (Prelude.map sem_ParamDef list) )
--- semantic domain
-type T_ParamDefList  = Catalog ->
-                       IDEnv ->
-                       LocalBindings ->
-                       Int ->
-                       ( ParamDefList ,ParamDefList ,ParamDefList ,([(ParamName, Maybe Type)]))
-data Inh_ParamDefList  = Inh_ParamDefList {cat_Inh_ParamDefList :: Catalog,idenv_Inh_ParamDefList :: IDEnv,lib_Inh_ParamDefList :: LocalBindings,pos_Inh_ParamDefList :: Int}
-data Syn_ParamDefList  = Syn_ParamDefList {annotatedTree_Syn_ParamDefList :: ParamDefList ,fixedUpIdentifiersTree_Syn_ParamDefList :: ParamDefList ,originalTree_Syn_ParamDefList :: ParamDefList ,params_Syn_ParamDefList :: ([(ParamName, Maybe Type)])}
-wrap_ParamDefList :: T_ParamDefList  ->
-                     Inh_ParamDefList  ->
-                     Syn_ParamDefList 
-wrap_ParamDefList sem (Inh_ParamDefList _lhsIcat _lhsIidenv _lhsIlib _lhsIpos )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOparams) = sem _lhsIcat _lhsIidenv _lhsIlib _lhsIpos 
-     in  (Syn_ParamDefList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree _lhsOparams ))
-sem_ParamDefList_Cons :: T_ParamDef  ->
-                         T_ParamDefList  ->
-                         T_ParamDefList 
-sem_ParamDefList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib
-       _lhsIpos ->
-         (let _lhsOparams :: ([(ParamName, Maybe Type)])
-              _hdOpos :: Int
-              _tlOpos :: Int
-              _lhsOannotatedTree :: ParamDefList 
-              _lhsOfixedUpIdentifiersTree :: ParamDefList 
-              _lhsOoriginalTree :: ParamDefList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: ParamDef 
-              _hdIfixedUpIdentifiersTree :: ParamDef 
-              _hdInamedType :: (Maybe Type)
-              _hdIoriginalTree :: ParamDef 
-              _hdIparamName :: ParamName
-              _tlIannotatedTree :: ParamDefList 
-              _tlIfixedUpIdentifiersTree :: ParamDefList 
-              _tlIoriginalTree :: ParamDefList 
-              _tlIparams :: ([(ParamName, Maybe Type)])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateFunction.ag"(line 53, column 13)
-              _lhsOparams =
-                  ((_hdIparamName, _hdInamedType) : _tlIparams)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateFunction.ag"(line 54, column 13)
-              _hdOpos =
-                  _lhsIpos
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateFunction.ag"(line 55, column 13)
-              _tlOpos =
-                  _lhsIpos + 1
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIfixedUpIdentifiersTree,_hdInamedType,_hdIoriginalTree,_hdIparamName) =
-                  hd_ _hdOcat _hdOidenv _hdOlib _hdOpos 
-              ( _tlIannotatedTree,_tlIfixedUpIdentifiersTree,_tlIoriginalTree,_tlIparams) =
-                  tl_ _tlOcat _tlOidenv _tlOlib _tlOpos 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOparams)))
-sem_ParamDefList_Nil :: T_ParamDefList 
-sem_ParamDefList_Nil  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib
-       _lhsIpos ->
-         (let _lhsOparams :: ([(ParamName, Maybe Type)])
-              _lhsOannotatedTree :: ParamDefList 
-              _lhsOfixedUpIdentifiersTree :: ParamDefList 
-              _lhsOoriginalTree :: ParamDefList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateFunction.ag"(line 52, column 12)
-              _lhsOparams =
-                  []
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOparams)))
--- QueryExpr ---------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         csql                 : LocalBindings
-         expectedTypes        : [Maybe Type]
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         cidenv               : IDEnv
-         fixedUpIdentifiersTree : SELF 
-         libUpdates           : [LocalBindingsUpdate]
-         originalTree         : SELF 
-         uType                : Maybe [(String,Type)]
-   alternatives:
-      alternative CombineQueryExpr:
-         child ann            : {Annotation}
-         child ctype          : {CombineType}
-         child sel1           : QueryExpr 
-         child sel2           : QueryExpr 
-         visit 0:
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Select:
-         child ann            : {Annotation}
-         child selDistinct    : {Distinct}
-         child selSelectList  : SelectList 
-         child selTref        : TableRefList 
-         child selWhere       : MaybeBoolExpr 
-         child selGroupBy     : ScalarExprList 
-         child selHaving      : MaybeBoolExpr 
-         child selOrderBy     : ScalarExprDirectionPairList 
-         child selLimit       : MaybeScalarExpr 
-         child selOffset      : MaybeScalarExpr 
-         visit 0:
-            local trefEnv     : _
-            local includeCorrelations : _
-            local newLib      : _
-            local slTypes     : {LocalBindings}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Values:
-         child ann            : {Annotation}
-         child vll            : ScalarExprListList 
-         visit 0:
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative WithQueryExpr:
-         child ann            : {Annotation}
-         child withs          : WithQueryList 
-         child ex             : QueryExpr 
-         visit 0:
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data QueryExpr  = CombineQueryExpr (Annotation) (CombineType) (QueryExpr ) (QueryExpr ) 
-                | Select (Annotation) (Distinct) (SelectList ) (TableRefList ) (MaybeBoolExpr ) (ScalarExprList ) (MaybeBoolExpr ) (ScalarExprDirectionPairList ) (MaybeScalarExpr ) (MaybeScalarExpr ) 
-                | Values (Annotation) (ScalarExprListList ) 
-                | WithQueryExpr (Annotation) (WithQueryList ) (QueryExpr ) 
-                deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_QueryExpr :: QueryExpr  ->
-                 T_QueryExpr 
-sem_QueryExpr (CombineQueryExpr _ann _ctype _sel1 _sel2 )  =
-    (sem_QueryExpr_CombineQueryExpr _ann _ctype (sem_QueryExpr _sel1 ) (sem_QueryExpr _sel2 ) )
-sem_QueryExpr (Select _ann _selDistinct _selSelectList _selTref _selWhere _selGroupBy _selHaving _selOrderBy _selLimit _selOffset )  =
-    (sem_QueryExpr_Select _ann _selDistinct (sem_SelectList _selSelectList ) (sem_TableRefList _selTref ) (sem_MaybeBoolExpr _selWhere ) (sem_ScalarExprList _selGroupBy ) (sem_MaybeBoolExpr _selHaving ) (sem_ScalarExprDirectionPairList _selOrderBy ) (sem_MaybeScalarExpr _selLimit ) (sem_MaybeScalarExpr _selOffset ) )
-sem_QueryExpr (Values _ann _vll )  =
-    (sem_QueryExpr_Values _ann (sem_ScalarExprListList _vll ) )
-sem_QueryExpr (WithQueryExpr _ann _withs _ex )  =
-    (sem_QueryExpr_WithQueryExpr _ann (sem_WithQueryList _withs ) (sem_QueryExpr _ex ) )
--- semantic domain
-type T_QueryExpr  = Catalog ->
-                    LocalBindings ->
-                    ([Maybe Type]) ->
-                    IDEnv ->
-                    LocalBindings ->
-                    ( QueryExpr ,IDEnv,QueryExpr ,([LocalBindingsUpdate]),QueryExpr ,(Maybe [(String,Type)]))
-data Inh_QueryExpr  = Inh_QueryExpr {cat_Inh_QueryExpr :: Catalog,csql_Inh_QueryExpr :: LocalBindings,expectedTypes_Inh_QueryExpr :: ([Maybe Type]),idenv_Inh_QueryExpr :: IDEnv,lib_Inh_QueryExpr :: LocalBindings}
-data Syn_QueryExpr  = Syn_QueryExpr {annotatedTree_Syn_QueryExpr :: QueryExpr ,cidenv_Syn_QueryExpr :: IDEnv,fixedUpIdentifiersTree_Syn_QueryExpr :: QueryExpr ,libUpdates_Syn_QueryExpr :: ([LocalBindingsUpdate]),originalTree_Syn_QueryExpr :: QueryExpr ,uType_Syn_QueryExpr :: (Maybe [(String,Type)])}
-wrap_QueryExpr :: T_QueryExpr  ->
-                  Inh_QueryExpr  ->
-                  Syn_QueryExpr 
-wrap_QueryExpr sem (Inh_QueryExpr _lhsIcat _lhsIcsql _lhsIexpectedTypes _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOcidenv,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree,_lhsOuType) = sem _lhsIcat _lhsIcsql _lhsIexpectedTypes _lhsIidenv _lhsIlib 
-     in  (Syn_QueryExpr _lhsOannotatedTree _lhsOcidenv _lhsOfixedUpIdentifiersTree _lhsOlibUpdates _lhsOoriginalTree _lhsOuType ))
-sem_QueryExpr_CombineQueryExpr :: Annotation ->
-                                  CombineType ->
-                                  T_QueryExpr  ->
-                                  T_QueryExpr  ->
-                                  T_QueryExpr 
-sem_QueryExpr_CombineQueryExpr ann_ ctype_ sel1_ sel2_  =
-    (\ _lhsIcat
-       _lhsIcsql
-       _lhsIexpectedTypes
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOcidenv :: IDEnv
-              _lhsOannotatedTree :: QueryExpr 
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _tpe :: Et
-              _lhsOuType :: (Maybe [(String,Type)])
-              _lhsOfixedUpIdentifiersTree :: QueryExpr 
-              _lhsOoriginalTree :: QueryExpr 
-              _sel1Ocat :: Catalog
-              _sel1Ocsql :: LocalBindings
-              _sel1OexpectedTypes :: ([Maybe Type])
-              _sel1Oidenv :: IDEnv
-              _sel1Olib :: LocalBindings
-              _sel2Ocat :: Catalog
-              _sel2Ocsql :: LocalBindings
-              _sel2OexpectedTypes :: ([Maybe Type])
-              _sel2Oidenv :: IDEnv
-              _sel2Olib :: LocalBindings
-              _sel1IannotatedTree :: QueryExpr 
-              _sel1Icidenv :: IDEnv
-              _sel1IfixedUpIdentifiersTree :: QueryExpr 
-              _sel1IlibUpdates :: ([LocalBindingsUpdate])
-              _sel1IoriginalTree :: QueryExpr 
-              _sel1IuType :: (Maybe [(String,Type)])
-              _sel2IannotatedTree :: QueryExpr 
-              _sel2Icidenv :: IDEnv
-              _sel2IfixedUpIdentifiersTree :: QueryExpr 
-              _sel2IlibUpdates :: ([LocalBindingsUpdate])
-              _sel2IoriginalTree :: QueryExpr 
-              _sel2IuType :: (Maybe [(String,Type)])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 237, column 24)
-              _lhsOcidenv =
-                  _sel1Icidenv
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 29, column 9)
-              _lhsOannotatedTree =
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 141, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 168, column 9)
-              _tpe =
-                  do
-                  sel1t <- lmt ((SetOfType . CompositeType) <$> _sel1IuType)
-                  sel2t <- lmt ((SetOfType . CompositeType) <$> _sel2IuType)
-                  typeCheckCombineSelect _lhsIcat sel1t sel2t
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 174, column 9)
-              _backTree =
-                  CombineQueryExpr ann_ ctype_
-                                _sel1IannotatedTree
-                                _sel2IannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 185, column 9)
-              _lhsOuType =
-                  etmt (_tpe     >>= unwrapSetOfComposite)
-              -- self rule
-              _annotatedTree =
-                  CombineQueryExpr ann_ ctype_ _sel1IannotatedTree _sel2IannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  CombineQueryExpr ann_ ctype_ _sel1IfixedUpIdentifiersTree _sel2IfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  CombineQueryExpr ann_ ctype_ _sel1IoriginalTree _sel2IoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _sel1Ocat =
-                  _lhsIcat
-              -- copy rule (down)
-              _sel1Ocsql =
-                  _lhsIcsql
-              -- copy rule (down)
-              _sel1OexpectedTypes =
-                  _lhsIexpectedTypes
-              -- copy rule (down)
-              _sel1Oidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _sel1Olib =
-                  _lhsIlib
-              -- copy rule (down)
-              _sel2Ocat =
-                  _lhsIcat
-              -- copy rule (down)
-              _sel2Ocsql =
-                  _lhsIcsql
-              -- copy rule (down)
-              _sel2OexpectedTypes =
-                  _lhsIexpectedTypes
-              -- copy rule (down)
-              _sel2Oidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _sel2Olib =
-                  _lhsIlib
-              ( _sel1IannotatedTree,_sel1Icidenv,_sel1IfixedUpIdentifiersTree,_sel1IlibUpdates,_sel1IoriginalTree,_sel1IuType) =
-                  sel1_ _sel1Ocat _sel1Ocsql _sel1OexpectedTypes _sel1Oidenv _sel1Olib 
-              ( _sel2IannotatedTree,_sel2Icidenv,_sel2IfixedUpIdentifiersTree,_sel2IlibUpdates,_sel2IoriginalTree,_sel2IuType) =
-                  sel2_ _sel2Ocat _sel2Ocsql _sel2OexpectedTypes _sel2Oidenv _sel2Olib 
-          in  ( _lhsOannotatedTree,_lhsOcidenv,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree,_lhsOuType)))
-sem_QueryExpr_Select :: Annotation ->
-                        Distinct ->
-                        T_SelectList  ->
-                        T_TableRefList  ->
-                        T_MaybeBoolExpr  ->
-                        T_ScalarExprList  ->
-                        T_MaybeBoolExpr  ->
-                        T_ScalarExprDirectionPairList  ->
-                        T_MaybeScalarExpr  ->
-                        T_MaybeScalarExpr  ->
-                        T_QueryExpr 
-sem_QueryExpr_Select ann_ selDistinct_ selSelectList_ selTref_ selWhere_ selGroupBy_ selHaving_ selOrderBy_ selLimit_ selOffset_  =
-    (\ _lhsIcat
-       _lhsIcsql
-       _lhsIexpectedTypes
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOfixedUpIdentifiersTree :: QueryExpr 
-              _lhsOcidenv :: IDEnv
-              _selSelectListOidenv :: IDEnv
-              _selWhereOidenv :: IDEnv
-              _selGroupByOidenv :: IDEnv
-              _selHavingOidenv :: IDEnv
-              _selOrderByOidenv :: IDEnv
-              _lhsOannotatedTree :: QueryExpr 
-              _selSelectListOlib :: LocalBindings
-              _selWhereOlib :: LocalBindings
-              _selHavingOlib :: LocalBindings
-              _selGroupByOlib :: LocalBindings
-              _slTypes :: LocalBindings
-              _selOrderByOlib :: LocalBindings
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _tpe :: Et
-              _lhsOuType :: (Maybe [(String,Type)])
-              _selGroupByOexpectedTypes :: ([Maybe Type])
-              _lhsOoriginalTree :: QueryExpr 
-              _selSelectListOcat :: Catalog
-              _selTrefOcat :: Catalog
-              _selTrefOidenv :: IDEnv
-              _selTrefOlib :: LocalBindings
-              _selWhereOcat :: Catalog
-              _selGroupByOcat :: Catalog
-              _selHavingOcat :: Catalog
-              _selOrderByOcat :: Catalog
-              _selLimitOcat :: Catalog
-              _selLimitOidenv :: IDEnv
-              _selLimitOlib :: LocalBindings
-              _selOffsetOcat :: Catalog
-              _selOffsetOidenv :: IDEnv
-              _selOffsetOlib :: LocalBindings
-              _selSelectListIannotatedTree :: SelectList 
-              _selSelectListIcidenv :: IDEnv
-              _selSelectListIfixedUpIdentifiersTree :: SelectList 
-              _selSelectListIlibUpdates :: ([LocalBindingsUpdate])
-              _selSelectListIlistType :: ([(String,Maybe Type)])
-              _selSelectListIoriginalTree :: SelectList 
-              _selTrefIannotatedTree :: TableRefList 
-              _selTrefIfixedUpIdentifiersTree :: TableRefList 
-              _selTrefIlibUpdates :: ([LocalBindingsUpdate])
-              _selTrefInewLib2 :: LocalBindings
-              _selTrefIoriginalTree :: TableRefList 
-              _selTrefItrefIDs :: IDEnv
-              _selWhereIannotatedTree :: MaybeBoolExpr 
-              _selWhereIfixedUpIdentifiersTree :: MaybeBoolExpr 
-              _selWhereIoriginalTree :: MaybeBoolExpr 
-              _selGroupByIannotatedTree :: ScalarExprList 
-              _selGroupByIfixedUpIdentifiersTree :: ScalarExprList 
-              _selGroupByIoriginalTree :: ScalarExprList 
-              _selGroupByIuType :: ([Maybe Type])
-              _selHavingIannotatedTree :: MaybeBoolExpr 
-              _selHavingIfixedUpIdentifiersTree :: MaybeBoolExpr 
-              _selHavingIoriginalTree :: MaybeBoolExpr 
-              _selOrderByIannotatedTree :: ScalarExprDirectionPairList 
-              _selOrderByIfixedUpIdentifiersTree :: ScalarExprDirectionPairList 
-              _selOrderByIoriginalTree :: ScalarExprDirectionPairList 
-              _selLimitIannotatedTree :: MaybeScalarExpr 
-              _selLimitIfixedUpIdentifiersTree :: MaybeScalarExpr 
-              _selLimitIoriginalTree :: MaybeScalarExpr 
-              _selLimitIuType :: (Maybe Type)
-              _selOffsetIannotatedTree :: MaybeScalarExpr 
-              _selOffsetIfixedUpIdentifiersTree :: MaybeScalarExpr 
-              _selOffsetIoriginalTree :: MaybeScalarExpr 
-              _selOffsetIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 194, column 9)
-              _lhsOfixedUpIdentifiersTree =
-                  Select ann_
-                         selDistinct_
-                         _selSelectListIfixedUpIdentifiersTree
-                         _selTrefIfixedUpIdentifiersTree
-                         _selWhereIfixedUpIdentifiersTree
-                         _selGroupByIfixedUpIdentifiersTree
-                         _selHavingIfixedUpIdentifiersTree
-                         _selOrderByIfixedUpIdentifiersTree
-                         _selLimitIfixedUpIdentifiersTree
-                         _selOffsetIfixedUpIdentifiersTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 236, column 14)
-              _lhsOcidenv =
-                  _selSelectListIcidenv
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 282, column 14)
-              _trefEnv =
-                  _selTrefItrefIDs
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 283, column 14)
-              _includeCorrelations =
-                  CorrelatedIDEnv _trefEnv     _lhsIidenv
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 284, column 14)
-              _selSelectListOidenv =
-                  _trefEnv
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 285, column 14)
-              _selWhereOidenv =
-                  _includeCorrelations
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 286, column 14)
-              _selGroupByOidenv =
-                  _trefEnv
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 287, column 14)
-              _selHavingOidenv =
-                  _includeCorrelations
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 288, column 14)
-              _selOrderByOidenv =
-                  _trefEnv
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 29, column 9)
-              _lhsOannotatedTree =
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 101, column 10)
-              _newLib =
-                  _selTrefInewLib2
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 102, column 10)
-              _selSelectListOlib =
-                  _newLib
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 104, column 10)
-              _selWhereOlib =
-                  joinBindings _newLib     _lhsIcsql
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 105, column 10)
-              _selHavingOlib =
-                  joinBindings _newLib     _lhsIcsql
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 106, column 10)
-              _selGroupByOlib =
-                  _newLib
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 111, column 10)
-              _slTypes =
-                  createLocalBindings $ Just [("",_selSelectListIlistType)]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 112, column 10)
-              _selOrderByOlib =
-                  joinBindings _slTypes     _newLib
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 143, column 9)
-              _lhsOlibUpdates =
-                  _selSelectListIlibUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 155, column 9)
-              _tpe =
-                  Right $ SetOfType $ CompositeType $ fromMaybe [] $ liftList  _selSelectListIlistType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 157, column 9)
-              _backTree =
-                  Select ann_
-                         selDistinct_
-                         _selSelectListIannotatedTree
-                         _selTrefIannotatedTree
-                         _selWhereIannotatedTree
-                         _selGroupByIannotatedTree
-                         _selHavingIannotatedTree
-                         _selOrderByIannotatedTree
-                         _selLimitIannotatedTree
-                         _selOffsetIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 185, column 9)
-              _lhsOuType =
-                  etmt (_tpe     >>= unwrapSetOfComposite)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 148, column 14)
-              _selGroupByOexpectedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  Select ann_ selDistinct_ _selSelectListIannotatedTree _selTrefIannotatedTree _selWhereIannotatedTree _selGroupByIannotatedTree _selHavingIannotatedTree _selOrderByIannotatedTree _selLimitIannotatedTree _selOffsetIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Select ann_ selDistinct_ _selSelectListIfixedUpIdentifiersTree _selTrefIfixedUpIdentifiersTree _selWhereIfixedUpIdentifiersTree _selGroupByIfixedUpIdentifiersTree _selHavingIfixedUpIdentifiersTree _selOrderByIfixedUpIdentifiersTree _selLimitIfixedUpIdentifiersTree _selOffsetIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Select ann_ selDistinct_ _selSelectListIoriginalTree _selTrefIoriginalTree _selWhereIoriginalTree _selGroupByIoriginalTree _selHavingIoriginalTree _selOrderByIoriginalTree _selLimitIoriginalTree _selOffsetIoriginalTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _selSelectListOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _selTrefOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _selTrefOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _selTrefOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _selWhereOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _selGroupByOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _selHavingOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _selOrderByOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _selLimitOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _selLimitOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _selLimitOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _selOffsetOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _selOffsetOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _selOffsetOlib =
-                  _lhsIlib
-              ( _selSelectListIannotatedTree,_selSelectListIcidenv,_selSelectListIfixedUpIdentifiersTree,_selSelectListIlibUpdates,_selSelectListIlistType,_selSelectListIoriginalTree) =
-                  selSelectList_ _selSelectListOcat _selSelectListOidenv _selSelectListOlib 
-              ( _selTrefIannotatedTree,_selTrefIfixedUpIdentifiersTree,_selTrefIlibUpdates,_selTrefInewLib2,_selTrefIoriginalTree,_selTrefItrefIDs) =
-                  selTref_ _selTrefOcat _selTrefOidenv _selTrefOlib 
-              ( _selWhereIannotatedTree,_selWhereIfixedUpIdentifiersTree,_selWhereIoriginalTree) =
-                  selWhere_ _selWhereOcat _selWhereOidenv _selWhereOlib 
-              ( _selGroupByIannotatedTree,_selGroupByIfixedUpIdentifiersTree,_selGroupByIoriginalTree,_selGroupByIuType) =
-                  selGroupBy_ _selGroupByOcat _selGroupByOexpectedTypes _selGroupByOidenv _selGroupByOlib 
-              ( _selHavingIannotatedTree,_selHavingIfixedUpIdentifiersTree,_selHavingIoriginalTree) =
-                  selHaving_ _selHavingOcat _selHavingOidenv _selHavingOlib 
-              ( _selOrderByIannotatedTree,_selOrderByIfixedUpIdentifiersTree,_selOrderByIoriginalTree) =
-                  selOrderBy_ _selOrderByOcat _selOrderByOidenv _selOrderByOlib 
-              ( _selLimitIannotatedTree,_selLimitIfixedUpIdentifiersTree,_selLimitIoriginalTree,_selLimitIuType) =
-                  selLimit_ _selLimitOcat _selLimitOidenv _selLimitOlib 
-              ( _selOffsetIannotatedTree,_selOffsetIfixedUpIdentifiersTree,_selOffsetIoriginalTree,_selOffsetIuType) =
-                  selOffset_ _selOffsetOcat _selOffsetOidenv _selOffsetOlib 
-          in  ( _lhsOannotatedTree,_lhsOcidenv,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree,_lhsOuType)))
-sem_QueryExpr_Values :: Annotation ->
-                        T_ScalarExprListList  ->
-                        T_QueryExpr 
-sem_QueryExpr_Values ann_ vll_  =
-    (\ _lhsIcat
-       _lhsIcsql
-       _lhsIexpectedTypes
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOcidenv :: IDEnv
-              _lhsOannotatedTree :: QueryExpr 
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _tpe :: Et
-              _lhsOuType :: (Maybe [(String,Type)])
-              _vllOexpectedTypes :: ([Maybe Type])
-              _lhsOfixedUpIdentifiersTree :: QueryExpr 
-              _lhsOoriginalTree :: QueryExpr 
-              _vllOcat :: Catalog
-              _vllOidenv :: IDEnv
-              _vllOlib :: LocalBindings
-              _vllIannotatedTree :: ScalarExprListList 
-              _vllIfixedUpIdentifiersTree :: ScalarExprListList 
-              _vllIoriginalTree :: ScalarExprListList 
-              _vllIuType :: ([[Maybe Type]])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 238, column 14)
-              _lhsOcidenv =
-                  emptyIDEnv "values"
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 29, column 9)
-              _lhsOannotatedTree =
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 141, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 150, column 9)
-              _tpe =
-                  typeCheckValuesExpr
-                              _lhsIcat
-                              _vllIuType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 153, column 9)
-              _backTree =
-                  Values ann_ _vllIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 185, column 9)
-              _lhsOuType =
-                  etmt (_tpe     >>= unwrapSetOfComposite)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 162, column 14)
-              _vllOexpectedTypes =
-                  _lhsIexpectedTypes
-              -- self rule
-              _annotatedTree =
-                  Values ann_ _vllIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Values ann_ _vllIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Values ann_ _vllIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _vllOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _vllOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _vllOlib =
-                  _lhsIlib
-              ( _vllIannotatedTree,_vllIfixedUpIdentifiersTree,_vllIoriginalTree,_vllIuType) =
-                  vll_ _vllOcat _vllOexpectedTypes _vllOidenv _vllOlib 
-          in  ( _lhsOannotatedTree,_lhsOcidenv,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree,_lhsOuType)))
-sem_QueryExpr_WithQueryExpr :: Annotation ->
-                               T_WithQueryList  ->
-                               T_QueryExpr  ->
-                               T_QueryExpr 
-sem_QueryExpr_WithQueryExpr ann_ withs_ ex_  =
-    (\ _lhsIcat
-       _lhsIcsql
-       _lhsIexpectedTypes
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOcidenv :: IDEnv
-              _exOidenv :: IDEnv
-              _lhsOannotatedTree :: QueryExpr 
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _tpe :: Et
-              _exOcat :: Catalog
-              _withsOcatUpdates :: ([CatalogUpdate])
-              _lhsOuType :: (Maybe [(String,Type)])
-              _lhsOfixedUpIdentifiersTree :: QueryExpr 
-              _lhsOoriginalTree :: QueryExpr 
-              _withsOcat :: Catalog
-              _withsOidenv :: IDEnv
-              _withsOlib :: LocalBindings
-              _exOcsql :: LocalBindings
-              _exOexpectedTypes :: ([Maybe Type])
-              _exOlib :: LocalBindings
-              _withsIannotatedTree :: WithQueryList 
-              _withsIcidenv :: IDEnv
-              _withsIfixedUpIdentifiersTree :: WithQueryList 
-              _withsIoriginalTree :: WithQueryList 
-              _withsIproducedCat :: Catalog
-              _exIannotatedTree :: QueryExpr 
-              _exIcidenv :: IDEnv
-              _exIfixedUpIdentifiersTree :: QueryExpr 
-              _exIlibUpdates :: ([LocalBindingsUpdate])
-              _exIoriginalTree :: QueryExpr 
-              _exIuType :: (Maybe [(String,Type)])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 239, column 21)
-              _lhsOcidenv =
-                  _exIcidenv
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 240, column 21)
-              _exOidenv =
-                  _exIcidenv
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 29, column 9)
-              _lhsOannotatedTree =
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 145, column 9)
-              _lhsOlibUpdates =
-                  _exIlibUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 178, column 9)
-              _tpe =
-                  lmt ((SetOfType . CompositeType) <$> _exIuType)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 179, column 9)
-              _backTree =
-                  WithQueryExpr ann_ _withsIannotatedTree _exIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 180, column 9)
-              _exOcat =
-                  _withsIproducedCat
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 181, column 9)
-              _withsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 185, column 9)
-              _lhsOuType =
-                  etmt (_tpe     >>= unwrapSetOfComposite)
-              -- self rule
-              _annotatedTree =
-                  WithQueryExpr ann_ _withsIannotatedTree _exIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  WithQueryExpr ann_ _withsIfixedUpIdentifiersTree _exIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  WithQueryExpr ann_ _withsIoriginalTree _exIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _withsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _withsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _withsOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _exOcsql =
-                  _lhsIcsql
-              -- copy rule (down)
-              _exOexpectedTypes =
-                  _lhsIexpectedTypes
-              -- copy rule (down)
-              _exOlib =
-                  _lhsIlib
-              ( _withsIannotatedTree,_withsIcidenv,_withsIfixedUpIdentifiersTree,_withsIoriginalTree,_withsIproducedCat) =
-                  withs_ _withsOcat _withsOcatUpdates _withsOidenv _withsOlib 
-              ( _exIannotatedTree,_exIcidenv,_exIfixedUpIdentifiersTree,_exIlibUpdates,_exIoriginalTree,_exIuType) =
-                  ex_ _exOcat _exOcsql _exOexpectedTypes _exOidenv _exOlib 
-          in  ( _lhsOannotatedTree,_lhsOcidenv,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree,_lhsOuType)))
--- Root --------------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-         producedCat          : Catalog
-         producedLib          : LocalBindings
-   alternatives:
-      alternative Root:
-         child statements     : StatementList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data Root  = Root (StatementList ) 
-           deriving ( Show)
--- cata
-sem_Root :: Root  ->
-            T_Root 
-sem_Root (Root _statements )  =
-    (sem_Root_Root (sem_StatementList _statements ) )
--- semantic domain
-type T_Root  = Catalog ->
-               IDEnv ->
-               LocalBindings ->
-               ( Root ,Root ,Root ,Catalog,LocalBindings)
-data Inh_Root  = Inh_Root {cat_Inh_Root :: Catalog,idenv_Inh_Root :: IDEnv,lib_Inh_Root :: LocalBindings}
-data Syn_Root  = Syn_Root {annotatedTree_Syn_Root :: Root ,fixedUpIdentifiersTree_Syn_Root :: Root ,originalTree_Syn_Root :: Root ,producedCat_Syn_Root :: Catalog,producedLib_Syn_Root :: LocalBindings}
-wrap_Root :: T_Root  ->
-             Inh_Root  ->
-             Syn_Root 
-wrap_Root sem (Inh_Root _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOproducedCat,_lhsOproducedLib) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_Root _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree _lhsOproducedCat _lhsOproducedLib ))
-sem_Root_Root :: T_StatementList  ->
-                 T_Root 
-sem_Root_Root statements_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _statementsOcatUpdates :: ([CatalogUpdate])
-              _statementsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Root 
-              _lhsOfixedUpIdentifiersTree :: Root 
-              _lhsOoriginalTree :: Root 
-              _lhsOproducedCat :: Catalog
-              _lhsOproducedLib :: LocalBindings
-              _statementsOcat :: Catalog
-              _statementsOidenv :: IDEnv
-              _statementsOlib :: LocalBindings
-              _statementsIannotatedTree :: StatementList 
-              _statementsIfixedUpIdentifiersTree :: StatementList 
-              _statementsIoriginalTree :: StatementList 
-              _statementsIproducedCat :: Catalog
-              _statementsIproducedLib :: LocalBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 107, column 12)
-              _statementsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 108, column 12)
-              _statementsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  Root _statementsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Root _statementsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Root _statementsIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (up)
-              _lhsOproducedCat =
-                  _statementsIproducedCat
-              -- copy rule (up)
-              _lhsOproducedLib =
-                  _statementsIproducedLib
-              -- copy rule (down)
-              _statementsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _statementsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _statementsOlib =
-                  _lhsIlib
-              ( _statementsIannotatedTree,_statementsIfixedUpIdentifiersTree,_statementsIoriginalTree,_statementsIproducedCat,_statementsIproducedLib) =
-                  statements_ _statementsOcat _statementsOcatUpdates _statementsOidenv _statementsOlib _statementsOlibUpdates 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOproducedCat,_lhsOproducedLib)))
--- RowConstraint -----------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative NotNullConstraint:
-         child ann            : {Annotation}
-         child name           : {String}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative NullConstraint:
-         child ann            : {Annotation}
-         child name           : {String}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative RowCheckConstraint:
-         child ann            : {Annotation}
-         child name           : {String}
-         child expr           : ScalarExpr 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative RowPrimaryKeyConstraint:
-         child ann            : {Annotation}
-         child name           : {String}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative RowReferenceConstraint:
-         child ann            : {Annotation}
-         child name           : {String}
-         child table          : Name 
-         child att            : {Maybe NameComponent}
-         child onUpdate       : {Cascade}
-         child onDelete       : {Cascade}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative RowUniqueConstraint:
-         child ann            : {Annotation}
-         child name           : {String}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data RowConstraint  = NotNullConstraint (Annotation) (String) 
-                    | NullConstraint (Annotation) (String) 
-                    | RowCheckConstraint (Annotation) (String) (ScalarExpr ) 
-                    | RowPrimaryKeyConstraint (Annotation) (String) 
-                    | RowReferenceConstraint (Annotation) (String) (Name ) ((Maybe NameComponent)) (Cascade) (Cascade) 
-                    | RowUniqueConstraint (Annotation) (String) 
-                    deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_RowConstraint :: RowConstraint  ->
-                     T_RowConstraint 
-sem_RowConstraint (NotNullConstraint _ann _name )  =
-    (sem_RowConstraint_NotNullConstraint _ann _name )
-sem_RowConstraint (NullConstraint _ann _name )  =
-    (sem_RowConstraint_NullConstraint _ann _name )
-sem_RowConstraint (RowCheckConstraint _ann _name _expr )  =
-    (sem_RowConstraint_RowCheckConstraint _ann _name (sem_ScalarExpr _expr ) )
-sem_RowConstraint (RowPrimaryKeyConstraint _ann _name )  =
-    (sem_RowConstraint_RowPrimaryKeyConstraint _ann _name )
-sem_RowConstraint (RowReferenceConstraint _ann _name _table _att _onUpdate _onDelete )  =
-    (sem_RowConstraint_RowReferenceConstraint _ann _name (sem_Name _table ) _att _onUpdate _onDelete )
-sem_RowConstraint (RowUniqueConstraint _ann _name )  =
-    (sem_RowConstraint_RowUniqueConstraint _ann _name )
--- semantic domain
-type T_RowConstraint  = Catalog ->
-                        IDEnv ->
-                        LocalBindings ->
-                        ( RowConstraint ,RowConstraint ,RowConstraint )
-data Inh_RowConstraint  = Inh_RowConstraint {cat_Inh_RowConstraint :: Catalog,idenv_Inh_RowConstraint :: IDEnv,lib_Inh_RowConstraint :: LocalBindings}
-data Syn_RowConstraint  = Syn_RowConstraint {annotatedTree_Syn_RowConstraint :: RowConstraint ,fixedUpIdentifiersTree_Syn_RowConstraint :: RowConstraint ,originalTree_Syn_RowConstraint :: RowConstraint }
-wrap_RowConstraint :: T_RowConstraint  ->
-                      Inh_RowConstraint  ->
-                      Syn_RowConstraint 
-wrap_RowConstraint sem (Inh_RowConstraint _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_RowConstraint _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_RowConstraint_NotNullConstraint :: Annotation ->
-                                       String ->
-                                       T_RowConstraint 
-sem_RowConstraint_NotNullConstraint ann_ name_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: RowConstraint 
-              _lhsOfixedUpIdentifiersTree :: RowConstraint 
-              _lhsOoriginalTree :: RowConstraint 
-              -- self rule
-              _annotatedTree =
-                  NotNullConstraint ann_ name_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  NotNullConstraint ann_ name_
-              -- self rule
-              _originalTree =
-                  NotNullConstraint ann_ name_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_RowConstraint_NullConstraint :: Annotation ->
-                                    String ->
-                                    T_RowConstraint 
-sem_RowConstraint_NullConstraint ann_ name_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: RowConstraint 
-              _lhsOfixedUpIdentifiersTree :: RowConstraint 
-              _lhsOoriginalTree :: RowConstraint 
-              -- self rule
-              _annotatedTree =
-                  NullConstraint ann_ name_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  NullConstraint ann_ name_
-              -- self rule
-              _originalTree =
-                  NullConstraint ann_ name_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_RowConstraint_RowCheckConstraint :: Annotation ->
-                                        String ->
-                                        T_ScalarExpr  ->
-                                        T_RowConstraint 
-sem_RowConstraint_RowCheckConstraint ann_ name_ expr_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _exprOexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: RowConstraint 
-              _lhsOfixedUpIdentifiersTree :: RowConstraint 
-              _lhsOoriginalTree :: RowConstraint 
-              _exprOcat :: Catalog
-              _exprOidenv :: IDEnv
-              _exprOlib :: LocalBindings
-              _exprIannotatedTree :: ScalarExpr 
-              _exprIfixedUpIdentifiersTree :: ScalarExpr 
-              _exprIoriginalTree :: ScalarExpr 
-              _exprIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 103, column 26)
-              _exprOexpectedType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  RowCheckConstraint ann_ name_ _exprIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  RowCheckConstraint ann_ name_ _exprIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  RowCheckConstraint ann_ name_ _exprIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _exprOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exprOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exprOlib =
-                  _lhsIlib
-              ( _exprIannotatedTree,_exprIfixedUpIdentifiersTree,_exprIoriginalTree,_exprIuType) =
-                  expr_ _exprOcat _exprOexpectedType _exprOidenv _exprOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_RowConstraint_RowPrimaryKeyConstraint :: Annotation ->
-                                             String ->
-                                             T_RowConstraint 
-sem_RowConstraint_RowPrimaryKeyConstraint ann_ name_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: RowConstraint 
-              _lhsOfixedUpIdentifiersTree :: RowConstraint 
-              _lhsOoriginalTree :: RowConstraint 
-              -- self rule
-              _annotatedTree =
-                  RowPrimaryKeyConstraint ann_ name_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  RowPrimaryKeyConstraint ann_ name_
-              -- self rule
-              _originalTree =
-                  RowPrimaryKeyConstraint ann_ name_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_RowConstraint_RowReferenceConstraint :: Annotation ->
-                                            String ->
-                                            T_Name  ->
-                                            (Maybe NameComponent) ->
-                                            Cascade ->
-                                            Cascade ->
-                                            T_RowConstraint 
-sem_RowConstraint_RowReferenceConstraint ann_ name_ table_ att_ onUpdate_ onDelete_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: RowConstraint 
-              _lhsOfixedUpIdentifiersTree :: RowConstraint 
-              _lhsOoriginalTree :: RowConstraint 
-              _tableOcat :: Catalog
-              _tableOidenv :: IDEnv
-              _tableOlib :: LocalBindings
-              _tableIannotatedTree :: Name 
-              _tableIfixedUpIdentifiersTree :: Name 
-              _tableIoriginalTree :: Name 
-              _tableItbAnnotatedTree :: Name 
-              _tableItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              -- self rule
-              _annotatedTree =
-                  RowReferenceConstraint ann_ name_ _tableIannotatedTree att_ onUpdate_ onDelete_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  RowReferenceConstraint ann_ name_ _tableIfixedUpIdentifiersTree att_ onUpdate_ onDelete_
-              -- self rule
-              _originalTree =
-                  RowReferenceConstraint ann_ name_ _tableIoriginalTree att_ onUpdate_ onDelete_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _tableOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tableOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tableOlib =
-                  _lhsIlib
-              ( _tableIannotatedTree,_tableIfixedUpIdentifiersTree,_tableIoriginalTree,_tableItbAnnotatedTree,_tableItbUType) =
-                  table_ _tableOcat _tableOidenv _tableOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_RowConstraint_RowUniqueConstraint :: Annotation ->
-                                         String ->
-                                         T_RowConstraint 
-sem_RowConstraint_RowUniqueConstraint ann_ name_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: RowConstraint 
-              _lhsOfixedUpIdentifiersTree :: RowConstraint 
-              _lhsOoriginalTree :: RowConstraint 
-              -- self rule
-              _annotatedTree =
-                  RowUniqueConstraint ann_ name_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  RowUniqueConstraint ann_ name_
-              -- self rule
-              _originalTree =
-                  RowUniqueConstraint ann_ name_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- RowConstraintList -------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative Cons:
-         child hd             : RowConstraint 
-         child tl             : RowConstraintList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type RowConstraintList  = [RowConstraint ]
--- cata
-sem_RowConstraintList :: RowConstraintList  ->
-                         T_RowConstraintList 
-sem_RowConstraintList list  =
-    (Prelude.foldr sem_RowConstraintList_Cons sem_RowConstraintList_Nil (Prelude.map sem_RowConstraint list) )
--- semantic domain
-type T_RowConstraintList  = Catalog ->
-                            IDEnv ->
-                            LocalBindings ->
-                            ( RowConstraintList ,RowConstraintList ,RowConstraintList )
-data Inh_RowConstraintList  = Inh_RowConstraintList {cat_Inh_RowConstraintList :: Catalog,idenv_Inh_RowConstraintList :: IDEnv,lib_Inh_RowConstraintList :: LocalBindings}
-data Syn_RowConstraintList  = Syn_RowConstraintList {annotatedTree_Syn_RowConstraintList :: RowConstraintList ,fixedUpIdentifiersTree_Syn_RowConstraintList :: RowConstraintList ,originalTree_Syn_RowConstraintList :: RowConstraintList }
-wrap_RowConstraintList :: T_RowConstraintList  ->
-                          Inh_RowConstraintList  ->
-                          Syn_RowConstraintList 
-wrap_RowConstraintList sem (Inh_RowConstraintList _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_RowConstraintList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_RowConstraintList_Cons :: T_RowConstraint  ->
-                              T_RowConstraintList  ->
-                              T_RowConstraintList 
-sem_RowConstraintList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: RowConstraintList 
-              _lhsOfixedUpIdentifiersTree :: RowConstraintList 
-              _lhsOoriginalTree :: RowConstraintList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: RowConstraint 
-              _hdIfixedUpIdentifiersTree :: RowConstraint 
-              _hdIoriginalTree :: RowConstraint 
-              _tlIannotatedTree :: RowConstraintList 
-              _tlIfixedUpIdentifiersTree :: RowConstraintList 
-              _tlIoriginalTree :: RowConstraintList 
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIfixedUpIdentifiersTree,_hdIoriginalTree) =
-                  hd_ _hdOcat _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIfixedUpIdentifiersTree,_tlIoriginalTree) =
-                  tl_ _tlOcat _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_RowConstraintList_Nil :: T_RowConstraintList 
-sem_RowConstraintList_Nil  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: RowConstraintList 
-              _lhsOfixedUpIdentifiersTree :: RowConstraintList 
-              _lhsOoriginalTree :: RowConstraintList 
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- ScalarExpr --------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         expectedType         : Maybe Type
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-         uType                : Maybe Type
-   alternatives:
-      alternative AggregateFn:
-         child ann            : {Annotation}
-         child aggDistinct    : {Distinct}
-         child fn             : ScalarExpr 
-         child orderBy        : ScalarExprDirectionPairList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative AntiScalarExpr:
-         child string         : {String}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative BooleanLit:
-         child ann            : {Annotation}
-         child b              : {Bool}
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Case:
-         child ann            : {Annotation}
-         child cases          : CaseScalarExprListScalarExprPairList 
-         child els            : MaybeScalarExpr 
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local whenTypes   : _
-            local thenTypes   : _
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative CaseSimple:
-         child ann            : {Annotation}
-         child value          : ScalarExpr 
-         child cases          : CaseScalarExprListScalarExprPairList 
-         child els            : MaybeScalarExpr 
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local whenTypes   : _
-            local thenTypes   : _
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Cast:
-         child ann            : {Annotation}
-         child expr           : ScalarExpr 
-         child tn             : TypeName 
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Exists:
-         child ann            : {Annotation}
-         child sel            : QueryExpr 
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Extract:
-         child ann            : {Annotation}
-         child field          : {ExtractField}
-         child e              : ScalarExpr 
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative FunCall:
-         child ann            : {Annotation}
-         child funName        : Name 
-         child args           : ScalarExprList 
-         visit 0:
-            local _tup1       : _
-            local tpe         : {Et}
-            local prototype   : _
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Identifier:
-         child ann            : {Annotation}
-         child i              : {NameComponent}
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative InPredicate:
-         child ann            : {Annotation}
-         child expr           : ScalarExpr 
-         child i              : {Bool}
-         child list           : InList 
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local rt          : {Either [TypeError] Type}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Interval:
-         child ann            : {Annotation}
-         child value          : {String}
-         child field          : {IntervalField}
-         child prec           : {Maybe Int}
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative LiftOperator:
-         child ann            : {Annotation}
-         child oper           : {String}
-         child flav           : {LiftFlavour}
-         child args           : ScalarExprList 
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative NullLit:
-         child ann            : {Annotation}
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative NumberLit:
-         child ann            : {Annotation}
-         child d              : {String}
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Placeholder:
-         child ann            : {Annotation}
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative PositionalArg:
-         child ann            : {Annotation}
-         child p              : {Integer}
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative QIdentifier:
-         child ann            : {Annotation}
-         child is             : {[NameComponent]}
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative QStar:
-         child ann            : {Annotation}
-         child q              : {NameComponent}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative ScalarSubQuery:
-         child ann            : {Annotation}
-         child sel            : QueryExpr 
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Star:
-         child ann            : {Annotation}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative StringLit:
-         child ann            : {Annotation}
-         child value          : {String}
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative TypedStringLit:
-         child ann            : {Annotation}
-         child tn             : TypeName 
-         child value          : {String}
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative WindowFn:
-         child ann            : {Annotation}
-         child fn             : ScalarExpr 
-         child partitionBy    : ScalarExprList 
-         child orderBy        : ScalarExprDirectionPairList 
-         child frm            : {FrameClause}
-         visit 0:
-            local prototype   : {Maybe FunctionPrototype}
-            local tpe         : {Et}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data ScalarExpr  = AggregateFn (Annotation) (Distinct) (ScalarExpr ) (ScalarExprDirectionPairList ) 
-                 | AntiScalarExpr (String) 
-                 | BooleanLit (Annotation) (Bool) 
-                 | Case (Annotation) (CaseScalarExprListScalarExprPairList ) (MaybeScalarExpr ) 
-                 | CaseSimple (Annotation) (ScalarExpr ) (CaseScalarExprListScalarExprPairList ) (MaybeScalarExpr ) 
-                 | Cast (Annotation) (ScalarExpr ) (TypeName ) 
-                 | Exists (Annotation) (QueryExpr ) 
-                 | Extract (Annotation) (ExtractField) (ScalarExpr ) 
-                 | FunCall (Annotation) (Name ) (ScalarExprList ) 
-                 | Identifier (Annotation) (NameComponent) 
-                 | InPredicate (Annotation) (ScalarExpr ) (Bool) (InList ) 
-                 | Interval (Annotation) (String) (IntervalField) ((Maybe Int)) 
-                 | LiftOperator (Annotation) (String) (LiftFlavour) (ScalarExprList ) 
-                 | NullLit (Annotation) 
-                 | NumberLit (Annotation) (String) 
-                 | Placeholder (Annotation) 
-                 | PositionalArg (Annotation) (Integer) 
-                 | QIdentifier (Annotation) (([NameComponent])) 
-                 | QStar (Annotation) (NameComponent) 
-                 | ScalarSubQuery (Annotation) (QueryExpr ) 
-                 | Star (Annotation) 
-                 | StringLit (Annotation) (String) 
-                 | TypedStringLit (Annotation) (TypeName ) (String) 
-                 | WindowFn (Annotation) (ScalarExpr ) (ScalarExprList ) (ScalarExprDirectionPairList ) (FrameClause) 
-                 deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_ScalarExpr :: ScalarExpr  ->
-                  T_ScalarExpr 
-sem_ScalarExpr (AggregateFn _ann _aggDistinct _fn _orderBy )  =
-    (sem_ScalarExpr_AggregateFn _ann _aggDistinct (sem_ScalarExpr _fn ) (sem_ScalarExprDirectionPairList _orderBy ) )
-sem_ScalarExpr (AntiScalarExpr _string )  =
-    (sem_ScalarExpr_AntiScalarExpr _string )
-sem_ScalarExpr (BooleanLit _ann _b )  =
-    (sem_ScalarExpr_BooleanLit _ann _b )
-sem_ScalarExpr (Case _ann _cases _els )  =
-    (sem_ScalarExpr_Case _ann (sem_CaseScalarExprListScalarExprPairList _cases ) (sem_MaybeScalarExpr _els ) )
-sem_ScalarExpr (CaseSimple _ann _value _cases _els )  =
-    (sem_ScalarExpr_CaseSimple _ann (sem_ScalarExpr _value ) (sem_CaseScalarExprListScalarExprPairList _cases ) (sem_MaybeScalarExpr _els ) )
-sem_ScalarExpr (Cast _ann _expr _tn )  =
-    (sem_ScalarExpr_Cast _ann (sem_ScalarExpr _expr ) (sem_TypeName _tn ) )
-sem_ScalarExpr (Exists _ann _sel )  =
-    (sem_ScalarExpr_Exists _ann (sem_QueryExpr _sel ) )
-sem_ScalarExpr (Extract _ann _field _e )  =
-    (sem_ScalarExpr_Extract _ann _field (sem_ScalarExpr _e ) )
-sem_ScalarExpr (FunCall _ann _funName _args )  =
-    (sem_ScalarExpr_FunCall _ann (sem_Name _funName ) (sem_ScalarExprList _args ) )
-sem_ScalarExpr (Identifier _ann _i )  =
-    (sem_ScalarExpr_Identifier _ann _i )
-sem_ScalarExpr (InPredicate _ann _expr _i _list )  =
-    (sem_ScalarExpr_InPredicate _ann (sem_ScalarExpr _expr ) _i (sem_InList _list ) )
-sem_ScalarExpr (Interval _ann _value _field _prec )  =
-    (sem_ScalarExpr_Interval _ann _value _field _prec )
-sem_ScalarExpr (LiftOperator _ann _oper _flav _args )  =
-    (sem_ScalarExpr_LiftOperator _ann _oper _flav (sem_ScalarExprList _args ) )
-sem_ScalarExpr (NullLit _ann )  =
-    (sem_ScalarExpr_NullLit _ann )
-sem_ScalarExpr (NumberLit _ann _d )  =
-    (sem_ScalarExpr_NumberLit _ann _d )
-sem_ScalarExpr (Placeholder _ann )  =
-    (sem_ScalarExpr_Placeholder _ann )
-sem_ScalarExpr (PositionalArg _ann _p )  =
-    (sem_ScalarExpr_PositionalArg _ann _p )
-sem_ScalarExpr (QIdentifier _ann _is )  =
-    (sem_ScalarExpr_QIdentifier _ann _is )
-sem_ScalarExpr (QStar _ann _q )  =
-    (sem_ScalarExpr_QStar _ann _q )
-sem_ScalarExpr (ScalarSubQuery _ann _sel )  =
-    (sem_ScalarExpr_ScalarSubQuery _ann (sem_QueryExpr _sel ) )
-sem_ScalarExpr (Star _ann )  =
-    (sem_ScalarExpr_Star _ann )
-sem_ScalarExpr (StringLit _ann _value )  =
-    (sem_ScalarExpr_StringLit _ann _value )
-sem_ScalarExpr (TypedStringLit _ann _tn _value )  =
-    (sem_ScalarExpr_TypedStringLit _ann (sem_TypeName _tn ) _value )
-sem_ScalarExpr (WindowFn _ann _fn _partitionBy _orderBy _frm )  =
-    (sem_ScalarExpr_WindowFn _ann (sem_ScalarExpr _fn ) (sem_ScalarExprList _partitionBy ) (sem_ScalarExprDirectionPairList _orderBy ) _frm )
--- semantic domain
-type T_ScalarExpr  = Catalog ->
-                     (Maybe Type) ->
-                     IDEnv ->
-                     LocalBindings ->
-                     ( ScalarExpr ,ScalarExpr ,ScalarExpr ,(Maybe Type))
-data Inh_ScalarExpr  = Inh_ScalarExpr {cat_Inh_ScalarExpr :: Catalog,expectedType_Inh_ScalarExpr :: (Maybe Type),idenv_Inh_ScalarExpr :: IDEnv,lib_Inh_ScalarExpr :: LocalBindings}
-data Syn_ScalarExpr  = Syn_ScalarExpr {annotatedTree_Syn_ScalarExpr :: ScalarExpr ,fixedUpIdentifiersTree_Syn_ScalarExpr :: ScalarExpr ,originalTree_Syn_ScalarExpr :: ScalarExpr ,uType_Syn_ScalarExpr :: (Maybe Type)}
-wrap_ScalarExpr :: T_ScalarExpr  ->
-                   Inh_ScalarExpr  ->
-                   Syn_ScalarExpr 
-wrap_ScalarExpr sem (Inh_ScalarExpr _lhsIcat _lhsIexpectedType _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType) = sem _lhsIcat _lhsIexpectedType _lhsIidenv _lhsIlib 
-     in  (Syn_ScalarExpr _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree _lhsOuType ))
-sem_ScalarExpr_AggregateFn :: Annotation ->
-                              Distinct ->
-                              T_ScalarExpr  ->
-                              T_ScalarExprDirectionPairList  ->
-                              T_ScalarExpr 
-sem_ScalarExpr_AggregateFn ann_ aggDistinct_ fn_ orderBy_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              _lhsOuType :: (Maybe Type)
-              _fnOcat :: Catalog
-              _fnOexpectedType :: (Maybe Type)
-              _fnOidenv :: IDEnv
-              _fnOlib :: LocalBindings
-              _orderByOcat :: Catalog
-              _orderByOidenv :: IDEnv
-              _orderByOlib :: LocalBindings
-              _fnIannotatedTree :: ScalarExpr 
-              _fnIfixedUpIdentifiersTree :: ScalarExpr 
-              _fnIoriginalTree :: ScalarExpr 
-              _fnIuType :: (Maybe Type)
-              _orderByIannotatedTree :: ScalarExprDirectionPairList 
-              _orderByIfixedUpIdentifiersTree :: ScalarExprDirectionPairList 
-              _orderByIoriginalTree :: ScalarExprDirectionPairList 
-              -- self rule
-              _annotatedTree =
-                  AggregateFn ann_ aggDistinct_ _fnIannotatedTree _orderByIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  AggregateFn ann_ aggDistinct_ _fnIfixedUpIdentifiersTree _orderByIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  AggregateFn ann_ aggDistinct_ _fnIoriginalTree _orderByIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (up)
-              _lhsOuType =
-                  _fnIuType
-              -- copy rule (down)
-              _fnOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _fnOexpectedType =
-                  _lhsIexpectedType
-              -- copy rule (down)
-              _fnOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _fnOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _orderByOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _orderByOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _orderByOlib =
-                  _lhsIlib
-              ( _fnIannotatedTree,_fnIfixedUpIdentifiersTree,_fnIoriginalTree,_fnIuType) =
-                  fn_ _fnOcat _fnOexpectedType _fnOidenv _fnOlib 
-              ( _orderByIannotatedTree,_orderByIfixedUpIdentifiersTree,_orderByIoriginalTree) =
-                  orderBy_ _orderByOcat _orderByOidenv _orderByOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_AntiScalarExpr :: String ->
-                                 T_ScalarExpr 
-sem_ScalarExpr_AntiScalarExpr string_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOuType :: (Maybe Type)
-              _lhsOannotatedTree :: ScalarExpr 
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 108, column 9)
-              _lhsOuType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  AntiScalarExpr string_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  AntiScalarExpr string_
-              -- self rule
-              _originalTree =
-                  AntiScalarExpr string_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_BooleanLit :: Annotation ->
-                             Bool ->
-                             T_ScalarExpr 
-sem_ScalarExpr_BooleanLit ann_ b_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 162, column 19)
-              _tpe =
-                  Right typeBool
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 172, column 9)
-              _backTree =
-                  BooleanLit ann_ b_
-              -- self rule
-              _annotatedTree =
-                  BooleanLit ann_ b_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  BooleanLit ann_ b_
-              -- self rule
-              _originalTree =
-                  BooleanLit ann_ b_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_Case :: Annotation ->
-                       T_CaseScalarExprListScalarExprPairList  ->
-                       T_MaybeScalarExpr  ->
-                       T_ScalarExpr 
-sem_ScalarExpr_Case ann_ cases_ els_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              _casesOcat :: Catalog
-              _casesOidenv :: IDEnv
-              _casesOlib :: LocalBindings
-              _elsOcat :: Catalog
-              _elsOidenv :: IDEnv
-              _elsOlib :: LocalBindings
-              _casesIannotatedTree :: CaseScalarExprListScalarExprPairList 
-              _casesIfixedUpIdentifiersTree :: CaseScalarExprListScalarExprPairList 
-              _casesIoriginalTree :: CaseScalarExprListScalarExprPairList 
-              _casesIthenTypes :: ([Maybe Type])
-              _casesIwhenTypes :: ([[Maybe Type]])
-              _elsIannotatedTree :: MaybeScalarExpr 
-              _elsIfixedUpIdentifiersTree :: MaybeScalarExpr 
-              _elsIoriginalTree :: MaybeScalarExpr 
-              _elsIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 282, column 9)
-              _whenTypes =
-                  _casesIwhenTypes
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 283, column 9)
-              _thenTypes =
-                  _casesIthenTypes ++ maybe [] ((:[]) . Just) _elsIuType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 287, column 9)
-              _tpe =
-                  do
-                  wt <- mapM lmt $ concat _whenTypes
-                  errorWhen (any (/= typeBool) wt)
-                      [WrongTypes typeBool wt]
-                  tt <- mapM lmt _thenTypes
-                  resolveResultSetType _lhsIcat tt
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 295, column 9)
-              _backTree =
-                  Case ann_ _casesIannotatedTree _elsIannotatedTree
-              -- self rule
-              _annotatedTree =
-                  Case ann_ _casesIannotatedTree _elsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Case ann_ _casesIfixedUpIdentifiersTree _elsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Case ann_ _casesIoriginalTree _elsIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _casesOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _casesOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _casesOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _elsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _elsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _elsOlib =
-                  _lhsIlib
-              ( _casesIannotatedTree,_casesIfixedUpIdentifiersTree,_casesIoriginalTree,_casesIthenTypes,_casesIwhenTypes) =
-                  cases_ _casesOcat _casesOidenv _casesOlib 
-              ( _elsIannotatedTree,_elsIfixedUpIdentifiersTree,_elsIoriginalTree,_elsIuType) =
-                  els_ _elsOcat _elsOidenv _elsOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_CaseSimple :: Annotation ->
-                             T_ScalarExpr  ->
-                             T_CaseScalarExprListScalarExprPairList  ->
-                             T_MaybeScalarExpr  ->
-                             T_ScalarExpr 
-sem_ScalarExpr_CaseSimple ann_ value_ cases_ els_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              _valueOcat :: Catalog
-              _valueOexpectedType :: (Maybe Type)
-              _valueOidenv :: IDEnv
-              _valueOlib :: LocalBindings
-              _casesOcat :: Catalog
-              _casesOidenv :: IDEnv
-              _casesOlib :: LocalBindings
-              _elsOcat :: Catalog
-              _elsOidenv :: IDEnv
-              _elsOlib :: LocalBindings
-              _valueIannotatedTree :: ScalarExpr 
-              _valueIfixedUpIdentifiersTree :: ScalarExpr 
-              _valueIoriginalTree :: ScalarExpr 
-              _valueIuType :: (Maybe Type)
-              _casesIannotatedTree :: CaseScalarExprListScalarExprPairList 
-              _casesIfixedUpIdentifiersTree :: CaseScalarExprListScalarExprPairList 
-              _casesIoriginalTree :: CaseScalarExprListScalarExprPairList 
-              _casesIthenTypes :: ([Maybe Type])
-              _casesIwhenTypes :: ([[Maybe Type]])
-              _elsIannotatedTree :: MaybeScalarExpr 
-              _elsIfixedUpIdentifiersTree :: MaybeScalarExpr 
-              _elsIoriginalTree :: MaybeScalarExpr 
-              _elsIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 282, column 9)
-              _whenTypes =
-                  _casesIwhenTypes
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 283, column 9)
-              _thenTypes =
-                  _casesIthenTypes ++ maybe [] ((:[]) . Just) _elsIuType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 300, column 9)
-              _tpe =
-                  do
-                  wt <- mapM lmt $ concat _whenTypes
-                  vt <- lmt _valueIuType
-                  _ <- resolveResultSetType _lhsIcat (vt : wt)
-                  tt <- mapM lmt _thenTypes
-                  resolveResultSetType _lhsIcat tt
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 307, column 9)
-              _backTree =
-                  CaseSimple ann_
-                             _valueIannotatedTree
-                             _casesIannotatedTree
-                             _elsIannotatedTree
-              -- self rule
-              _annotatedTree =
-                  CaseSimple ann_ _valueIannotatedTree _casesIannotatedTree _elsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  CaseSimple ann_ _valueIfixedUpIdentifiersTree _casesIfixedUpIdentifiersTree _elsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  CaseSimple ann_ _valueIoriginalTree _casesIoriginalTree _elsIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _valueOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _valueOexpectedType =
-                  _lhsIexpectedType
-              -- copy rule (down)
-              _valueOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _valueOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _casesOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _casesOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _casesOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _elsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _elsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _elsOlib =
-                  _lhsIlib
-              ( _valueIannotatedTree,_valueIfixedUpIdentifiersTree,_valueIoriginalTree,_valueIuType) =
-                  value_ _valueOcat _valueOexpectedType _valueOidenv _valueOlib 
-              ( _casesIannotatedTree,_casesIfixedUpIdentifiersTree,_casesIoriginalTree,_casesIthenTypes,_casesIwhenTypes) =
-                  cases_ _casesOcat _casesOidenv _casesOlib 
-              ( _elsIannotatedTree,_elsIfixedUpIdentifiersTree,_elsIoriginalTree,_elsIuType) =
-                  els_ _elsOcat _elsOidenv _elsOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_Cast :: Annotation ->
-                       T_ScalarExpr  ->
-                       T_TypeName  ->
-                       T_ScalarExpr 
-sem_ScalarExpr_Cast ann_ expr_ tn_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              _exprOcat :: Catalog
-              _exprOexpectedType :: (Maybe Type)
-              _exprOidenv :: IDEnv
-              _exprOlib :: LocalBindings
-              _tnOcat :: Catalog
-              _tnOidenv :: IDEnv
-              _tnOlib :: LocalBindings
-              _exprIannotatedTree :: ScalarExpr 
-              _exprIfixedUpIdentifiersTree :: ScalarExpr 
-              _exprIoriginalTree :: ScalarExpr 
-              _exprIuType :: (Maybe Type)
-              _tnIannotatedTree :: TypeName 
-              _tnIfixedUpIdentifiersTree :: TypeName 
-              _tnInamedType :: (Maybe Type)
-              _tnIoriginalTree :: TypeName 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 189, column 12)
-              _tpe =
-                  lmt _tnInamedType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 190, column 12)
-              _backTree =
-                  Cast ann_ _exprIannotatedTree _tnIannotatedTree
-              -- self rule
-              _annotatedTree =
-                  Cast ann_ _exprIannotatedTree _tnIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Cast ann_ _exprIfixedUpIdentifiersTree _tnIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Cast ann_ _exprIoriginalTree _tnIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _exprOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exprOexpectedType =
-                  _lhsIexpectedType
-              -- copy rule (down)
-              _exprOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exprOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tnOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tnOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tnOlib =
-                  _lhsIlib
-              ( _exprIannotatedTree,_exprIfixedUpIdentifiersTree,_exprIoriginalTree,_exprIuType) =
-                  expr_ _exprOcat _exprOexpectedType _exprOidenv _exprOlib 
-              ( _tnIannotatedTree,_tnIfixedUpIdentifiersTree,_tnInamedType,_tnIoriginalTree) =
-                  tn_ _tnOcat _tnOidenv _tnOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_Exists :: Annotation ->
-                         T_QueryExpr  ->
-                         T_ScalarExpr 
-sem_ScalarExpr_Exists ann_ sel_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _selOcsql :: LocalBindings
-              _selOexpectedTypes :: ([Maybe Type])
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              _selOcat :: Catalog
-              _selOidenv :: IDEnv
-              _selOlib :: LocalBindings
-              _selIannotatedTree :: QueryExpr 
-              _selIcidenv :: IDEnv
-              _selIfixedUpIdentifiersTree :: QueryExpr 
-              _selIlibUpdates :: ([LocalBindingsUpdate])
-              _selIoriginalTree :: QueryExpr 
-              _selIuType :: (Maybe [(String,Type)])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 366, column 9)
-              _tpe =
-                  Right typeBool
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 367, column 9)
-              _backTree =
-                  Exists ann_ _selIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 390, column 9)
-              _selOcsql =
-                  _lhsIlib
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 169, column 29)
-              _selOexpectedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  Exists ann_ _selIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Exists ann_ _selIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Exists ann_ _selIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _selOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _selOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _selOlib =
-                  _lhsIlib
-              ( _selIannotatedTree,_selIcidenv,_selIfixedUpIdentifiersTree,_selIlibUpdates,_selIoriginalTree,_selIuType) =
-                  sel_ _selOcat _selOcsql _selOexpectedTypes _selOidenv _selOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_Extract :: Annotation ->
-                          ExtractField ->
-                          T_ScalarExpr  ->
-                          T_ScalarExpr 
-sem_ScalarExpr_Extract ann_ field_ e_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              _eOcat :: Catalog
-              _eOexpectedType :: (Maybe Type)
-              _eOidenv :: IDEnv
-              _eOlib :: LocalBindings
-              _eIannotatedTree :: ScalarExpr 
-              _eIfixedUpIdentifiersTree :: ScalarExpr 
-              _eIoriginalTree :: ScalarExpr 
-              _eIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 435, column 9)
-              _tpe =
-                  do
-                  x <- lmt _eIuType
-                  if x == typeDate
-                    then Right typeFloat8
-                    else Left [NoMatchingOperator "extract" [x]]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 440, column 9)
-              _backTree =
-                  Extract ann_ field_ _eIannotatedTree
-              -- self rule
-              _annotatedTree =
-                  Extract ann_ field_ _eIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Extract ann_ field_ _eIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Extract ann_ field_ _eIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _eOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _eOexpectedType =
-                  _lhsIexpectedType
-              -- copy rule (down)
-              _eOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _eOlib =
-                  _lhsIlib
-              ( _eIannotatedTree,_eIfixedUpIdentifiersTree,_eIoriginalTree,_eIuType) =
-                  e_ _eOcat _eOexpectedType _eOidenv _eOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_FunCall :: Annotation ->
-                          T_Name  ->
-                          T_ScalarExprList  ->
-                          T_ScalarExpr 
-sem_ScalarExpr_FunCall ann_ funName_ args_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _argsOexpectedTypes :: ([Maybe Type])
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              _funNameOcat :: Catalog
-              _funNameOidenv :: IDEnv
-              _funNameOlib :: LocalBindings
-              _argsOcat :: Catalog
-              _argsOidenv :: IDEnv
-              _argsOlib :: LocalBindings
-              _funNameIannotatedTree :: Name 
-              _funNameIfixedUpIdentifiersTree :: Name 
-              _funNameIoriginalTree :: Name 
-              _funNameItbAnnotatedTree :: Name 
-              _funNameItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _argsIannotatedTree :: ScalarExprList 
-              _argsIfixedUpIdentifiersTree :: ScalarExprList 
-              _argsIoriginalTree :: ScalarExprList 
-              _argsIuType :: ([Maybe Type])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 203, column 9)
-              __tup1 =
-                  either (\e -> (Left e, Nothing)) id $ do
-                  args <- mapM lmt _argsIuType
-                  efp <- findCallMatch _lhsIcat
-                                       (getTName _funNameIoriginalTree)
-                                       args
-                  let (_,_,r,_) = efp
-                  return (Right r, Just efp)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 203, column 9)
-              (_tpe,_) =
-                  __tup1
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 203, column 9)
-              (_,_prototype) =
-                  __tup1
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 213, column 9)
-              _backTree =
-                  FunCall ann_ _funNameIoriginalTree _argsIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 127, column 9)
-              _argsOexpectedTypes =
-                  maybe [] id $
-                  case (getTName _funNameIoriginalTree,_lhsIexpectedType) of
-                    ("!rowctor", Just (AnonymousRecordType ts)) -> return $ map Just ts
-                    _ -> do
-                         (_,t,_,_) <- _prototype
-                         return $ map Just t
-              -- self rule
-              _annotatedTree =
-                  FunCall ann_ _funNameIannotatedTree _argsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  FunCall ann_ _funNameIfixedUpIdentifiersTree _argsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  FunCall ann_ _funNameIoriginalTree _argsIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _funNameOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _funNameOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _funNameOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _argsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _argsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _argsOlib =
-                  _lhsIlib
-              ( _funNameIannotatedTree,_funNameIfixedUpIdentifiersTree,_funNameIoriginalTree,_funNameItbAnnotatedTree,_funNameItbUType) =
-                  funName_ _funNameOcat _funNameOidenv _funNameOlib 
-              ( _argsIannotatedTree,_argsIfixedUpIdentifiersTree,_argsIoriginalTree,_argsIuType) =
-                  args_ _argsOcat _argsOexpectedTypes _argsOidenv _argsOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_Identifier :: Annotation ->
-                             NameComponent ->
-                             T_ScalarExpr 
-sem_ScalarExpr_Identifier ann_ i_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _lhsOoriginalTree :: ScalarExpr 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 128, column 9)
-              _lhsOfixedUpIdentifiersTree =
-                  case qualifyID _lhsIidenv (ncStr i_) of
-                    Nothing -> Identifier ann_ i_
-                    Just (t,i) -> QIdentifier ann_ [Nmc t, Nmc i]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 320, column 9)
-              _tpe =
-                  case lookupLocalBinding _lhsIlib "" (ncStr i_) of
-                                        Right Nothing -> Left []
-                                        Right (Just t) -> Right t
-                                        Left e -> Left e
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 325, column 9)
-              _backTree =
-                  Identifier ann_ i_
-              -- self rule
-              _annotatedTree =
-                  Identifier ann_ i_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Identifier ann_ i_
-              -- self rule
-              _originalTree =
-                  Identifier ann_ i_
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_InPredicate :: Annotation ->
-                              T_ScalarExpr  ->
-                              Bool ->
-                              T_InList  ->
-                              T_ScalarExpr 
-sem_ScalarExpr_InPredicate ann_ expr_ i_ list_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _rt :: (Either [TypeError] Type)
-              _tpe :: Et
-              _listOexpectedType :: (Maybe Type)
-              _exprOexpectedType :: (Maybe Type)
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              _exprOcat :: Catalog
-              _exprOidenv :: IDEnv
-              _exprOlib :: LocalBindings
-              _listOcat :: Catalog
-              _listOidenv :: IDEnv
-              _listOlib :: LocalBindings
-              _exprIannotatedTree :: ScalarExpr 
-              _exprIfixedUpIdentifiersTree :: ScalarExpr 
-              _exprIoriginalTree :: ScalarExpr 
-              _exprIuType :: (Maybe Type)
-              _listIannotatedTree :: InList 
-              _listIfixedUpIdentifiersTree :: InList 
-              _listIlistType :: (Either [TypeError] Type)
-              _listIoriginalTree :: InList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 399, column 9)
-              _rt =
-                  do
-                  lt <- _listIlistType
-                  expt <- lmt _exprIuType
-                  resolveResultSetType _lhsIcat [expt, lt]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 403, column 9)
-              _tpe =
-                  do
-                  _ <- _rt
-                  return typeBool
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 406, column 9)
-              _listOexpectedType =
-                  etmt _rt
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 407, column 9)
-              _exprOexpectedType =
-                  etmt _rt
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 408, column 9)
-              _backTree =
-                  InPredicate ann_
-                              _exprIannotatedTree
-                              i_
-                              _listIannotatedTree
-              -- self rule
-              _annotatedTree =
-                  InPredicate ann_ _exprIannotatedTree i_ _listIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  InPredicate ann_ _exprIfixedUpIdentifiersTree i_ _listIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  InPredicate ann_ _exprIoriginalTree i_ _listIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _exprOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exprOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exprOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _listOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _listOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _listOlib =
-                  _lhsIlib
-              ( _exprIannotatedTree,_exprIfixedUpIdentifiersTree,_exprIoriginalTree,_exprIuType) =
-                  expr_ _exprOcat _exprOexpectedType _exprOidenv _exprOlib 
-              ( _listIannotatedTree,_listIfixedUpIdentifiersTree,_listIlistType,_listIoriginalTree) =
-                  list_ _listOcat _listOexpectedType _listOidenv _listOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_Interval :: Annotation ->
-                           String ->
-                           IntervalField ->
-                           (Maybe Int) ->
-                           T_ScalarExpr 
-sem_ScalarExpr_Interval ann_ value_ field_ prec_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 177, column 16)
-              _tpe =
-                  Right $ ScalarType "interval"
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 178, column 16)
-              _backTree =
-                  Interval ann_ value_ field_ prec_
-              -- self rule
-              _annotatedTree =
-                  Interval ann_ value_ field_ prec_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Interval ann_ value_ field_ prec_
-              -- self rule
-              _originalTree =
-                  Interval ann_ value_ field_ prec_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_LiftOperator :: Annotation ->
-                               String ->
-                               LiftFlavour ->
-                               T_ScalarExprList  ->
-                               T_ScalarExpr 
-sem_ScalarExpr_LiftOperator ann_ oper_ flav_ args_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _argsOexpectedTypes :: ([Maybe Type])
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              _argsOcat :: Catalog
-              _argsOidenv :: IDEnv
-              _argsOlib :: LocalBindings
-              _argsIannotatedTree :: ScalarExprList 
-              _argsIfixedUpIdentifiersTree :: ScalarExprList 
-              _argsIoriginalTree :: ScalarExprList 
-              _argsIuType :: ([Maybe Type])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 235, column 9)
-              _tpe =
-                  do
-                  at <- mapM lmt _argsIuType
-                  errorWhen (length at /= 2)
-                            [AnyAllError $ "must have two args, got " ++ show at]
-                  let [aType,bType] = at
-                  errorWhen (not $ isArrayType bType)
-                            [AnyAllError $ "second arg must be array, got " ++ show at]
-                  elemType <- unwrapArray $ bType
-                  resType <- fmap (\(_,_,r,_) -> r) $ findCallMatch _lhsIcat
-                                                                    oper_
-                                                                    [aType,elemType]
-                  errorWhen (resType /= typeBool)
-                            [AnyAllError $ "operator must have bool return, got " ++ show resType]
-                  return resType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 249, column 9)
-              _backTree =
-                  LiftOperator ann_ oper_ flav_ _argsIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 135, column 9)
-              _argsOexpectedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  LiftOperator ann_ oper_ flav_ _argsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  LiftOperator ann_ oper_ flav_ _argsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  LiftOperator ann_ oper_ flav_ _argsIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _argsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _argsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _argsOlib =
-                  _lhsIlib
-              ( _argsIannotatedTree,_argsIfixedUpIdentifiersTree,_argsIoriginalTree,_argsIuType) =
-                  args_ _argsOcat _argsOexpectedTypes _argsOidenv _argsOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_NullLit :: Annotation ->
-                          T_ScalarExpr 
-sem_ScalarExpr_NullLit ann_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 164, column 16)
-              _tpe =
-                  Right UnknownType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 174, column 9)
-              _backTree =
-                  NullLit ann_
-              -- self rule
-              _annotatedTree =
-                  NullLit ann_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  NullLit ann_
-              -- self rule
-              _originalTree =
-                  NullLit ann_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_NumberLit :: Annotation ->
-                            String ->
-                            T_ScalarExpr 
-sem_ScalarExpr_NumberLit ann_ d_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 156, column 18)
-              _tpe =
-                  if all (`elem` digChars) d_
-                  then Right typeInt
-                  else Right typeNumeric
-                  where
-                    digChars = concatMap show [(0::Int)..9]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 168, column 9)
-              _backTree =
-                  NumberLit ann_ d_
-              -- self rule
-              _annotatedTree =
-                  NumberLit ann_ d_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  NumberLit ann_ d_
-              -- self rule
-              _originalTree =
-                  NumberLit ann_ d_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_Placeholder :: Annotation ->
-                              T_ScalarExpr 
-sem_ScalarExpr_Placeholder ann_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 360, column 9)
-              _tpe =
-                  Right UnknownType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 361, column 9)
-              _backTree =
-                  Placeholder ann_
-              -- self rule
-              _annotatedTree =
-                  Placeholder ann_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Placeholder ann_
-              -- self rule
-              _originalTree =
-                  Placeholder ann_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_PositionalArg :: Annotation ->
-                                Integer ->
-                                T_ScalarExpr 
-sem_ScalarExpr_PositionalArg ann_ p_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 354, column 9)
-              _tpe =
-                  unwrapLookup <$> lbLookupID _lhsIlib ['$':show p_]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 355, column 9)
-              _backTree =
-                  PositionalArg ann_ p_
-              -- self rule
-              _annotatedTree =
-                  PositionalArg ann_ p_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  PositionalArg ann_ p_
-              -- self rule
-              _originalTree =
-                  PositionalArg ann_ p_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_QIdentifier :: Annotation ->
-                              ([NameComponent]) ->
-                              T_ScalarExpr 
-sem_ScalarExpr_QIdentifier ann_ is_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _lhsOoriginalTree :: ScalarExpr 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 134, column 9)
-              _lhsOfixedUpIdentifiersTree =
-                  QIdentifier ann_ is_
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 327, column 9)
-              _tpe =
-                  case is_ of
-                    [Nmc q,Nmc i] ->
-                        case lookupLocalBinding _lhsIlib q i of
-                                        Right Nothing -> Left []
-                                        Right (Just t) -> Right t
-                                        Left e -> Left e
-                    _ -> Left [InternalError "dot selection not implemented"]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 334, column 9)
-              _backTree =
-                  QIdentifier ann_ is_
-              -- self rule
-              _annotatedTree =
-                  QIdentifier ann_ is_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  QIdentifier ann_ is_
-              -- self rule
-              _originalTree =
-                  QIdentifier ann_ is_
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_QStar :: Annotation ->
-                        NameComponent ->
-                        T_ScalarExpr 
-sem_ScalarExpr_QStar ann_ q_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOuType :: (Maybe Type)
-              _lhsOannotatedTree :: ScalarExpr 
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 108, column 9)
-              _lhsOuType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  QStar ann_ q_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  QStar ann_ q_
-              -- self rule
-              _originalTree =
-                  QStar ann_ q_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_ScalarSubQuery :: Annotation ->
-                                 T_QueryExpr  ->
-                                 T_ScalarExpr 
-sem_ScalarExpr_ScalarSubQuery ann_ sel_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _selOcsql :: LocalBindings
-              _selOexpectedTypes :: ([Maybe Type])
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              _selOcat :: Catalog
-              _selOidenv :: IDEnv
-              _selOlib :: LocalBindings
-              _selIannotatedTree :: QueryExpr 
-              _selIcidenv :: IDEnv
-              _selIfixedUpIdentifiersTree :: QueryExpr 
-              _selIlibUpdates :: ([LocalBindingsUpdate])
-              _selIoriginalTree :: QueryExpr 
-              _selIuType :: (Maybe [(String,Type)])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 378, column 9)
-              _tpe =
-                  do
-                  selType <- lmt (map snd <$> _selIuType)
-                  case length selType of
-                    0 -> Left [InternalError "no columns in scalar subquery?"]
-                    1 -> Right $ head selType
-                    _ -> Right $ AnonymousRecordType selType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 386, column 9)
-              _backTree =
-                  ScalarSubQuery ann_ _selIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 388, column 9)
-              _selOcsql =
-                  _lhsIlib
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 169, column 29)
-              _selOexpectedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  ScalarSubQuery ann_ _selIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  ScalarSubQuery ann_ _selIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  ScalarSubQuery ann_ _selIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _selOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _selOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _selOlib =
-                  _lhsIlib
-              ( _selIannotatedTree,_selIcidenv,_selIfixedUpIdentifiersTree,_selIlibUpdates,_selIoriginalTree,_selIuType) =
-                  sel_ _selOcat _selOcsql _selOexpectedTypes _selOidenv _selOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_Star :: Annotation ->
-                       T_ScalarExpr 
-sem_ScalarExpr_Star ann_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOuType :: (Maybe Type)
-              _lhsOannotatedTree :: ScalarExpr 
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 108, column 9)
-              _lhsOuType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  Star ann_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Star ann_
-              -- self rule
-              _originalTree =
-                  Star ann_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_StringLit :: Annotation ->
-                            String ->
-                            T_ScalarExpr 
-sem_ScalarExpr_StringLit ann_ value_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 161, column 18)
-              _tpe =
-                  Right UnknownType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 170, column 9)
-              _backTree =
-                  StringLit ann_ value_
-              -- self rule
-              _annotatedTree =
-                  StringLit ann_ value_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  StringLit ann_ value_
-              -- self rule
-              _originalTree =
-                  StringLit ann_ value_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_TypedStringLit :: Annotation ->
-                                 T_TypeName  ->
-                                 String ->
-                                 T_ScalarExpr 
-sem_ScalarExpr_TypedStringLit ann_ tn_ value_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              _tnOcat :: Catalog
-              _tnOidenv :: IDEnv
-              _tnOlib :: LocalBindings
-              _tnIannotatedTree :: TypeName 
-              _tnIfixedUpIdentifiersTree :: TypeName 
-              _tnInamedType :: (Maybe Type)
-              _tnIoriginalTree :: TypeName 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 194, column 10)
-              _tpe =
-                  lmt _tnInamedType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 195, column 10)
-              _backTree =
-                  TypedStringLit ann_ _tnIannotatedTree value_
-              -- self rule
-              _annotatedTree =
-                  TypedStringLit ann_ _tnIannotatedTree value_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  TypedStringLit ann_ _tnIfixedUpIdentifiersTree value_
-              -- self rule
-              _originalTree =
-                  TypedStringLit ann_ _tnIoriginalTree value_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _tnOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tnOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tnOlib =
-                  _lhsIlib
-              ( _tnIannotatedTree,_tnIfixedUpIdentifiersTree,_tnInamedType,_tnIoriginalTree) =
-                  tn_ _tnOcat _tnOidenv _tnOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExpr_WindowFn :: Annotation ->
-                           T_ScalarExpr  ->
-                           T_ScalarExprList  ->
-                           T_ScalarExprDirectionPairList  ->
-                           FrameClause ->
-                           T_ScalarExpr 
-sem_ScalarExpr_WindowFn ann_ fn_ partitionBy_ orderBy_ frm_  =
-    (\ _lhsIcat
-       _lhsIexpectedType
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExpr 
-              _prototype :: (Maybe FunctionPrototype)
-              _lhsOuType :: (Maybe Type)
-              _tpe :: Et
-              _partitionByOexpectedTypes :: ([Maybe Type])
-              _lhsOfixedUpIdentifiersTree :: ScalarExpr 
-              _lhsOoriginalTree :: ScalarExpr 
-              _fnOcat :: Catalog
-              _fnOexpectedType :: (Maybe Type)
-              _fnOidenv :: IDEnv
-              _fnOlib :: LocalBindings
-              _partitionByOcat :: Catalog
-              _partitionByOidenv :: IDEnv
-              _partitionByOlib :: LocalBindings
-              _orderByOcat :: Catalog
-              _orderByOidenv :: IDEnv
-              _orderByOlib :: LocalBindings
-              _fnIannotatedTree :: ScalarExpr 
-              _fnIfixedUpIdentifiersTree :: ScalarExpr 
-              _fnIoriginalTree :: ScalarExpr 
-              _fnIuType :: (Maybe Type)
-              _partitionByIannotatedTree :: ScalarExprList 
-              _partitionByIfixedUpIdentifiersTree :: ScalarExprList 
-              _partitionByIoriginalTree :: ScalarExprList 
-              _partitionByIuType :: ([Maybe Type])
-              _orderByIannotatedTree :: ScalarExprDirectionPairList 
-              _orderByIfixedUpIdentifiersTree :: ScalarExprDirectionPairList 
-              _orderByIoriginalTree :: ScalarExprDirectionPairList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 24, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                    (setTypeAddErrorsA _tpe
-                     . \a -> a {fnProt = _prototype
-                               ,infType = msum [_lhsIexpectedType
-                                               ,etmt _tpe
-                                               ,Nothing]}) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 46, column 9)
-              _prototype =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 104, column 9)
-              _lhsOuType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 217, column 9)
-              _tpe =
-                  lmt _fnIuType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 218, column 9)
-              _backTree =
-                  WindowFn ann_
-                           _fnIannotatedTree
-                           _partitionByIannotatedTree
-                           _orderByIannotatedTree
-                           frm_
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 137, column 9)
-              _partitionByOexpectedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  WindowFn ann_ _fnIannotatedTree _partitionByIannotatedTree _orderByIannotatedTree frm_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  WindowFn ann_ _fnIfixedUpIdentifiersTree _partitionByIfixedUpIdentifiersTree _orderByIfixedUpIdentifiersTree frm_
-              -- self rule
-              _originalTree =
-                  WindowFn ann_ _fnIoriginalTree _partitionByIoriginalTree _orderByIoriginalTree frm_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _fnOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _fnOexpectedType =
-                  _lhsIexpectedType
-              -- copy rule (down)
-              _fnOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _fnOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _partitionByOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _partitionByOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _partitionByOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _orderByOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _orderByOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _orderByOlib =
-                  _lhsIlib
-              ( _fnIannotatedTree,_fnIfixedUpIdentifiersTree,_fnIoriginalTree,_fnIuType) =
-                  fn_ _fnOcat _fnOexpectedType _fnOidenv _fnOlib 
-              ( _partitionByIannotatedTree,_partitionByIfixedUpIdentifiersTree,_partitionByIoriginalTree,_partitionByIuType) =
-                  partitionBy_ _partitionByOcat _partitionByOexpectedTypes _partitionByOidenv _partitionByOlib 
-              ( _orderByIannotatedTree,_orderByIfixedUpIdentifiersTree,_orderByIoriginalTree) =
-                  orderBy_ _orderByOcat _orderByOidenv _orderByOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
--- ScalarExprDirectionPair -------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative Tuple:
-         child x1             : ScalarExpr 
-         child x2             : {Direction}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type ScalarExprDirectionPair  = ( ScalarExpr ,(Direction))
--- cata
-sem_ScalarExprDirectionPair :: ScalarExprDirectionPair  ->
-                               T_ScalarExprDirectionPair 
-sem_ScalarExprDirectionPair ( x1,x2)  =
-    (sem_ScalarExprDirectionPair_Tuple (sem_ScalarExpr x1 ) x2 )
--- semantic domain
-type T_ScalarExprDirectionPair  = Catalog ->
-                                  IDEnv ->
-                                  LocalBindings ->
-                                  ( ScalarExprDirectionPair ,ScalarExprDirectionPair ,ScalarExprDirectionPair )
-data Inh_ScalarExprDirectionPair  = Inh_ScalarExprDirectionPair {cat_Inh_ScalarExprDirectionPair :: Catalog,idenv_Inh_ScalarExprDirectionPair :: IDEnv,lib_Inh_ScalarExprDirectionPair :: LocalBindings}
-data Syn_ScalarExprDirectionPair  = Syn_ScalarExprDirectionPair {annotatedTree_Syn_ScalarExprDirectionPair :: ScalarExprDirectionPair ,fixedUpIdentifiersTree_Syn_ScalarExprDirectionPair :: ScalarExprDirectionPair ,originalTree_Syn_ScalarExprDirectionPair :: ScalarExprDirectionPair }
-wrap_ScalarExprDirectionPair :: T_ScalarExprDirectionPair  ->
-                                Inh_ScalarExprDirectionPair  ->
-                                Syn_ScalarExprDirectionPair 
-wrap_ScalarExprDirectionPair sem (Inh_ScalarExprDirectionPair _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_ScalarExprDirectionPair _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_ScalarExprDirectionPair_Tuple :: T_ScalarExpr  ->
-                                     Direction ->
-                                     T_ScalarExprDirectionPair 
-sem_ScalarExprDirectionPair_Tuple x1_ x2_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _x1OexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: ScalarExprDirectionPair 
-              _lhsOfixedUpIdentifiersTree :: ScalarExprDirectionPair 
-              _lhsOoriginalTree :: ScalarExprDirectionPair 
-              _x1Ocat :: Catalog
-              _x1Oidenv :: IDEnv
-              _x1Olib :: LocalBindings
-              _x1IannotatedTree :: ScalarExpr 
-              _x1IfixedUpIdentifiersTree :: ScalarExpr 
-              _x1IoriginalTree :: ScalarExpr 
-              _x1IuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 83, column 13)
-              _x1OexpectedType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  (_x1IannotatedTree,x2_)
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (_x1IfixedUpIdentifiersTree,x2_)
-              -- self rule
-              _originalTree =
-                  (_x1IoriginalTree,x2_)
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _x1Ocat =
-                  _lhsIcat
-              -- copy rule (down)
-              _x1Oidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _x1Olib =
-                  _lhsIlib
-              ( _x1IannotatedTree,_x1IfixedUpIdentifiersTree,_x1IoriginalTree,_x1IuType) =
-                  x1_ _x1Ocat _x1OexpectedType _x1Oidenv _x1Olib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- ScalarExprDirectionPairList ---------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative Cons:
-         child hd             : ScalarExprDirectionPair 
-         child tl             : ScalarExprDirectionPairList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type ScalarExprDirectionPairList  = [ScalarExprDirectionPair ]
--- cata
-sem_ScalarExprDirectionPairList :: ScalarExprDirectionPairList  ->
-                                   T_ScalarExprDirectionPairList 
-sem_ScalarExprDirectionPairList list  =
-    (Prelude.foldr sem_ScalarExprDirectionPairList_Cons sem_ScalarExprDirectionPairList_Nil (Prelude.map sem_ScalarExprDirectionPair list) )
--- semantic domain
-type T_ScalarExprDirectionPairList  = Catalog ->
-                                      IDEnv ->
-                                      LocalBindings ->
-                                      ( ScalarExprDirectionPairList ,ScalarExprDirectionPairList ,ScalarExprDirectionPairList )
-data Inh_ScalarExprDirectionPairList  = Inh_ScalarExprDirectionPairList {cat_Inh_ScalarExprDirectionPairList :: Catalog,idenv_Inh_ScalarExprDirectionPairList :: IDEnv,lib_Inh_ScalarExprDirectionPairList :: LocalBindings}
-data Syn_ScalarExprDirectionPairList  = Syn_ScalarExprDirectionPairList {annotatedTree_Syn_ScalarExprDirectionPairList :: ScalarExprDirectionPairList ,fixedUpIdentifiersTree_Syn_ScalarExprDirectionPairList :: ScalarExprDirectionPairList ,originalTree_Syn_ScalarExprDirectionPairList :: ScalarExprDirectionPairList }
-wrap_ScalarExprDirectionPairList :: T_ScalarExprDirectionPairList  ->
-                                    Inh_ScalarExprDirectionPairList  ->
-                                    Syn_ScalarExprDirectionPairList 
-wrap_ScalarExprDirectionPairList sem (Inh_ScalarExprDirectionPairList _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_ScalarExprDirectionPairList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_ScalarExprDirectionPairList_Cons :: T_ScalarExprDirectionPair  ->
-                                        T_ScalarExprDirectionPairList  ->
-                                        T_ScalarExprDirectionPairList 
-sem_ScalarExprDirectionPairList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExprDirectionPairList 
-              _lhsOfixedUpIdentifiersTree :: ScalarExprDirectionPairList 
-              _lhsOoriginalTree :: ScalarExprDirectionPairList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: ScalarExprDirectionPair 
-              _hdIfixedUpIdentifiersTree :: ScalarExprDirectionPair 
-              _hdIoriginalTree :: ScalarExprDirectionPair 
-              _tlIannotatedTree :: ScalarExprDirectionPairList 
-              _tlIfixedUpIdentifiersTree :: ScalarExprDirectionPairList 
-              _tlIoriginalTree :: ScalarExprDirectionPairList 
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIfixedUpIdentifiersTree,_hdIoriginalTree) =
-                  hd_ _hdOcat _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIfixedUpIdentifiersTree,_tlIoriginalTree) =
-                  tl_ _tlOcat _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_ScalarExprDirectionPairList_Nil :: T_ScalarExprDirectionPairList 
-sem_ScalarExprDirectionPairList_Nil  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExprDirectionPairList 
-              _lhsOfixedUpIdentifiersTree :: ScalarExprDirectionPairList 
-              _lhsOoriginalTree :: ScalarExprDirectionPairList 
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- ScalarExprList ----------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         expectedTypes        : [Maybe Type]
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-         uType                : [Maybe Type]
-   alternatives:
-      alternative Cons:
-         child hd             : ScalarExpr 
-         child tl             : ScalarExprList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type ScalarExprList  = [ScalarExpr ]
--- cata
-sem_ScalarExprList :: ScalarExprList  ->
-                      T_ScalarExprList 
-sem_ScalarExprList list  =
-    (Prelude.foldr sem_ScalarExprList_Cons sem_ScalarExprList_Nil (Prelude.map sem_ScalarExpr list) )
--- semantic domain
-type T_ScalarExprList  = Catalog ->
-                         ([Maybe Type]) ->
-                         IDEnv ->
-                         LocalBindings ->
-                         ( ScalarExprList ,ScalarExprList ,ScalarExprList ,([Maybe Type]))
-data Inh_ScalarExprList  = Inh_ScalarExprList {cat_Inh_ScalarExprList :: Catalog,expectedTypes_Inh_ScalarExprList :: ([Maybe Type]),idenv_Inh_ScalarExprList :: IDEnv,lib_Inh_ScalarExprList :: LocalBindings}
-data Syn_ScalarExprList  = Syn_ScalarExprList {annotatedTree_Syn_ScalarExprList :: ScalarExprList ,fixedUpIdentifiersTree_Syn_ScalarExprList :: ScalarExprList ,originalTree_Syn_ScalarExprList :: ScalarExprList ,uType_Syn_ScalarExprList :: ([Maybe Type])}
-wrap_ScalarExprList :: T_ScalarExprList  ->
-                       Inh_ScalarExprList  ->
-                       Syn_ScalarExprList 
-wrap_ScalarExprList sem (Inh_ScalarExprList _lhsIcat _lhsIexpectedTypes _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType) = sem _lhsIcat _lhsIexpectedTypes _lhsIidenv _lhsIlib 
-     in  (Syn_ScalarExprList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree _lhsOuType ))
-sem_ScalarExprList_Cons :: T_ScalarExpr  ->
-                           T_ScalarExprList  ->
-                           T_ScalarExprList 
-sem_ScalarExprList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIexpectedTypes
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOuType :: ([Maybe Type])
-              _hdOexpectedType :: (Maybe Type)
-              _tlOexpectedTypes :: ([Maybe Type])
-              _lhsOannotatedTree :: ScalarExprList 
-              _lhsOfixedUpIdentifiersTree :: ScalarExprList 
-              _lhsOoriginalTree :: ScalarExprList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: ScalarExpr 
-              _hdIfixedUpIdentifiersTree :: ScalarExpr 
-              _hdIoriginalTree :: ScalarExpr 
-              _hdIuType :: (Maybe Type)
-              _tlIannotatedTree :: ScalarExprList 
-              _tlIfixedUpIdentifiersTree :: ScalarExprList 
-              _tlIoriginalTree :: ScalarExprList 
-              _tlIuType :: ([Maybe Type])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 114, column 12)
-              _lhsOuType =
-                  _hdIuType : _tlIuType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 86, column 12)
-              _hdOexpectedType =
-                  case _lhsIexpectedTypes of
-                    (t:_) -> t
-                    _ -> Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 89, column 12)
-              _tlOexpectedTypes =
-                  case _lhsIexpectedTypes of
-                   (_:ts) -> ts
-                   _ -> []
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIfixedUpIdentifiersTree,_hdIoriginalTree,_hdIuType) =
-                  hd_ _hdOcat _hdOexpectedType _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIfixedUpIdentifiersTree,_tlIoriginalTree,_tlIuType) =
-                  tl_ _tlOcat _tlOexpectedTypes _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExprList_Nil :: T_ScalarExprList 
-sem_ScalarExprList_Nil  =
-    (\ _lhsIcat
-       _lhsIexpectedTypes
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOuType :: ([Maybe Type])
-              _lhsOannotatedTree :: ScalarExprList 
-              _lhsOfixedUpIdentifiersTree :: ScalarExprList 
-              _lhsOoriginalTree :: ScalarExprList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 115, column 11)
-              _lhsOuType =
-                  []
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
--- ScalarExprListList ------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         expectedTypes        : [Maybe Type]
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-         uType                : [[Maybe Type]]
-   alternatives:
-      alternative Cons:
-         child hd             : ScalarExprList 
-         child tl             : ScalarExprListList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type ScalarExprListList  = [ScalarExprList ]
--- cata
-sem_ScalarExprListList :: ScalarExprListList  ->
-                          T_ScalarExprListList 
-sem_ScalarExprListList list  =
-    (Prelude.foldr sem_ScalarExprListList_Cons sem_ScalarExprListList_Nil (Prelude.map sem_ScalarExprList list) )
--- semantic domain
-type T_ScalarExprListList  = Catalog ->
-                             ([Maybe Type]) ->
-                             IDEnv ->
-                             LocalBindings ->
-                             ( ScalarExprListList ,ScalarExprListList ,ScalarExprListList ,([[Maybe Type]]))
-data Inh_ScalarExprListList  = Inh_ScalarExprListList {cat_Inh_ScalarExprListList :: Catalog,expectedTypes_Inh_ScalarExprListList :: ([Maybe Type]),idenv_Inh_ScalarExprListList :: IDEnv,lib_Inh_ScalarExprListList :: LocalBindings}
-data Syn_ScalarExprListList  = Syn_ScalarExprListList {annotatedTree_Syn_ScalarExprListList :: ScalarExprListList ,fixedUpIdentifiersTree_Syn_ScalarExprListList :: ScalarExprListList ,originalTree_Syn_ScalarExprListList :: ScalarExprListList ,uType_Syn_ScalarExprListList :: ([[Maybe Type]])}
-wrap_ScalarExprListList :: T_ScalarExprListList  ->
-                           Inh_ScalarExprListList  ->
-                           Syn_ScalarExprListList 
-wrap_ScalarExprListList sem (Inh_ScalarExprListList _lhsIcat _lhsIexpectedTypes _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType) = sem _lhsIcat _lhsIexpectedTypes _lhsIidenv _lhsIlib 
-     in  (Syn_ScalarExprListList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree _lhsOuType ))
-sem_ScalarExprListList_Cons :: T_ScalarExprList  ->
-                               T_ScalarExprListList  ->
-                               T_ScalarExprListList 
-sem_ScalarExprListList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIexpectedTypes
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOuType :: ([[Maybe Type]])
-              _hdOexpectedTypes :: ([Maybe Type])
-              _tlOexpectedTypes :: ([Maybe Type])
-              _lhsOannotatedTree :: ScalarExprListList 
-              _lhsOfixedUpIdentifiersTree :: ScalarExprListList 
-              _lhsOoriginalTree :: ScalarExprListList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: ScalarExprList 
-              _hdIfixedUpIdentifiersTree :: ScalarExprList 
-              _hdIoriginalTree :: ScalarExprList 
-              _hdIuType :: ([Maybe Type])
-              _tlIannotatedTree :: ScalarExprListList 
-              _tlIfixedUpIdentifiersTree :: ScalarExprListList 
-              _tlIoriginalTree :: ScalarExprListList 
-              _tlIuType :: ([[Maybe Type]])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 124, column 12)
-              _lhsOuType =
-                  _hdIuType : _tlIuType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 165, column 12)
-              _hdOexpectedTypes =
-                  _lhsIexpectedTypes
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 166, column 12)
-              _tlOexpectedTypes =
-                  _lhsIexpectedTypes
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIfixedUpIdentifiersTree,_hdIoriginalTree,_hdIuType) =
-                  hd_ _hdOcat _hdOexpectedTypes _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIfixedUpIdentifiersTree,_tlIoriginalTree,_tlIuType) =
-                  tl_ _tlOcat _tlOexpectedTypes _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
-sem_ScalarExprListList_Nil :: T_ScalarExprListList 
-sem_ScalarExprListList_Nil  =
-    (\ _lhsIcat
-       _lhsIexpectedTypes
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOuType :: ([[Maybe Type]])
-              _lhsOannotatedTree :: ScalarExprListList 
-              _lhsOfixedUpIdentifiersTree :: ScalarExprListList 
-              _lhsOoriginalTree :: ScalarExprListList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs/ScalarExprs.ag"(line 125, column 11)
-              _lhsOuType =
-                  []
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOuType)))
--- ScalarExprListStatementListPair -----------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative Tuple:
-         child x1             : ScalarExprList 
-         child x2             : StatementList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type ScalarExprListStatementListPair  = ( ScalarExprList ,StatementList )
--- cata
-sem_ScalarExprListStatementListPair :: ScalarExprListStatementListPair  ->
-                                       T_ScalarExprListStatementListPair 
-sem_ScalarExprListStatementListPair ( x1,x2)  =
-    (sem_ScalarExprListStatementListPair_Tuple (sem_ScalarExprList x1 ) (sem_StatementList x2 ) )
--- semantic domain
-type T_ScalarExprListStatementListPair  = Catalog ->
-                                          IDEnv ->
-                                          LocalBindings ->
-                                          ( ScalarExprListStatementListPair ,ScalarExprListStatementListPair ,ScalarExprListStatementListPair )
-data Inh_ScalarExprListStatementListPair  = Inh_ScalarExprListStatementListPair {cat_Inh_ScalarExprListStatementListPair :: Catalog,idenv_Inh_ScalarExprListStatementListPair :: IDEnv,lib_Inh_ScalarExprListStatementListPair :: LocalBindings}
-data Syn_ScalarExprListStatementListPair  = Syn_ScalarExprListStatementListPair {annotatedTree_Syn_ScalarExprListStatementListPair :: ScalarExprListStatementListPair ,fixedUpIdentifiersTree_Syn_ScalarExprListStatementListPair :: ScalarExprListStatementListPair ,originalTree_Syn_ScalarExprListStatementListPair :: ScalarExprListStatementListPair }
-wrap_ScalarExprListStatementListPair :: T_ScalarExprListStatementListPair  ->
-                                        Inh_ScalarExprListStatementListPair  ->
-                                        Syn_ScalarExprListStatementListPair 
-wrap_ScalarExprListStatementListPair sem (Inh_ScalarExprListStatementListPair _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_ScalarExprListStatementListPair _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_ScalarExprListStatementListPair_Tuple :: T_ScalarExprList  ->
-                                             T_StatementList  ->
-                                             T_ScalarExprListStatementListPair 
-sem_ScalarExprListStatementListPair_Tuple x1_ x2_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _x2OcatUpdates :: ([CatalogUpdate])
-              _x2OlibUpdates :: ([LocalBindingsUpdate])
-              _x1OexpectedTypes :: ([Maybe Type])
-              _lhsOannotatedTree :: ScalarExprListStatementListPair 
-              _lhsOfixedUpIdentifiersTree :: ScalarExprListStatementListPair 
-              _lhsOoriginalTree :: ScalarExprListStatementListPair 
-              _x1Ocat :: Catalog
-              _x1Oidenv :: IDEnv
-              _x1Olib :: LocalBindings
-              _x2Ocat :: Catalog
-              _x2Oidenv :: IDEnv
-              _x2Olib :: LocalBindings
-              _x1IannotatedTree :: ScalarExprList 
-              _x1IfixedUpIdentifiersTree :: ScalarExprList 
-              _x1IoriginalTree :: ScalarExprList 
-              _x1IuType :: ([Maybe Type])
-              _x2IannotatedTree :: StatementList 
-              _x2IfixedUpIdentifiersTree :: StatementList 
-              _x2IoriginalTree :: StatementList 
-              _x2IproducedCat :: Catalog
-              _x2IproducedLib :: LocalBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 121, column 9)
-              _x2OcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 122, column 9)
-              _x2OlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 142, column 13)
-              _x1OexpectedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  (_x1IannotatedTree,_x2IannotatedTree)
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (_x1IfixedUpIdentifiersTree,_x2IfixedUpIdentifiersTree)
-              -- self rule
-              _originalTree =
-                  (_x1IoriginalTree,_x2IoriginalTree)
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _x1Ocat =
-                  _lhsIcat
-              -- copy rule (down)
-              _x1Oidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _x1Olib =
-                  _lhsIlib
-              -- copy rule (down)
-              _x2Ocat =
-                  _lhsIcat
-              -- copy rule (down)
-              _x2Oidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _x2Olib =
-                  _lhsIlib
-              ( _x1IannotatedTree,_x1IfixedUpIdentifiersTree,_x1IoriginalTree,_x1IuType) =
-                  x1_ _x1Ocat _x1OexpectedTypes _x1Oidenv _x1Olib 
-              ( _x2IannotatedTree,_x2IfixedUpIdentifiersTree,_x2IoriginalTree,_x2IproducedCat,_x2IproducedLib) =
-                  x2_ _x2Ocat _x2OcatUpdates _x2Oidenv _x2Olib _x2OlibUpdates 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- ScalarExprListStatementListPairList -------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative Cons:
-         child hd             : ScalarExprListStatementListPair 
-         child tl             : ScalarExprListStatementListPairList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type ScalarExprListStatementListPairList  = [ScalarExprListStatementListPair ]
--- cata
-sem_ScalarExprListStatementListPairList :: ScalarExprListStatementListPairList  ->
-                                           T_ScalarExprListStatementListPairList 
-sem_ScalarExprListStatementListPairList list  =
-    (Prelude.foldr sem_ScalarExprListStatementListPairList_Cons sem_ScalarExprListStatementListPairList_Nil (Prelude.map sem_ScalarExprListStatementListPair list) )
--- semantic domain
-type T_ScalarExprListStatementListPairList  = Catalog ->
-                                              IDEnv ->
-                                              LocalBindings ->
-                                              ( ScalarExprListStatementListPairList ,ScalarExprListStatementListPairList ,ScalarExprListStatementListPairList )
-data Inh_ScalarExprListStatementListPairList  = Inh_ScalarExprListStatementListPairList {cat_Inh_ScalarExprListStatementListPairList :: Catalog,idenv_Inh_ScalarExprListStatementListPairList :: IDEnv,lib_Inh_ScalarExprListStatementListPairList :: LocalBindings}
-data Syn_ScalarExprListStatementListPairList  = Syn_ScalarExprListStatementListPairList {annotatedTree_Syn_ScalarExprListStatementListPairList :: ScalarExprListStatementListPairList ,fixedUpIdentifiersTree_Syn_ScalarExprListStatementListPairList :: ScalarExprListStatementListPairList ,originalTree_Syn_ScalarExprListStatementListPairList :: ScalarExprListStatementListPairList }
-wrap_ScalarExprListStatementListPairList :: T_ScalarExprListStatementListPairList  ->
-                                            Inh_ScalarExprListStatementListPairList  ->
-                                            Syn_ScalarExprListStatementListPairList 
-wrap_ScalarExprListStatementListPairList sem (Inh_ScalarExprListStatementListPairList _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_ScalarExprListStatementListPairList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_ScalarExprListStatementListPairList_Cons :: T_ScalarExprListStatementListPair  ->
-                                                T_ScalarExprListStatementListPairList  ->
-                                                T_ScalarExprListStatementListPairList 
-sem_ScalarExprListStatementListPairList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExprListStatementListPairList 
-              _lhsOfixedUpIdentifiersTree :: ScalarExprListStatementListPairList 
-              _lhsOoriginalTree :: ScalarExprListStatementListPairList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: ScalarExprListStatementListPair 
-              _hdIfixedUpIdentifiersTree :: ScalarExprListStatementListPair 
-              _hdIoriginalTree :: ScalarExprListStatementListPair 
-              _tlIannotatedTree :: ScalarExprListStatementListPairList 
-              _tlIfixedUpIdentifiersTree :: ScalarExprListStatementListPairList 
-              _tlIoriginalTree :: ScalarExprListStatementListPairList 
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIfixedUpIdentifiersTree,_hdIoriginalTree) =
-                  hd_ _hdOcat _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIfixedUpIdentifiersTree,_tlIoriginalTree) =
-                  tl_ _tlOcat _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_ScalarExprListStatementListPairList_Nil :: T_ScalarExprListStatementListPairList 
-sem_ScalarExprListStatementListPairList_Nil  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExprListStatementListPairList 
-              _lhsOfixedUpIdentifiersTree :: ScalarExprListStatementListPairList 
-              _lhsOoriginalTree :: ScalarExprListStatementListPairList 
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- ScalarExprRoot ----------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative ScalarExprRoot:
-         child expr           : ScalarExpr 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data ScalarExprRoot  = ScalarExprRoot (ScalarExpr ) 
-                     deriving ( Show)
--- cata
-sem_ScalarExprRoot :: ScalarExprRoot  ->
-                      T_ScalarExprRoot 
-sem_ScalarExprRoot (ScalarExprRoot _expr )  =
-    (sem_ScalarExprRoot_ScalarExprRoot (sem_ScalarExpr _expr ) )
--- semantic domain
-type T_ScalarExprRoot  = Catalog ->
-                         IDEnv ->
-                         LocalBindings ->
-                         ( ScalarExprRoot ,ScalarExprRoot ,ScalarExprRoot )
-data Inh_ScalarExprRoot  = Inh_ScalarExprRoot {cat_Inh_ScalarExprRoot :: Catalog,idenv_Inh_ScalarExprRoot :: IDEnv,lib_Inh_ScalarExprRoot :: LocalBindings}
-data Syn_ScalarExprRoot  = Syn_ScalarExprRoot {annotatedTree_Syn_ScalarExprRoot :: ScalarExprRoot ,fixedUpIdentifiersTree_Syn_ScalarExprRoot :: ScalarExprRoot ,originalTree_Syn_ScalarExprRoot :: ScalarExprRoot }
-wrap_ScalarExprRoot :: T_ScalarExprRoot  ->
-                       Inh_ScalarExprRoot  ->
-                       Syn_ScalarExprRoot 
-wrap_ScalarExprRoot sem (Inh_ScalarExprRoot _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_ScalarExprRoot _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_ScalarExprRoot_ScalarExprRoot :: T_ScalarExpr  ->
-                                     T_ScalarExprRoot 
-sem_ScalarExprRoot_ScalarExprRoot expr_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _exprOexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: ScalarExprRoot 
-              _lhsOfixedUpIdentifiersTree :: ScalarExprRoot 
-              _lhsOoriginalTree :: ScalarExprRoot 
-              _exprOcat :: Catalog
-              _exprOidenv :: IDEnv
-              _exprOlib :: LocalBindings
-              _exprIannotatedTree :: ScalarExpr 
-              _exprIfixedUpIdentifiersTree :: ScalarExpr 
-              _exprIoriginalTree :: ScalarExpr 
-              _exprIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 120, column 22)
-              _exprOexpectedType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  ScalarExprRoot _exprIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  ScalarExprRoot _exprIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  ScalarExprRoot _exprIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _exprOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exprOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exprOlib =
-                  _lhsIlib
-              ( _exprIannotatedTree,_exprIfixedUpIdentifiersTree,_exprIoriginalTree,_exprIuType) =
-                  expr_ _exprOcat _exprOexpectedType _exprOidenv _exprOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- ScalarExprStatementListPair ---------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative Tuple:
-         child x1             : ScalarExpr 
-         child x2             : StatementList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type ScalarExprStatementListPair  = ( ScalarExpr ,StatementList )
--- cata
-sem_ScalarExprStatementListPair :: ScalarExprStatementListPair  ->
-                                   T_ScalarExprStatementListPair 
-sem_ScalarExprStatementListPair ( x1,x2)  =
-    (sem_ScalarExprStatementListPair_Tuple (sem_ScalarExpr x1 ) (sem_StatementList x2 ) )
--- semantic domain
-type T_ScalarExprStatementListPair  = Catalog ->
-                                      IDEnv ->
-                                      LocalBindings ->
-                                      ( ScalarExprStatementListPair ,ScalarExprStatementListPair ,ScalarExprStatementListPair )
-data Inh_ScalarExprStatementListPair  = Inh_ScalarExprStatementListPair {cat_Inh_ScalarExprStatementListPair :: Catalog,idenv_Inh_ScalarExprStatementListPair :: IDEnv,lib_Inh_ScalarExprStatementListPair :: LocalBindings}
-data Syn_ScalarExprStatementListPair  = Syn_ScalarExprStatementListPair {annotatedTree_Syn_ScalarExprStatementListPair :: ScalarExprStatementListPair ,fixedUpIdentifiersTree_Syn_ScalarExprStatementListPair :: ScalarExprStatementListPair ,originalTree_Syn_ScalarExprStatementListPair :: ScalarExprStatementListPair }
-wrap_ScalarExprStatementListPair :: T_ScalarExprStatementListPair  ->
-                                    Inh_ScalarExprStatementListPair  ->
-                                    Syn_ScalarExprStatementListPair 
-wrap_ScalarExprStatementListPair sem (Inh_ScalarExprStatementListPair _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_ScalarExprStatementListPair _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_ScalarExprStatementListPair_Tuple :: T_ScalarExpr  ->
-                                         T_StatementList  ->
-                                         T_ScalarExprStatementListPair 
-sem_ScalarExprStatementListPair_Tuple x1_ x2_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _x2OcatUpdates :: ([CatalogUpdate])
-              _x2OlibUpdates :: ([LocalBindingsUpdate])
-              _x1OexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: ScalarExprStatementListPair 
-              _lhsOfixedUpIdentifiersTree :: ScalarExprStatementListPair 
-              _lhsOoriginalTree :: ScalarExprStatementListPair 
-              _x1Ocat :: Catalog
-              _x1Oidenv :: IDEnv
-              _x1Olib :: LocalBindings
-              _x2Ocat :: Catalog
-              _x2Oidenv :: IDEnv
-              _x2Olib :: LocalBindings
-              _x1IannotatedTree :: ScalarExpr 
-              _x1IfixedUpIdentifiersTree :: ScalarExpr 
-              _x1IoriginalTree :: ScalarExpr 
-              _x1IuType :: (Maybe Type)
-              _x2IannotatedTree :: StatementList 
-              _x2IfixedUpIdentifiersTree :: StatementList 
-              _x2IoriginalTree :: StatementList 
-              _x2IproducedCat :: Catalog
-              _x2IproducedLib :: LocalBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 125, column 9)
-              _x2OcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 126, column 9)
-              _x2OlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 123, column 13)
-              _x1OexpectedType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  (_x1IannotatedTree,_x2IannotatedTree)
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (_x1IfixedUpIdentifiersTree,_x2IfixedUpIdentifiersTree)
-              -- self rule
-              _originalTree =
-                  (_x1IoriginalTree,_x2IoriginalTree)
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _x1Ocat =
-                  _lhsIcat
-              -- copy rule (down)
-              _x1Oidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _x1Olib =
-                  _lhsIlib
-              -- copy rule (down)
-              _x2Ocat =
-                  _lhsIcat
-              -- copy rule (down)
-              _x2Oidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _x2Olib =
-                  _lhsIlib
-              ( _x1IannotatedTree,_x1IfixedUpIdentifiersTree,_x1IoriginalTree,_x1IuType) =
-                  x1_ _x1Ocat _x1OexpectedType _x1Oidenv _x1Olib 
-              ( _x2IannotatedTree,_x2IfixedUpIdentifiersTree,_x2IoriginalTree,_x2IproducedCat,_x2IproducedLib) =
-                  x2_ _x2Ocat _x2OcatUpdates _x2Oidenv _x2Olib _x2OlibUpdates 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- ScalarExprStatementListPairList -----------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative Cons:
-         child hd             : ScalarExprStatementListPair 
-         child tl             : ScalarExprStatementListPairList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type ScalarExprStatementListPairList  = [ScalarExprStatementListPair ]
--- cata
-sem_ScalarExprStatementListPairList :: ScalarExprStatementListPairList  ->
-                                       T_ScalarExprStatementListPairList 
-sem_ScalarExprStatementListPairList list  =
-    (Prelude.foldr sem_ScalarExprStatementListPairList_Cons sem_ScalarExprStatementListPairList_Nil (Prelude.map sem_ScalarExprStatementListPair list) )
--- semantic domain
-type T_ScalarExprStatementListPairList  = Catalog ->
-                                          IDEnv ->
-                                          LocalBindings ->
-                                          ( ScalarExprStatementListPairList ,ScalarExprStatementListPairList ,ScalarExprStatementListPairList )
-data Inh_ScalarExprStatementListPairList  = Inh_ScalarExprStatementListPairList {cat_Inh_ScalarExprStatementListPairList :: Catalog,idenv_Inh_ScalarExprStatementListPairList :: IDEnv,lib_Inh_ScalarExprStatementListPairList :: LocalBindings}
-data Syn_ScalarExprStatementListPairList  = Syn_ScalarExprStatementListPairList {annotatedTree_Syn_ScalarExprStatementListPairList :: ScalarExprStatementListPairList ,fixedUpIdentifiersTree_Syn_ScalarExprStatementListPairList :: ScalarExprStatementListPairList ,originalTree_Syn_ScalarExprStatementListPairList :: ScalarExprStatementListPairList }
-wrap_ScalarExprStatementListPairList :: T_ScalarExprStatementListPairList  ->
-                                        Inh_ScalarExprStatementListPairList  ->
-                                        Syn_ScalarExprStatementListPairList 
-wrap_ScalarExprStatementListPairList sem (Inh_ScalarExprStatementListPairList _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_ScalarExprStatementListPairList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_ScalarExprStatementListPairList_Cons :: T_ScalarExprStatementListPair  ->
-                                            T_ScalarExprStatementListPairList  ->
-                                            T_ScalarExprStatementListPairList 
-sem_ScalarExprStatementListPairList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExprStatementListPairList 
-              _lhsOfixedUpIdentifiersTree :: ScalarExprStatementListPairList 
-              _lhsOoriginalTree :: ScalarExprStatementListPairList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: ScalarExprStatementListPair 
-              _hdIfixedUpIdentifiersTree :: ScalarExprStatementListPair 
-              _hdIoriginalTree :: ScalarExprStatementListPair 
-              _tlIannotatedTree :: ScalarExprStatementListPairList 
-              _tlIfixedUpIdentifiersTree :: ScalarExprStatementListPairList 
-              _tlIoriginalTree :: ScalarExprStatementListPairList 
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIfixedUpIdentifiersTree,_hdIoriginalTree) =
-                  hd_ _hdOcat _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIfixedUpIdentifiersTree,_tlIoriginalTree) =
-                  tl_ _tlOcat _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_ScalarExprStatementListPairList_Nil :: T_ScalarExprStatementListPairList 
-sem_ScalarExprStatementListPairList_Nil  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: ScalarExprStatementListPairList 
-              _lhsOfixedUpIdentifiersTree :: ScalarExprStatementListPairList 
-              _lhsOoriginalTree :: ScalarExprStatementListPairList 
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- SelectItem --------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         itemType             : (String,Maybe Type)
-         originalTree         : SELF 
-         seIdTree             : [SelectItem]
-   alternatives:
-      alternative SelExp:
-         child ann            : {Annotation}
-         child ex             : ScalarExpr 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative SelectItem:
-         child ann            : {Annotation}
-         child ex             : ScalarExpr 
-         child name           : {NameComponent}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data SelectItem  = SelExp (Annotation) (ScalarExpr ) 
-                 | SelectItem (Annotation) (ScalarExpr ) (NameComponent) 
-                 deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_SelectItem :: SelectItem  ->
-                  T_SelectItem 
-sem_SelectItem (SelExp _ann _ex )  =
-    (sem_SelectItem_SelExp _ann (sem_ScalarExpr _ex ) )
-sem_SelectItem (SelectItem _ann _ex _name )  =
-    (sem_SelectItem_SelectItem _ann (sem_ScalarExpr _ex ) _name )
--- semantic domain
-type T_SelectItem  = Catalog ->
-                     IDEnv ->
-                     LocalBindings ->
-                     ( SelectItem ,SelectItem ,((String,Maybe Type)),SelectItem ,([SelectItem]))
-data Inh_SelectItem  = Inh_SelectItem {cat_Inh_SelectItem :: Catalog,idenv_Inh_SelectItem :: IDEnv,lib_Inh_SelectItem :: LocalBindings}
-data Syn_SelectItem  = Syn_SelectItem {annotatedTree_Syn_SelectItem :: SelectItem ,fixedUpIdentifiersTree_Syn_SelectItem :: SelectItem ,itemType_Syn_SelectItem :: ((String,Maybe Type)),originalTree_Syn_SelectItem :: SelectItem ,seIdTree_Syn_SelectItem :: ([SelectItem])}
-wrap_SelectItem :: T_SelectItem  ->
-                   Inh_SelectItem  ->
-                   Syn_SelectItem 
-wrap_SelectItem sem (Inh_SelectItem _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOitemType,_lhsOoriginalTree,_lhsOseIdTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_SelectItem _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOitemType _lhsOoriginalTree _lhsOseIdTree ))
-sem_SelectItem_SelExp :: Annotation ->
-                         T_ScalarExpr  ->
-                         T_SelectItem 
-sem_SelectItem_SelExp ann_ ex_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOseIdTree :: ([SelectItem])
-              _lhsOitemType :: ((String,Maybe Type))
-              _exOexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: SelectItem 
-              _lhsOfixedUpIdentifiersTree :: SelectItem 
-              _lhsOoriginalTree :: SelectItem 
-              _exOcat :: Catalog
-              _exOidenv :: IDEnv
-              _exOlib :: LocalBindings
-              _exIannotatedTree :: ScalarExpr 
-              _exIfixedUpIdentifiersTree :: ScalarExpr 
-              _exIoriginalTree :: ScalarExpr 
-              _exIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 147, column 14)
-              _lhsOseIdTree =
-                  case _exIfixedUpIdentifiersTree of
-                    Star a ->
-                       maybe [SelExp ann_ _exIfixedUpIdentifiersTree]
-                             (makeSelExps ann_ a a)
-                             $ expandStar _lhsIidenv Nothing
-                    QStar a0 (Nmc q) ->
-                       maybe [SelExp ann_ _exIfixedUpIdentifiersTree]
-                             (makeSelExps ann_ a0 a0)
-                             $ expandStar _lhsIidenv $ Just q
-                    _ -> [addSIAlias $ SelExp ann_ _exIfixedUpIdentifiersTree]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 32, column 9)
-              _annotatedTree =
-                  SelExp ann_ _exIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 60, column 9)
-              _lhsOitemType =
-                  ("", Nothing)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 106, column 25)
-              _exOexpectedType =
-                  Nothing
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  SelExp ann_ _exIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  SelExp ann_ _exIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _exOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exOlib =
-                  _lhsIlib
-              ( _exIannotatedTree,_exIfixedUpIdentifiersTree,_exIoriginalTree,_exIuType) =
-                  ex_ _exOcat _exOexpectedType _exOidenv _exOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOitemType,_lhsOoriginalTree,_lhsOseIdTree)))
-sem_SelectItem_SelectItem :: Annotation ->
-                             T_ScalarExpr  ->
-                             NameComponent ->
-                             T_SelectItem 
-sem_SelectItem_SelectItem ann_ ex_ name_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOseIdTree :: ([SelectItem])
-              _lhsOitemType :: ((String,Maybe Type))
-              _exOexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: SelectItem 
-              _lhsOfixedUpIdentifiersTree :: SelectItem 
-              _lhsOoriginalTree :: SelectItem 
-              _exOcat :: Catalog
-              _exOidenv :: IDEnv
-              _exOlib :: LocalBindings
-              _exIannotatedTree :: ScalarExpr 
-              _exIfixedUpIdentifiersTree :: ScalarExpr 
-              _exIoriginalTree :: ScalarExpr 
-              _exIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 168, column 18)
-              _lhsOseIdTree =
-                  [SelectItem ann_ _exIfixedUpIdentifiersTree name_]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 34, column 9)
-              _annotatedTree =
-                  SelectItem ann_ _exIannotatedTree name_
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 62, column 9)
-              _lhsOitemType =
-                  (ncStr name_, unwrapSetof `fmap` _exIuType)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 106, column 25)
-              _exOexpectedType =
-                  Nothing
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  SelectItem ann_ _exIfixedUpIdentifiersTree name_
-              -- self rule
-              _originalTree =
-                  SelectItem ann_ _exIoriginalTree name_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _exOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exOlib =
-                  _lhsIlib
-              ( _exIannotatedTree,_exIfixedUpIdentifiersTree,_exIoriginalTree,_exIuType) =
-                  ex_ _exOcat _exOexpectedType _exOidenv _exOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOitemType,_lhsOoriginalTree,_lhsOseIdTree)))
--- SelectItemList ----------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         listType             : [(String,Maybe Type)]
-         originalTree         : SELF 
-   alternatives:
-      alternative Cons:
-         child hd             : SelectItem 
-         child tl             : SelectItemList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type SelectItemList  = [SelectItem ]
--- cata
-sem_SelectItemList :: SelectItemList  ->
-                      T_SelectItemList 
-sem_SelectItemList list  =
-    (Prelude.foldr sem_SelectItemList_Cons sem_SelectItemList_Nil (Prelude.map sem_SelectItem list) )
--- semantic domain
-type T_SelectItemList  = Catalog ->
-                         IDEnv ->
-                         LocalBindings ->
-                         ( SelectItemList ,SelectItemList ,([(String,Maybe Type)]),SelectItemList )
-data Inh_SelectItemList  = Inh_SelectItemList {cat_Inh_SelectItemList :: Catalog,idenv_Inh_SelectItemList :: IDEnv,lib_Inh_SelectItemList :: LocalBindings}
-data Syn_SelectItemList  = Syn_SelectItemList {annotatedTree_Syn_SelectItemList :: SelectItemList ,fixedUpIdentifiersTree_Syn_SelectItemList :: SelectItemList ,listType_Syn_SelectItemList :: ([(String,Maybe Type)]),originalTree_Syn_SelectItemList :: SelectItemList }
-wrap_SelectItemList :: T_SelectItemList  ->
-                       Inh_SelectItemList  ->
-                       Syn_SelectItemList 
-wrap_SelectItemList sem (Inh_SelectItemList _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlistType,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_SelectItemList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOlistType _lhsOoriginalTree ))
-sem_SelectItemList_Cons :: T_SelectItem  ->
-                           T_SelectItemList  ->
-                           T_SelectItemList 
-sem_SelectItemList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOfixedUpIdentifiersTree :: SelectItemList 
-              _lhsOlistType :: ([(String,Maybe Type)])
-              _lhsOannotatedTree :: SelectItemList 
-              _lhsOoriginalTree :: SelectItemList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: SelectItem 
-              _hdIfixedUpIdentifiersTree :: SelectItem 
-              _hdIitemType :: ((String,Maybe Type))
-              _hdIoriginalTree :: SelectItem 
-              _hdIseIdTree :: ([SelectItem])
-              _tlIannotatedTree :: SelectItemList 
-              _tlIfixedUpIdentifiersTree :: SelectItemList 
-              _tlIlistType :: ([(String,Maybe Type)])
-              _tlIoriginalTree :: SelectItemList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 138, column 12)
-              _lhsOfixedUpIdentifiersTree =
-                  _hdIseIdTree ++ _tlIfixedUpIdentifiersTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 12)
-              _lhsOlistType =
-                  _hdIitemType : _tlIlistType
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIfixedUpIdentifiersTree,_hdIitemType,_hdIoriginalTree,_hdIseIdTree) =
-                  hd_ _hdOcat _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIfixedUpIdentifiersTree,_tlIlistType,_tlIoriginalTree) =
-                  tl_ _tlOcat _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlistType,_lhsOoriginalTree)))
-sem_SelectItemList_Nil :: T_SelectItemList 
-sem_SelectItemList_Nil  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOfixedUpIdentifiersTree :: SelectItemList 
-              _lhsOlistType :: ([(String,Maybe Type)])
-              _lhsOannotatedTree :: SelectItemList 
-              _lhsOoriginalTree :: SelectItemList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 139, column 11)
-              _lhsOfixedUpIdentifiersTree =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 43, column 11)
-              _lhsOlistType =
-                  []
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlistType,_lhsOoriginalTree)))
--- SelectList --------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         cidenv               : IDEnv
-         fixedUpIdentifiersTree : SELF 
-         libUpdates           : [LocalBindingsUpdate]
-         listType             : [(String,Maybe Type)]
-         originalTree         : SELF 
-   alternatives:
-      alternative SelectList:
-         child ann            : {Annotation}
-         child items          : SelectItemList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data SelectList  = SelectList (Annotation) (SelectItemList ) 
-                 deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_SelectList :: SelectList  ->
-                  T_SelectList 
-sem_SelectList (SelectList _ann _items )  =
-    (sem_SelectList_SelectList _ann (sem_SelectItemList _items ) )
--- semantic domain
-type T_SelectList  = Catalog ->
-                     IDEnv ->
-                     LocalBindings ->
-                     ( SelectList ,IDEnv,SelectList ,([LocalBindingsUpdate]),([(String,Maybe Type)]),SelectList )
-data Inh_SelectList  = Inh_SelectList {cat_Inh_SelectList :: Catalog,idenv_Inh_SelectList :: IDEnv,lib_Inh_SelectList :: LocalBindings}
-data Syn_SelectList  = Syn_SelectList {annotatedTree_Syn_SelectList :: SelectList ,cidenv_Syn_SelectList :: IDEnv,fixedUpIdentifiersTree_Syn_SelectList :: SelectList ,libUpdates_Syn_SelectList :: ([LocalBindingsUpdate]),listType_Syn_SelectList :: ([(String,Maybe Type)]),originalTree_Syn_SelectList :: SelectList }
-wrap_SelectList :: T_SelectList  ->
-                   Inh_SelectList  ->
-                   Syn_SelectList 
-wrap_SelectList sem (Inh_SelectList _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOcidenv,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOlistType,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_SelectList _lhsOannotatedTree _lhsOcidenv _lhsOfixedUpIdentifiersTree _lhsOlibUpdates _lhsOlistType _lhsOoriginalTree ))
-sem_SelectList_SelectList :: Annotation ->
-                             T_SelectItemList  ->
-                             T_SelectList 
-sem_SelectList_SelectList ann_ items_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOcidenv :: IDEnv
-              _lhsOlistType :: ([(String,Maybe Type)])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: SelectList 
-              _lhsOfixedUpIdentifiersTree :: SelectList 
-              _lhsOoriginalTree :: SelectList 
-              _itemsOcat :: Catalog
-              _itemsOidenv :: IDEnv
-              _itemsOlib :: LocalBindings
-              _itemsIannotatedTree :: SelectItemList 
-              _itemsIfixedUpIdentifiersTree :: SelectItemList 
-              _itemsIlistType :: ([(String,Maybe Type)])
-              _itemsIoriginalTree :: SelectItemList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 119, column 9)
-              _lhsOcidenv =
-                  TrefIDEnv "" (map (\(SelectItem _ _ n) -> ncStr n)
-                                  _itemsIfixedUpIdentifiersTree)
-                             []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 77, column 9)
-              _lhsOlistType =
-                  _itemsIlistType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 97, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 131, column 9)
-              _lhsOannotatedTree =
-                  SelectList ann_
-                             _itemsIannotatedTree
-              -- self rule
-              _annotatedTree =
-                  SelectList ann_ _itemsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  SelectList ann_ _itemsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  SelectList ann_ _itemsIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _itemsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _itemsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _itemsOlib =
-                  _lhsIlib
-              ( _itemsIannotatedTree,_itemsIfixedUpIdentifiersTree,_itemsIlistType,_itemsIoriginalTree) =
-                  items_ _itemsOcat _itemsOidenv _itemsOlib 
-          in  ( _lhsOannotatedTree,_lhsOcidenv,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOlistType,_lhsOoriginalTree)))
--- SetClause ---------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-         tbName               : String
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative MultiSetClause:
-         child ann            : {Annotation}
-         child setTargets     : {[NameComponent]}
-         child ex             : ScalarExpr 
-         visit 0:
-            local targType    : {E Type}
-            local e           : _
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative SetClause:
-         child ann            : {Annotation}
-         child setTarget      : {NameComponent}
-         child ex             : ScalarExpr 
-         visit 0:
-            local targType    : {E Type}
-            local e           : {E ()}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data SetClause  = MultiSetClause (Annotation) (([NameComponent])) (ScalarExpr ) 
-                | SetClause (Annotation) (NameComponent) (ScalarExpr ) 
-                deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_SetClause :: SetClause  ->
-                 T_SetClause 
-sem_SetClause (MultiSetClause _ann _setTargets _ex )  =
-    (sem_SetClause_MultiSetClause _ann _setTargets (sem_ScalarExpr _ex ) )
-sem_SetClause (SetClause _ann _setTarget _ex )  =
-    (sem_SetClause_SetClause _ann _setTarget (sem_ScalarExpr _ex ) )
--- semantic domain
-type T_SetClause  = Catalog ->
-                    IDEnv ->
-                    LocalBindings ->
-                    String ->
-                    ( SetClause ,SetClause ,SetClause )
-data Inh_SetClause  = Inh_SetClause {cat_Inh_SetClause :: Catalog,idenv_Inh_SetClause :: IDEnv,lib_Inh_SetClause :: LocalBindings,tbName_Inh_SetClause :: String}
-data Syn_SetClause  = Syn_SetClause {annotatedTree_Syn_SetClause :: SetClause ,fixedUpIdentifiersTree_Syn_SetClause :: SetClause ,originalTree_Syn_SetClause :: SetClause }
-wrap_SetClause :: T_SetClause  ->
-                  Inh_SetClause  ->
-                  Syn_SetClause 
-wrap_SetClause sem (Inh_SetClause _lhsIcat _lhsIidenv _lhsIlib _lhsItbName )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib _lhsItbName 
-     in  (Syn_SetClause _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_SetClause_MultiSetClause :: Annotation ->
-                                ([NameComponent]) ->
-                                T_ScalarExpr  ->
-                                T_SetClause 
-sem_SetClause_MultiSetClause ann_ setTargets_ ex_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib
-       _lhsItbName ->
-         (let _targType :: (E Type)
-              _exOexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: SetClause 
-              _lhsOfixedUpIdentifiersTree :: SetClause 
-              _lhsOoriginalTree :: SetClause 
-              _exOcat :: Catalog
-              _exOidenv :: IDEnv
-              _exOlib :: LocalBindings
-              _exIannotatedTree :: ScalarExpr 
-              _exIfixedUpIdentifiersTree :: ScalarExpr 
-              _exIoriginalTree :: ScalarExpr 
-              _exIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 77, column 9)
-              _targType =
-                  do
-                  let etargTypes :: [E (Maybe Type)]
-                      etargTypes = map (lookupLocalBinding _lhsIlib _lhsItbName . ncStr) setTargets_
-                  concatLefts etargTypes
-                  targTypes <- lmt $ sequence $ rights etargTypes
-                  return $ AnonymousRecordType targTypes
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 84, column 9)
-              _e =
-                  do
-                  tt <- _targType
-                  exType <- lmt _exIuType
-                  checkAssignmentValid _lhsIcat exType tt
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 88, column 9)
-              _exOexpectedType =
-                  etmt _targType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 89, column 9)
-              _backTree =
-                  MultiSetClause ann_ setTargets_ _exIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 93, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {errs = errs a ++ tes _e    })
-                      _backTree
-              -- self rule
-              _annotatedTree =
-                  MultiSetClause ann_ setTargets_ _exIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  MultiSetClause ann_ setTargets_ _exIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  MultiSetClause ann_ setTargets_ _exIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _exOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exOlib =
-                  _lhsIlib
-              ( _exIannotatedTree,_exIfixedUpIdentifiersTree,_exIoriginalTree,_exIuType) =
-                  ex_ _exOcat _exOexpectedType _exOidenv _exOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_SetClause_SetClause :: Annotation ->
-                           NameComponent ->
-                           T_ScalarExpr  ->
-                           T_SetClause 
-sem_SetClause_SetClause ann_ setTarget_ ex_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib
-       _lhsItbName ->
-         (let _targType :: (E Type)
-              _e :: (E ())
-              _exOexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: SetClause 
-              _lhsOfixedUpIdentifiersTree :: SetClause 
-              _lhsOoriginalTree :: SetClause 
-              _exOcat :: Catalog
-              _exOidenv :: IDEnv
-              _exOlib :: LocalBindings
-              _exIannotatedTree :: ScalarExpr 
-              _exIfixedUpIdentifiersTree :: ScalarExpr 
-              _exIoriginalTree :: ScalarExpr 
-              _exIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 64, column 9)
-              _targType =
-                  case lookupLocalBinding _lhsIlib _lhsItbName $ ncStr setTarget_ of
-                         Right Nothing -> Left []
-                         Right (Just t) -> Right t
-                         Left e -> Left e
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 69, column 9)
-              _e =
-                  do
-                  tt <- _targType
-                  exType <- lmt _exIuType
-                  checkAssignmentValid _lhsIcat exType tt
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 73, column 9)
-              _exOexpectedType =
-                  etmt _targType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 74, column 9)
-              _backTree =
-                  SetClause ann_ setTarget_ _exIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 93, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {errs = errs a ++ tes _e    })
-                      _backTree
-              -- self rule
-              _annotatedTree =
-                  SetClause ann_ setTarget_ _exIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  SetClause ann_ setTarget_ _exIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  SetClause ann_ setTarget_ _exIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _exOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exOlib =
-                  _lhsIlib
-              ( _exIannotatedTree,_exIfixedUpIdentifiersTree,_exIoriginalTree,_exIuType) =
-                  ex_ _exOcat _exOexpectedType _exOidenv _exOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- SetClauseList -----------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-         tbName               : String
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative Cons:
-         child hd             : SetClause 
-         child tl             : SetClauseList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type SetClauseList  = [SetClause ]
--- cata
-sem_SetClauseList :: SetClauseList  ->
-                     T_SetClauseList 
-sem_SetClauseList list  =
-    (Prelude.foldr sem_SetClauseList_Cons sem_SetClauseList_Nil (Prelude.map sem_SetClause list) )
--- semantic domain
-type T_SetClauseList  = Catalog ->
-                        IDEnv ->
-                        LocalBindings ->
-                        String ->
-                        ( SetClauseList ,SetClauseList ,SetClauseList )
-data Inh_SetClauseList  = Inh_SetClauseList {cat_Inh_SetClauseList :: Catalog,idenv_Inh_SetClauseList :: IDEnv,lib_Inh_SetClauseList :: LocalBindings,tbName_Inh_SetClauseList :: String}
-data Syn_SetClauseList  = Syn_SetClauseList {annotatedTree_Syn_SetClauseList :: SetClauseList ,fixedUpIdentifiersTree_Syn_SetClauseList :: SetClauseList ,originalTree_Syn_SetClauseList :: SetClauseList }
-wrap_SetClauseList :: T_SetClauseList  ->
-                      Inh_SetClauseList  ->
-                      Syn_SetClauseList 
-wrap_SetClauseList sem (Inh_SetClauseList _lhsIcat _lhsIidenv _lhsIlib _lhsItbName )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib _lhsItbName 
-     in  (Syn_SetClauseList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_SetClauseList_Cons :: T_SetClause  ->
-                          T_SetClauseList  ->
-                          T_SetClauseList 
-sem_SetClauseList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib
-       _lhsItbName ->
-         (let _lhsOannotatedTree :: SetClauseList 
-              _lhsOfixedUpIdentifiersTree :: SetClauseList 
-              _lhsOoriginalTree :: SetClauseList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _hdOtbName :: String
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _tlOtbName :: String
-              _hdIannotatedTree :: SetClause 
-              _hdIfixedUpIdentifiersTree :: SetClause 
-              _hdIoriginalTree :: SetClause 
-              _tlIannotatedTree :: SetClauseList 
-              _tlIfixedUpIdentifiersTree :: SetClauseList 
-              _tlIoriginalTree :: SetClauseList 
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _hdOtbName =
-                  _lhsItbName
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOtbName =
-                  _lhsItbName
-              ( _hdIannotatedTree,_hdIfixedUpIdentifiersTree,_hdIoriginalTree) =
-                  hd_ _hdOcat _hdOidenv _hdOlib _hdOtbName 
-              ( _tlIannotatedTree,_tlIfixedUpIdentifiersTree,_tlIoriginalTree) =
-                  tl_ _tlOcat _tlOidenv _tlOlib _tlOtbName 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_SetClauseList_Nil :: T_SetClauseList 
-sem_SetClauseList_Nil  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib
-       _lhsItbName ->
-         (let _lhsOannotatedTree :: SetClauseList 
-              _lhsOfixedUpIdentifiersTree :: SetClauseList 
-              _lhsOoriginalTree :: SetClauseList 
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- Statement ---------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         inProducedCat        : Catalog
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         catUpdates           : [CatalogUpdate]
-         fixedUpIdentifiersTree : SELF 
-         libUpdates           : [LocalBindingsUpdate]
-         originalTree         : SELF 
-   alternatives:
-      alternative AlterSequence:
-         child ann            : {Annotation}
-         child name           : Name 
-         child ownedBy        : Name 
-         visit 0:
-            local libUpdates  : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative AlterTable:
-         child ann            : {Annotation}
-         child name           : Name 
-         child actions        : AlterTableActionList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative AntiStatement:
-         child string         : {String}
-         visit 0:
-            local libUpdates  : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Assignment:
-         child ann            : {Annotation}
-         child target         : Name 
-         child value          : ScalarExpr 
-         visit 0:
-            local libUpdates  : _
-            local tpe         : {Either [TypeError] Type}
-            local backTree    : _
-            local catUpdates  : {[CatalogUpdate]}
-            local statementType : {Maybe ParameterizedStatementType}
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Block:
-         child ann            : {Annotation}
-         child lb             : {Maybe String}
-         child vars           : VarDefList 
-         child sts            : StatementList 
-         visit 0:
-            local libUpdates  : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative CaseStatement:
-         child ann            : {Annotation}
-         child cases          : ScalarExprListStatementListPairList 
-         child els            : StatementList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative CaseStatementSimple:
-         child ann            : {Annotation}
-         child val            : ScalarExpr 
-         child cases          : ScalarExprListStatementListPairList 
-         child els            : StatementList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative ContinueStatement:
-         child ann            : {Annotation}
-         child lb             : {Maybe String}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Copy:
-         child ann            : {Annotation}
-         child table          : Name 
-         child targetCols     : {[NameComponent]}
-         child source         : {CopySource}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative CopyData:
-         child ann            : {Annotation}
-         child insData        : {String}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative CreateDomain:
-         child ann            : {Annotation}
-         child name           : Name 
-         child typ            : TypeName 
-         child constraintName : {String}
-         child check          : MaybeBoolExpr 
-         visit 0:
-            local libUpdates  : _
-            local tpe         : {Either [TypeError] Type}
-            local backTree    : _
-            local statementType : {Maybe ParameterizedStatementType}
-            local catUpdates  : {[CatalogUpdate]}
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative CreateFunction:
-         child ann            : {Annotation}
-         child name           : Name 
-         child params         : ParamDefList 
-         child rettype        : TypeName 
-         child rep            : {Replace}
-         child lang           : {Language}
-         child body           : FnBody 
-         child vol            : {Volatility}
-         visit 0:
-            local libUpdates  : _
-            local tpe         : {Either [TypeError] Type}
-            local catUpdates  : {[CatalogUpdate]}
-            local backTree    : _
-            local statementType : {Maybe ParameterizedStatementType}
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative CreateLanguage:
-         child ann            : {Annotation}
-         child name           : {String}
-         visit 0:
-            local libUpdates  : _
-            local tpe         : {Either [TypeError] Type}
-            local backTree    : _
-            local statementType : {Maybe ParameterizedStatementType}
-            local catUpdates  : {[CatalogUpdate]}
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative CreateSequence:
-         child ann            : {Annotation}
-         child name           : Name 
-         child incr           : {Integer}
-         child min            : {Integer}
-         child max            : {Integer}
-         child start          : {Integer}
-         child cache          : {Integer}
-         visit 0:
-            local libUpdates  : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative CreateTable:
-         child ann            : {Annotation}
-         child name           : Name 
-         child atts           : AttributeDefList 
-         child cons           : ConstraintList 
-         visit 0:
-            local libUpdates  : _
-            local tpe         : {Either [TypeError] Type}
-            local catUpdates  : {[CatalogUpdate]}
-            local attrs       : {[(String,Type)]}
-            local statementType : {Maybe ParameterizedStatementType}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative CreateTableAs:
-         child ann            : {Annotation}
-         child name           : Name 
-         child expr           : QueryExpr 
-         visit 0:
-            local libUpdates  : _
-            local tpe         : {Either [TypeError] Type}
-            local catUpdates  : {[CatalogUpdate]}
-            local attrs       : {Either [TypeError] [(String,Type)]}
-            local backTree    : _
-            local statementType : {Maybe ParameterizedStatementType}
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative CreateTrigger:
-         child ann            : {Annotation}
-         child name           : {NameComponent}
-         child wh             : {TriggerWhen}
-         child events         : {[TriggerEvent]}
-         child tbl            : Name 
-         child firing         : {TriggerFire}
-         child fnName         : Name 
-         child fnArgs         : ScalarExprList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative CreateType:
-         child ann            : {Annotation}
-         child name           : Name 
-         child atts           : TypeAttributeDefList 
-         visit 0:
-            local libUpdates  : _
-            local tpe         : {Either [TypeError] Type}
-            local attrs       : _
-            local backTree    : _
-            local statementType : {Maybe ParameterizedStatementType}
-            local catUpdates  : {[CatalogUpdate]}
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative CreateView:
-         child ann            : {Annotation}
-         child name           : Name 
-         child colNames       : {MaybeNameComponentList}
-         child expr           : QueryExpr 
-         visit 0:
-            local libUpdates  : _
-            local tpe         : {Either [TypeError] Type}
-            local backTree    : _
-            local catUpdates  : {[CatalogUpdate]}
-            local statementType : {Maybe ParameterizedStatementType}
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Delete:
-         child ann            : {Annotation}
-         child table          : Name 
-         child using          : TableRefList 
-         child whr            : MaybeBoolExpr 
-         child returning      : MaybeSelectList 
-         visit 0:
-            local trefEnv     : _
-            local libUpdates  : _
-            local tpe         : {Either [TypeError] Type}
-            local statementType : {Maybe ParameterizedStatementType}
-            local backTree    : _
-            local catUpdates  : {[CatalogUpdate]}
-            local lib         : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative DropFunction:
-         child ann            : {Annotation}
-         child ifE            : {IfExists}
-         child sigs           : NameTypeNameListPairList 
-         child cascade        : {Cascade}
-         visit 0:
-            local libUpdates  : _
-            local tpe         : {Either [TypeError] Type}
-            local backTree    : _
-            local catUpdates  : {[CatalogUpdate]}
-            local statementType : {Maybe ParameterizedStatementType}
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative DropSomething:
-         child ann            : {Annotation}
-         child dropType       : {DropType}
-         child ifE            : {IfExists}
-         child names          : {[Name]}
-         child cascade        : {Cascade}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Execute:
-         child ann            : {Annotation}
-         child expr           : ScalarExpr 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative ExitStatement:
-         child ann            : {Annotation}
-         child lb             : {Maybe String}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative ForIntegerStatement:
-         child ann            : {Annotation}
-         child lb             : {Maybe String}
-         child var            : {NameComponent}
-         child from           : ScalarExpr 
-         child to             : ScalarExpr 
-         child sts            : StatementList 
-         visit 0:
-            local libUpdates  : _
-            local tpe         : {Either [TypeError] Type}
-            local backTree    : _
-            local catUpdates  : {[CatalogUpdate]}
-            local statementType : {Maybe ParameterizedStatementType}
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative ForQueryStatement:
-         child ann            : {Annotation}
-         child lb             : {Maybe String}
-         child var            : {NameComponent}
-         child sel            : QueryExpr 
-         child sts            : StatementList 
-         visit 0:
-            local libUpdates  : _
-            local tpe         : {Either [TypeError] Type}
-            local backTree    : _
-            local catUpdates  : {[CatalogUpdate]}
-            local statementType : {Maybe ParameterizedStatementType}
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative If:
-         child ann            : {Annotation}
-         child cases          : ScalarExprStatementListPairList 
-         child els            : StatementList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Insert:
-         child ann            : {Annotation}
-         child table          : Name 
-         child targetCols     : {[NameComponent]}
-         child insData        : QueryExpr 
-         child returning      : MaybeSelectList 
-         visit 0:
-            local trefEnv     : _
-            local libUpdates  : _
-            local tpe         : {Either [TypeError] Type}
-            local statementType : {Maybe ParameterizedStatementType}
-            local columnTypes : {Either [TypeError] [(String,Type)]}
-            local backTree    : _
-            local catUpdates  : {[CatalogUpdate]}
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Into:
-         child ann            : {Annotation}
-         child strict         : {Bool}
-         child into           : {[Name]}
-         child stmt           : Statement 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative LoopStatement:
-         child ann            : {Annotation}
-         child lb             : {Maybe String}
-         child sts            : StatementList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Notify:
-         child ann            : {Annotation}
-         child name           : {String}
-         visit 0:
-            local libUpdates  : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative NullStatement:
-         child ann            : {Annotation}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Perform:
-         child ann            : {Annotation}
-         child expr           : ScalarExpr 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative QueryStatement:
-         child ann            : {Annotation}
-         child ex             : QueryExpr 
-         visit 0:
-            local tpe         : {Either [TypeError] Type}
-            local statementType : {Maybe ParameterizedStatementType}
-            local backTree    : _
-            local catUpdates  : {[CatalogUpdate]}
-            local libUpdates  : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Raise:
-         child ann            : {Annotation}
-         child level          : {RaiseType}
-         child message        : {String}
-         child args           : ScalarExprList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Return:
-         child ann            : {Annotation}
-         child value          : MaybeScalarExpr 
-         visit 0:
-            local libUpdates  : _
-            local tpe         : {Either [TypeError] Type}
-            local backTree    : _
-            local catUpdates  : {[CatalogUpdate]}
-            local statementType : {Maybe ParameterizedStatementType}
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative ReturnNext:
-         child ann            : {Annotation}
-         child expr           : ScalarExpr 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative ReturnQuery:
-         child ann            : {Annotation}
-         child sel            : QueryExpr 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Set:
-         child ann            : {Annotation}
-         child name           : {String}
-         child values         : {[SetValue]}
-         visit 0:
-            local libUpdates  : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Truncate:
-         child ann            : {Annotation}
-         child tables         : {[Name]}
-         child restartIdentity : {RestartIdentity}
-         child cascade        : {Cascade}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Update:
-         child ann            : {Annotation}
-         child table          : Name 
-         child assigns        : SetClauseList 
-         child fromList       : TableRefList 
-         child whr            : MaybeBoolExpr 
-         child returning      : MaybeSelectList 
-         visit 0:
-            local trefEnv     : _
-            local libUpdates  : _
-            local tpe         : {Either [TypeError] Type}
-            local statementType : {Maybe ParameterizedStatementType}
-            local backTree    : _
-            local catUpdates  : {[CatalogUpdate]}
-            local lib         : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative WhileStatement:
-         child ann            : {Annotation}
-         child lb             : {Maybe String}
-         child expr           : ScalarExpr 
-         child sts            : StatementList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data Statement  = AlterSequence (Annotation) (Name ) (Name ) 
-                | AlterTable (Annotation) (Name ) (AlterTableActionList ) 
-                | AntiStatement (String) 
-                | Assignment (Annotation) (Name ) (ScalarExpr ) 
-                | Block (Annotation) ((Maybe String)) (VarDefList ) (StatementList ) 
-                | CaseStatement (Annotation) (ScalarExprListStatementListPairList ) (StatementList ) 
-                | CaseStatementSimple (Annotation) (ScalarExpr ) (ScalarExprListStatementListPairList ) (StatementList ) 
-                | ContinueStatement (Annotation) ((Maybe String)) 
-                | Copy (Annotation) (Name ) (([NameComponent])) (CopySource) 
-                | CopyData (Annotation) (String) 
-                | CreateDomain (Annotation) (Name ) (TypeName ) (String) (MaybeBoolExpr ) 
-                | CreateFunction (Annotation) (Name ) (ParamDefList ) (TypeName ) (Replace) (Language) (FnBody ) (Volatility) 
-                | CreateLanguage (Annotation) (String) 
-                | CreateSequence (Annotation) (Name ) (Integer) (Integer) (Integer) (Integer) (Integer) 
-                | CreateTable (Annotation) (Name ) (AttributeDefList ) (ConstraintList ) 
-                | CreateTableAs (Annotation) (Name ) (QueryExpr ) 
-                | CreateTrigger (Annotation) (NameComponent) (TriggerWhen) (([TriggerEvent])) (Name ) (TriggerFire) (Name ) (ScalarExprList ) 
-                | CreateType (Annotation) (Name ) (TypeAttributeDefList ) 
-                | CreateView (Annotation) (Name ) (MaybeNameComponentList) (QueryExpr ) 
-                | Delete (Annotation) (Name ) (TableRefList ) (MaybeBoolExpr ) (MaybeSelectList ) 
-                | DropFunction (Annotation) (IfExists) (NameTypeNameListPairList ) (Cascade) 
-                | DropSomething (Annotation) (DropType) (IfExists) (([Name])) (Cascade) 
-                | Execute (Annotation) (ScalarExpr ) 
-                | ExitStatement (Annotation) ((Maybe String)) 
-                | ForIntegerStatement (Annotation) ((Maybe String)) (NameComponent) (ScalarExpr ) (ScalarExpr ) (StatementList ) 
-                | ForQueryStatement (Annotation) ((Maybe String)) (NameComponent) (QueryExpr ) (StatementList ) 
-                | If (Annotation) (ScalarExprStatementListPairList ) (StatementList ) 
-                | Insert (Annotation) (Name ) (([NameComponent])) (QueryExpr ) (MaybeSelectList ) 
-                | Into (Annotation) (Bool) (([Name])) (Statement ) 
-                | LoopStatement (Annotation) ((Maybe String)) (StatementList ) 
-                | Notify (Annotation) (String) 
-                | NullStatement (Annotation) 
-                | Perform (Annotation) (ScalarExpr ) 
-                | QueryStatement (Annotation) (QueryExpr ) 
-                | Raise (Annotation) (RaiseType) (String) (ScalarExprList ) 
-                | Return (Annotation) (MaybeScalarExpr ) 
-                | ReturnNext (Annotation) (ScalarExpr ) 
-                | ReturnQuery (Annotation) (QueryExpr ) 
-                | Set (Annotation) (String) (([SetValue])) 
-                | Truncate (Annotation) (([Name])) (RestartIdentity) (Cascade) 
-                | Update (Annotation) (Name ) (SetClauseList ) (TableRefList ) (MaybeBoolExpr ) (MaybeSelectList ) 
-                | WhileStatement (Annotation) ((Maybe String)) (ScalarExpr ) (StatementList ) 
-                deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_Statement :: Statement  ->
-                 T_Statement 
-sem_Statement (AlterSequence _ann _name _ownedBy )  =
-    (sem_Statement_AlterSequence _ann (sem_Name _name ) (sem_Name _ownedBy ) )
-sem_Statement (AlterTable _ann _name _actions )  =
-    (sem_Statement_AlterTable _ann (sem_Name _name ) (sem_AlterTableActionList _actions ) )
-sem_Statement (AntiStatement _string )  =
-    (sem_Statement_AntiStatement _string )
-sem_Statement (Assignment _ann _target _value )  =
-    (sem_Statement_Assignment _ann (sem_Name _target ) (sem_ScalarExpr _value ) )
-sem_Statement (Block _ann _lb _vars _sts )  =
-    (sem_Statement_Block _ann _lb (sem_VarDefList _vars ) (sem_StatementList _sts ) )
-sem_Statement (CaseStatement _ann _cases _els )  =
-    (sem_Statement_CaseStatement _ann (sem_ScalarExprListStatementListPairList _cases ) (sem_StatementList _els ) )
-sem_Statement (CaseStatementSimple _ann _val _cases _els )  =
-    (sem_Statement_CaseStatementSimple _ann (sem_ScalarExpr _val ) (sem_ScalarExprListStatementListPairList _cases ) (sem_StatementList _els ) )
-sem_Statement (ContinueStatement _ann _lb )  =
-    (sem_Statement_ContinueStatement _ann _lb )
-sem_Statement (Copy _ann _table _targetCols _source )  =
-    (sem_Statement_Copy _ann (sem_Name _table ) _targetCols _source )
-sem_Statement (CopyData _ann _insData )  =
-    (sem_Statement_CopyData _ann _insData )
-sem_Statement (CreateDomain _ann _name _typ _constraintName _check )  =
-    (sem_Statement_CreateDomain _ann (sem_Name _name ) (sem_TypeName _typ ) _constraintName (sem_MaybeBoolExpr _check ) )
-sem_Statement (CreateFunction _ann _name _params _rettype _rep _lang _body _vol )  =
-    (sem_Statement_CreateFunction _ann (sem_Name _name ) (sem_ParamDefList _params ) (sem_TypeName _rettype ) _rep _lang (sem_FnBody _body ) _vol )
-sem_Statement (CreateLanguage _ann _name )  =
-    (sem_Statement_CreateLanguage _ann _name )
-sem_Statement (CreateSequence _ann _name _incr _min _max _start _cache )  =
-    (sem_Statement_CreateSequence _ann (sem_Name _name ) _incr _min _max _start _cache )
-sem_Statement (CreateTable _ann _name _atts _cons )  =
-    (sem_Statement_CreateTable _ann (sem_Name _name ) (sem_AttributeDefList _atts ) (sem_ConstraintList _cons ) )
-sem_Statement (CreateTableAs _ann _name _expr )  =
-    (sem_Statement_CreateTableAs _ann (sem_Name _name ) (sem_QueryExpr _expr ) )
-sem_Statement (CreateTrigger _ann _name _wh _events _tbl _firing _fnName _fnArgs )  =
-    (sem_Statement_CreateTrigger _ann _name _wh _events (sem_Name _tbl ) _firing (sem_Name _fnName ) (sem_ScalarExprList _fnArgs ) )
-sem_Statement (CreateType _ann _name _atts )  =
-    (sem_Statement_CreateType _ann (sem_Name _name ) (sem_TypeAttributeDefList _atts ) )
-sem_Statement (CreateView _ann _name _colNames _expr )  =
-    (sem_Statement_CreateView _ann (sem_Name _name ) _colNames (sem_QueryExpr _expr ) )
-sem_Statement (Delete _ann _table _using _whr _returning )  =
-    (sem_Statement_Delete _ann (sem_Name _table ) (sem_TableRefList _using ) (sem_MaybeBoolExpr _whr ) (sem_MaybeSelectList _returning ) )
-sem_Statement (DropFunction _ann _ifE _sigs _cascade )  =
-    (sem_Statement_DropFunction _ann _ifE (sem_NameTypeNameListPairList _sigs ) _cascade )
-sem_Statement (DropSomething _ann _dropType _ifE _names _cascade )  =
-    (sem_Statement_DropSomething _ann _dropType _ifE _names _cascade )
-sem_Statement (Execute _ann _expr )  =
-    (sem_Statement_Execute _ann (sem_ScalarExpr _expr ) )
-sem_Statement (ExitStatement _ann _lb )  =
-    (sem_Statement_ExitStatement _ann _lb )
-sem_Statement (ForIntegerStatement _ann _lb _var _from _to _sts )  =
-    (sem_Statement_ForIntegerStatement _ann _lb _var (sem_ScalarExpr _from ) (sem_ScalarExpr _to ) (sem_StatementList _sts ) )
-sem_Statement (ForQueryStatement _ann _lb _var _sel _sts )  =
-    (sem_Statement_ForQueryStatement _ann _lb _var (sem_QueryExpr _sel ) (sem_StatementList _sts ) )
-sem_Statement (If _ann _cases _els )  =
-    (sem_Statement_If _ann (sem_ScalarExprStatementListPairList _cases ) (sem_StatementList _els ) )
-sem_Statement (Insert _ann _table _targetCols _insData _returning )  =
-    (sem_Statement_Insert _ann (sem_Name _table ) _targetCols (sem_QueryExpr _insData ) (sem_MaybeSelectList _returning ) )
-sem_Statement (Into _ann _strict _into _stmt )  =
-    (sem_Statement_Into _ann _strict _into (sem_Statement _stmt ) )
-sem_Statement (LoopStatement _ann _lb _sts )  =
-    (sem_Statement_LoopStatement _ann _lb (sem_StatementList _sts ) )
-sem_Statement (Notify _ann _name )  =
-    (sem_Statement_Notify _ann _name )
-sem_Statement (NullStatement _ann )  =
-    (sem_Statement_NullStatement _ann )
-sem_Statement (Perform _ann _expr )  =
-    (sem_Statement_Perform _ann (sem_ScalarExpr _expr ) )
-sem_Statement (QueryStatement _ann _ex )  =
-    (sem_Statement_QueryStatement _ann (sem_QueryExpr _ex ) )
-sem_Statement (Raise _ann _level _message _args )  =
-    (sem_Statement_Raise _ann _level _message (sem_ScalarExprList _args ) )
-sem_Statement (Return _ann _value )  =
-    (sem_Statement_Return _ann (sem_MaybeScalarExpr _value ) )
-sem_Statement (ReturnNext _ann _expr )  =
-    (sem_Statement_ReturnNext _ann (sem_ScalarExpr _expr ) )
-sem_Statement (ReturnQuery _ann _sel )  =
-    (sem_Statement_ReturnQuery _ann (sem_QueryExpr _sel ) )
-sem_Statement (Set _ann _name _values )  =
-    (sem_Statement_Set _ann _name _values )
-sem_Statement (Truncate _ann _tables _restartIdentity _cascade )  =
-    (sem_Statement_Truncate _ann _tables _restartIdentity _cascade )
-sem_Statement (Update _ann _table _assigns _fromList _whr _returning )  =
-    (sem_Statement_Update _ann (sem_Name _table ) (sem_SetClauseList _assigns ) (sem_TableRefList _fromList ) (sem_MaybeBoolExpr _whr ) (sem_MaybeSelectList _returning ) )
-sem_Statement (WhileStatement _ann _lb _expr _sts )  =
-    (sem_Statement_WhileStatement _ann _lb (sem_ScalarExpr _expr ) (sem_StatementList _sts ) )
--- semantic domain
-type T_Statement  = Catalog ->
-                    IDEnv ->
-                    Catalog ->
-                    LocalBindings ->
-                    ( Statement ,([CatalogUpdate]),Statement ,([LocalBindingsUpdate]),Statement )
-data Inh_Statement  = Inh_Statement {cat_Inh_Statement :: Catalog,idenv_Inh_Statement :: IDEnv,inProducedCat_Inh_Statement :: Catalog,lib_Inh_Statement :: LocalBindings}
-data Syn_Statement  = Syn_Statement {annotatedTree_Syn_Statement :: Statement ,catUpdates_Syn_Statement :: ([CatalogUpdate]),fixedUpIdentifiersTree_Syn_Statement :: Statement ,libUpdates_Syn_Statement :: ([LocalBindingsUpdate]),originalTree_Syn_Statement :: Statement }
-wrap_Statement :: T_Statement  ->
-                  Inh_Statement  ->
-                  Syn_Statement 
-wrap_Statement sem (Inh_Statement _lhsIcat _lhsIidenv _lhsIinProducedCat _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIinProducedCat _lhsIlib 
-     in  (Syn_Statement _lhsOannotatedTree _lhsOcatUpdates _lhsOfixedUpIdentifiersTree _lhsOlibUpdates _lhsOoriginalTree ))
-sem_Statement_AlterSequence :: Annotation ->
-                               T_Name  ->
-                               T_Name  ->
-                               T_Statement 
-sem_Statement_AlterSequence ann_ name_ ownedBy_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _nameOcat :: Catalog
-              _nameOidenv :: IDEnv
-              _nameOlib :: LocalBindings
-              _ownedByOcat :: Catalog
-              _ownedByOidenv :: IDEnv
-              _ownedByOlib :: LocalBindings
-              _nameIannotatedTree :: Name 
-              _nameIfixedUpIdentifiersTree :: Name 
-              _nameIoriginalTree :: Name 
-              _nameItbAnnotatedTree :: Name 
-              _nameItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _ownedByIannotatedTree :: Name 
-              _ownedByIfixedUpIdentifiersTree :: Name 
-              _ownedByIoriginalTree :: Name 
-              _ownedByItbAnnotatedTree :: Name 
-              _ownedByItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  AlterSequence ann_ _nameIannotatedTree _ownedByIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  AlterSequence ann_ _nameIfixedUpIdentifiersTree _ownedByIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  AlterSequence ann_ _nameIoriginalTree _ownedByIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _nameOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _nameOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _nameOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _ownedByOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _ownedByOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _ownedByOlib =
-                  _lhsIlib
-              ( _nameIannotatedTree,_nameIfixedUpIdentifiersTree,_nameIoriginalTree,_nameItbAnnotatedTree,_nameItbUType) =
-                  name_ _nameOcat _nameOidenv _nameOlib 
-              ( _ownedByIannotatedTree,_ownedByIfixedUpIdentifiersTree,_ownedByIoriginalTree,_ownedByItbAnnotatedTree,_ownedByItbUType) =
-                  ownedBy_ _ownedByOcat _ownedByOidenv _ownedByOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_AlterTable :: Annotation ->
-                            T_Name  ->
-                            T_AlterTableActionList  ->
-                            T_Statement 
-sem_Statement_AlterTable ann_ name_ actions_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _nameOcat :: Catalog
-              _nameOidenv :: IDEnv
-              _nameOlib :: LocalBindings
-              _actionsOcat :: Catalog
-              _actionsOidenv :: IDEnv
-              _actionsOlib :: LocalBindings
-              _nameIannotatedTree :: Name 
-              _nameIfixedUpIdentifiersTree :: Name 
-              _nameIoriginalTree :: Name 
-              _nameItbAnnotatedTree :: Name 
-              _nameItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _actionsIannotatedTree :: AlterTableActionList 
-              _actionsIfixedUpIdentifiersTree :: AlterTableActionList 
-              _actionsIoriginalTree :: AlterTableActionList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  AlterTable ann_ _nameIannotatedTree _actionsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  AlterTable ann_ _nameIfixedUpIdentifiersTree _actionsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  AlterTable ann_ _nameIoriginalTree _actionsIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _nameOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _nameOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _nameOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _actionsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _actionsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _actionsOlib =
-                  _lhsIlib
-              ( _nameIannotatedTree,_nameIfixedUpIdentifiersTree,_nameIoriginalTree,_nameItbAnnotatedTree,_nameItbUType) =
-                  name_ _nameOcat _nameOidenv _nameOlib 
-              ( _actionsIannotatedTree,_actionsIfixedUpIdentifiersTree,_actionsIoriginalTree) =
-                  actions_ _actionsOcat _actionsOidenv _actionsOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_AntiStatement :: String ->
-                               T_Statement 
-sem_Statement_AntiStatement string_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  AntiStatement string_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  AntiStatement string_
-              -- self rule
-              _originalTree =
-                  AntiStatement string_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_Assignment :: Annotation ->
-                            T_Name  ->
-                            T_ScalarExpr  ->
-                            T_Statement 
-sem_Statement_Assignment ann_ target_ value_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: Statement 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _tpe :: (Either [TypeError] Type)
-              _catUpdates :: ([CatalogUpdate])
-              _statementType :: (Maybe ParameterizedStatementType)
-              _valueOexpectedType :: (Maybe Type)
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _targetOcat :: Catalog
-              _targetOidenv :: IDEnv
-              _targetOlib :: LocalBindings
-              _valueOcat :: Catalog
-              _valueOidenv :: IDEnv
-              _valueOlib :: LocalBindings
-              _targetIannotatedTree :: Name 
-              _targetIfixedUpIdentifiersTree :: Name 
-              _targetIoriginalTree :: Name 
-              _targetItbAnnotatedTree :: Name 
-              _targetItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _valueIannotatedTree :: ScalarExpr 
-              _valueIfixedUpIdentifiersTree :: ScalarExpr 
-              _valueIoriginalTree :: ScalarExpr 
-              _valueIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 82, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {stType = _statementType
-                               ,catUpd = _catUpdates    }) $
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 88, column 9)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 89, column 9)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Plpgsql.ag"(line 20, column 9)
-              _tpe =
-                  Left []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Plpgsql.ag"(line 27, column 9)
-              _backTree =
-                  Assignment ann_ _targetIannotatedTree _valueIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Plpgsql.ag"(line 28, column 9)
-              _catUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Plpgsql.ag"(line 29, column 9)
-              _statementType =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 109, column 18)
-              _valueOexpectedType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  Assignment ann_ _targetIannotatedTree _valueIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Assignment ann_ _targetIfixedUpIdentifiersTree _valueIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Assignment ann_ _targetIoriginalTree _valueIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _targetOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _targetOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _targetOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _valueOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _valueOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _valueOlib =
-                  _lhsIlib
-              ( _targetIannotatedTree,_targetIfixedUpIdentifiersTree,_targetIoriginalTree,_targetItbAnnotatedTree,_targetItbUType) =
-                  target_ _targetOcat _targetOidenv _targetOlib 
-              ( _valueIannotatedTree,_valueIfixedUpIdentifiersTree,_valueIoriginalTree,_valueIuType) =
-                  value_ _valueOcat _valueOexpectedType _valueOidenv _valueOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_Block :: Annotation ->
-                       (Maybe String) ->
-                       T_VarDefList  ->
-                       T_StatementList  ->
-                       T_Statement 
-sem_Statement_Block ann_ lb_ vars_ sts_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _stsOcatUpdates :: ([CatalogUpdate])
-              _stsOlib :: LocalBindings
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _varsOcat :: Catalog
-              _varsOidenv :: IDEnv
-              _varsOlib :: LocalBindings
-              _stsOcat :: Catalog
-              _stsOidenv :: IDEnv
-              _stsOlibUpdates :: ([LocalBindingsUpdate])
-              _varsIannotatedTree :: VarDefList 
-              _varsIdefs :: ([(String,Maybe Type)])
-              _varsIfixedUpIdentifiersTree :: VarDefList 
-              _varsIoriginalTree :: VarDefList 
-              _stsIannotatedTree :: StatementList 
-              _stsIfixedUpIdentifiersTree :: StatementList 
-              _stsIoriginalTree :: StatementList 
-              _stsIproducedCat :: Catalog
-              _stsIproducedLib :: LocalBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 100, column 13)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 101, column 13)
-              _stsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Block.ag"(line 22, column 9)
-              _stsOlib =
-                  fromRight _lhsIlib $
-                  lbUpdate _lhsIcat
-                           (LBIds "declarations" lb_ $ mapMaybe lv _varsIdefs)
-                           _lhsIlib
-                  where
-                    lv (_,Nothing) = Nothing
-                    lv (s,Just t) = Just (s,t)
-              -- self rule
-              _annotatedTree =
-                  Block ann_ lb_ _varsIannotatedTree _stsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Block ann_ lb_ _varsIfixedUpIdentifiersTree _stsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Block ann_ lb_ _varsIoriginalTree _stsIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (from local)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- copy rule (down)
-              _varsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _varsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _varsOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _stsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _stsOidenv =
-                  _lhsIidenv
-              -- copy rule (from local)
-              _stsOlibUpdates =
-                  _libUpdates
-              ( _varsIannotatedTree,_varsIdefs,_varsIfixedUpIdentifiersTree,_varsIoriginalTree) =
-                  vars_ _varsOcat _varsOidenv _varsOlib 
-              ( _stsIannotatedTree,_stsIfixedUpIdentifiersTree,_stsIoriginalTree,_stsIproducedCat,_stsIproducedLib) =
-                  sts_ _stsOcat _stsOcatUpdates _stsOidenv _stsOlib _stsOlibUpdates 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_CaseStatement :: Annotation ->
-                               T_ScalarExprListStatementListPairList  ->
-                               T_StatementList  ->
-                               T_Statement 
-sem_Statement_CaseStatement ann_ cases_ els_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _elsOcatUpdates :: ([CatalogUpdate])
-              _elsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _casesOcat :: Catalog
-              _casesOidenv :: IDEnv
-              _casesOlib :: LocalBindings
-              _elsOcat :: Catalog
-              _elsOidenv :: IDEnv
-              _elsOlib :: LocalBindings
-              _casesIannotatedTree :: ScalarExprListStatementListPairList 
-              _casesIfixedUpIdentifiersTree :: ScalarExprListStatementListPairList 
-              _casesIoriginalTree :: ScalarExprListStatementListPairList 
-              _elsIannotatedTree :: StatementList 
-              _elsIfixedUpIdentifiersTree :: StatementList 
-              _elsIoriginalTree :: StatementList 
-              _elsIproducedCat :: Catalog
-              _elsIproducedLib :: LocalBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 134, column 9)
-              _elsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 135, column 9)
-              _elsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  CaseStatement ann_ _casesIannotatedTree _elsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  CaseStatement ann_ _casesIfixedUpIdentifiersTree _elsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  CaseStatement ann_ _casesIoriginalTree _elsIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _casesOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _casesOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _casesOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _elsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _elsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _elsOlib =
-                  _lhsIlib
-              ( _casesIannotatedTree,_casesIfixedUpIdentifiersTree,_casesIoriginalTree) =
-                  cases_ _casesOcat _casesOidenv _casesOlib 
-              ( _elsIannotatedTree,_elsIfixedUpIdentifiersTree,_elsIoriginalTree,_elsIproducedCat,_elsIproducedLib) =
-                  els_ _elsOcat _elsOcatUpdates _elsOidenv _elsOlib _elsOlibUpdates 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_CaseStatementSimple :: Annotation ->
-                                     T_ScalarExpr  ->
-                                     T_ScalarExprListStatementListPairList  ->
-                                     T_StatementList  ->
-                                     T_Statement 
-sem_Statement_CaseStatementSimple ann_ val_ cases_ els_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _elsOcatUpdates :: ([CatalogUpdate])
-              _elsOlibUpdates :: ([LocalBindingsUpdate])
-              _valOexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _valOcat :: Catalog
-              _valOidenv :: IDEnv
-              _valOlib :: LocalBindings
-              _casesOcat :: Catalog
-              _casesOidenv :: IDEnv
-              _casesOlib :: LocalBindings
-              _elsOcat :: Catalog
-              _elsOidenv :: IDEnv
-              _elsOlib :: LocalBindings
-              _valIannotatedTree :: ScalarExpr 
-              _valIfixedUpIdentifiersTree :: ScalarExpr 
-              _valIoriginalTree :: ScalarExpr 
-              _valIuType :: (Maybe Type)
-              _casesIannotatedTree :: ScalarExprListStatementListPairList 
-              _casesIfixedUpIdentifiersTree :: ScalarExprListStatementListPairList 
-              _casesIoriginalTree :: ScalarExprListStatementListPairList 
-              _elsIannotatedTree :: StatementList 
-              _elsIfixedUpIdentifiersTree :: StatementList 
-              _elsIoriginalTree :: StatementList 
-              _elsIproducedCat :: Catalog
-              _elsIproducedLib :: LocalBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 134, column 9)
-              _elsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 135, column 9)
-              _elsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 110, column 27)
-              _valOexpectedType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  CaseStatementSimple ann_ _valIannotatedTree _casesIannotatedTree _elsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  CaseStatementSimple ann_ _valIfixedUpIdentifiersTree _casesIfixedUpIdentifiersTree _elsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  CaseStatementSimple ann_ _valIoriginalTree _casesIoriginalTree _elsIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _valOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _valOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _valOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _casesOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _casesOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _casesOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _elsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _elsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _elsOlib =
-                  _lhsIlib
-              ( _valIannotatedTree,_valIfixedUpIdentifiersTree,_valIoriginalTree,_valIuType) =
-                  val_ _valOcat _valOexpectedType _valOidenv _valOlib 
-              ( _casesIannotatedTree,_casesIfixedUpIdentifiersTree,_casesIoriginalTree) =
-                  cases_ _casesOcat _casesOidenv _casesOlib 
-              ( _elsIannotatedTree,_elsIfixedUpIdentifiersTree,_elsIoriginalTree,_elsIproducedCat,_elsIproducedLib) =
-                  els_ _elsOcat _elsOcatUpdates _elsOidenv _elsOlib _elsOlibUpdates 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_ContinueStatement :: Annotation ->
-                                   (Maybe String) ->
-                                   T_Statement 
-sem_Statement_ContinueStatement ann_ lb_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  ContinueStatement ann_ lb_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  ContinueStatement ann_ lb_
-              -- self rule
-              _originalTree =
-                  ContinueStatement ann_ lb_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_Copy :: Annotation ->
-                      T_Name  ->
-                      ([NameComponent]) ->
-                      CopySource ->
-                      T_Statement 
-sem_Statement_Copy ann_ table_ targetCols_ source_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _tableOcat :: Catalog
-              _tableOidenv :: IDEnv
-              _tableOlib :: LocalBindings
-              _tableIannotatedTree :: Name 
-              _tableIfixedUpIdentifiersTree :: Name 
-              _tableIoriginalTree :: Name 
-              _tableItbAnnotatedTree :: Name 
-              _tableItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  Copy ann_ _tableIannotatedTree targetCols_ source_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Copy ann_ _tableIfixedUpIdentifiersTree targetCols_ source_
-              -- self rule
-              _originalTree =
-                  Copy ann_ _tableIoriginalTree targetCols_ source_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _tableOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tableOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tableOlib =
-                  _lhsIlib
-              ( _tableIannotatedTree,_tableIfixedUpIdentifiersTree,_tableIoriginalTree,_tableItbAnnotatedTree,_tableItbUType) =
-                  table_ _tableOcat _tableOidenv _tableOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_CopyData :: Annotation ->
-                          String ->
-                          T_Statement 
-sem_Statement_CopyData ann_ insData_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  CopyData ann_ insData_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  CopyData ann_ insData_
-              -- self rule
-              _originalTree =
-                  CopyData ann_ insData_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_CreateDomain :: Annotation ->
-                              T_Name  ->
-                              T_TypeName  ->
-                              String ->
-                              T_MaybeBoolExpr  ->
-                              T_Statement 
-sem_Statement_CreateDomain ann_ name_ typ_ constraintName_ check_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: Statement 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _tpe :: (Either [TypeError] Type)
-              _statementType :: (Maybe ParameterizedStatementType)
-              _catUpdates :: ([CatalogUpdate])
-              _checkOlib :: LocalBindings
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _nameOcat :: Catalog
-              _nameOidenv :: IDEnv
-              _nameOlib :: LocalBindings
-              _typOcat :: Catalog
-              _typOidenv :: IDEnv
-              _typOlib :: LocalBindings
-              _checkOcat :: Catalog
-              _checkOidenv :: IDEnv
-              _nameIannotatedTree :: Name 
-              _nameIfixedUpIdentifiersTree :: Name 
-              _nameIoriginalTree :: Name 
-              _nameItbAnnotatedTree :: Name 
-              _nameItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _typIannotatedTree :: TypeName 
-              _typIfixedUpIdentifiersTree :: TypeName 
-              _typInamedType :: (Maybe Type)
-              _typIoriginalTree :: TypeName 
-              _checkIannotatedTree :: MaybeBoolExpr 
-              _checkIfixedUpIdentifiersTree :: MaybeBoolExpr 
-              _checkIoriginalTree :: MaybeBoolExpr 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 82, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {stType = _statementType
-                               ,catUpd = _catUpdates    }) $
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 88, column 9)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 89, column 9)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 65, column 9)
-              _tpe =
-                  Right $ Pseudo Void
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 66, column 9)
-              _backTree =
-                  CreateDomain ann_ _nameIoriginalTree _typIannotatedTree constraintName_ _checkIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 67, column 9)
-              _statementType =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 68, column 9)
-              _catUpdates =
-                  maybe [] (\t -> [CatCreateDomain (DomainType (getTName _nameIoriginalTree)) t]) _typInamedType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 70, column 9)
-              _checkOlib =
-                  either (const _lhsIlib) id $ do
-                  nt <- lmt _typInamedType
-                  lbUpdate _lhsIcat
-                    (LBIds "domain check value" Nothing [("value", nt)])
-                    _lhsIlib
-              -- self rule
-              _annotatedTree =
-                  CreateDomain ann_ _nameIannotatedTree _typIannotatedTree constraintName_ _checkIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  CreateDomain ann_ _nameIfixedUpIdentifiersTree _typIfixedUpIdentifiersTree constraintName_ _checkIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  CreateDomain ann_ _nameIoriginalTree _typIoriginalTree constraintName_ _checkIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _nameOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _nameOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _nameOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _typOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _typOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _typOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _checkOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _checkOidenv =
-                  _lhsIidenv
-              ( _nameIannotatedTree,_nameIfixedUpIdentifiersTree,_nameIoriginalTree,_nameItbAnnotatedTree,_nameItbUType) =
-                  name_ _nameOcat _nameOidenv _nameOlib 
-              ( _typIannotatedTree,_typIfixedUpIdentifiersTree,_typInamedType,_typIoriginalTree) =
-                  typ_ _typOcat _typOidenv _typOlib 
-              ( _checkIannotatedTree,_checkIfixedUpIdentifiersTree,_checkIoriginalTree) =
-                  check_ _checkOcat _checkOidenv _checkOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_CreateFunction :: Annotation ->
-                                T_Name  ->
-                                T_ParamDefList  ->
-                                T_TypeName  ->
-                                Replace ->
-                                Language ->
-                                T_FnBody  ->
-                                Volatility ->
-                                T_Statement 
-sem_Statement_CreateFunction ann_ name_ params_ rettype_ rep_ lang_ body_ vol_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: Statement 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _bodyOlib :: LocalBindings
-              _paramsOpos :: Int
-              _tpe :: (Either [TypeError] Type)
-              _catUpdates :: ([CatalogUpdate])
-              _statementType :: (Maybe ParameterizedStatementType)
-              _bodyOcat :: Catalog
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _nameOcat :: Catalog
-              _nameOidenv :: IDEnv
-              _nameOlib :: LocalBindings
-              _paramsOcat :: Catalog
-              _paramsOidenv :: IDEnv
-              _paramsOlib :: LocalBindings
-              _rettypeOcat :: Catalog
-              _rettypeOidenv :: IDEnv
-              _rettypeOlib :: LocalBindings
-              _bodyOidenv :: IDEnv
-              _nameIannotatedTree :: Name 
-              _nameIfixedUpIdentifiersTree :: Name 
-              _nameIoriginalTree :: Name 
-              _nameItbAnnotatedTree :: Name 
-              _nameItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _paramsIannotatedTree :: ParamDefList 
-              _paramsIfixedUpIdentifiersTree :: ParamDefList 
-              _paramsIoriginalTree :: ParamDefList 
-              _paramsIparams :: ([(ParamName, Maybe Type)])
-              _rettypeIannotatedTree :: TypeName 
-              _rettypeIfixedUpIdentifiersTree :: TypeName 
-              _rettypeInamedType :: (Maybe Type)
-              _rettypeIoriginalTree :: TypeName 
-              _bodyIannotatedTree :: FnBody 
-              _bodyIfixedUpIdentifiersTree :: FnBody 
-              _bodyIoriginalTree :: FnBody 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 82, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {stType = _statementType
-                               ,catUpd = _catUpdates    }) $
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 88, column 9)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 89, column 9)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateFunction.ag"(line 63, column 9)
-              _bodyOlib =
-                  either (const _lhsIlib) id $ do
-                  _ <- lmt _rettypeInamedType
-                  lbUpdate _lhsIcat (LBIds ((getTName _nameIoriginalTree) ++ " parameters") (Just (getTName _nameIoriginalTree)) paramsNoPos) _lhsIlib
-                  >>= lbUpdate _lhsIcat (LBIds ((getTName _nameIoriginalTree) ++ " parameters") Nothing paramsPosOnly)
-                  where
-                    paramsPosOnly :: [(String,Type)]
-                    paramsPosOnly = mapMaybe prm _paramsIparams
-                    prm :: (ParamName,Maybe Type) -> Maybe (String,Type)
-                    prm (NamedParam p _,Just t) = Just ("$" ++ show p, t)
-                    prm (UnnamedParam p,Just t) = Just ("$" ++ show p, t)
-                    prm _ = Nothing
-                    paramsNoPos :: [(String,Type)]
-                    paramsNoPos = mapMaybe pnp _paramsIparams
-                    pnp :: (ParamName,Maybe Type) -> Maybe (String,Type)
-                    pnp (NamedParam _ n,Just t) = Just (n,t)
-                    pnp _ = Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateFunction.ag"(line 79, column 9)
-              _paramsOpos =
-                  1
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateFunction.ag"(line 88, column 9)
-              _tpe =
-                  Right $ Pseudo Void
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateFunction.ag"(line 89, column 9)
-              _catUpdates =
-                  either (const []) id $ do
-                  let ps = mapMaybe lpt _paramsIparams
-                  rt <- lmt _rettypeInamedType
-                  return [CatCreateFunction FunName
-                                            (map toLower (getTName _nameIoriginalTree))
-                                            ps
-                                            rt
-                                            False]
-                  where
-                    lpt (_,Just t) = Just t
-                    lpt _ = Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateFunction.ag"(line 101, column 9)
-              _backTree =
-                  CreateFunction ann_
-                                 _nameIoriginalTree
-                                 _paramsIannotatedTree
-                                 _rettypeIannotatedTree
-                                 rep_
-                                 lang_
-                                 _bodyIannotatedTree
-                                 vol_
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateFunction.ag"(line 109, column 9)
-              _statementType =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateFunction.ag"(line 110, column 9)
-              _bodyOcat =
-                  _lhsIinProducedCat
-              -- self rule
-              _annotatedTree =
-                  CreateFunction ann_ _nameIannotatedTree _paramsIannotatedTree _rettypeIannotatedTree rep_ lang_ _bodyIannotatedTree vol_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  CreateFunction ann_ _nameIfixedUpIdentifiersTree _paramsIfixedUpIdentifiersTree _rettypeIfixedUpIdentifiersTree rep_ lang_ _bodyIfixedUpIdentifiersTree vol_
-              -- self rule
-              _originalTree =
-                  CreateFunction ann_ _nameIoriginalTree _paramsIoriginalTree _rettypeIoriginalTree rep_ lang_ _bodyIoriginalTree vol_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _nameOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _nameOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _nameOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _paramsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _paramsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _paramsOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _rettypeOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _rettypeOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _rettypeOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _bodyOidenv =
-                  _lhsIidenv
-              ( _nameIannotatedTree,_nameIfixedUpIdentifiersTree,_nameIoriginalTree,_nameItbAnnotatedTree,_nameItbUType) =
-                  name_ _nameOcat _nameOidenv _nameOlib 
-              ( _paramsIannotatedTree,_paramsIfixedUpIdentifiersTree,_paramsIoriginalTree,_paramsIparams) =
-                  params_ _paramsOcat _paramsOidenv _paramsOlib _paramsOpos 
-              ( _rettypeIannotatedTree,_rettypeIfixedUpIdentifiersTree,_rettypeInamedType,_rettypeIoriginalTree) =
-                  rettype_ _rettypeOcat _rettypeOidenv _rettypeOlib 
-              ( _bodyIannotatedTree,_bodyIfixedUpIdentifiersTree,_bodyIoriginalTree) =
-                  body_ _bodyOcat _bodyOidenv _bodyOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_CreateLanguage :: Annotation ->
-                                String ->
-                                T_Statement 
-sem_Statement_CreateLanguage ann_ name_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: Statement 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _tpe :: (Either [TypeError] Type)
-              _statementType :: (Maybe ParameterizedStatementType)
-              _catUpdates :: ([CatalogUpdate])
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 82, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {stType = _statementType
-                               ,catUpd = _catUpdates    }) $
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 88, column 9)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 89, column 9)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 78, column 9)
-              _tpe =
-                  Right $ Pseudo Void
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 79, column 9)
-              _backTree =
-                  CreateLanguage ann_ name_
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 80, column 9)
-              _statementType =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 81, column 9)
-              _catUpdates =
-                  [CatCreateFunction FunName "plpgsql_call_handler" [] (Pseudo LanguageHandler) False
-                  ,CatCreateFunction FunName "plpgsql_validator" [ScalarType "oid"] (Pseudo Void) False]
-              -- self rule
-              _annotatedTree =
-                  CreateLanguage ann_ name_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  CreateLanguage ann_ name_
-              -- self rule
-              _originalTree =
-                  CreateLanguage ann_ name_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_CreateSequence :: Annotation ->
-                                T_Name  ->
-                                Integer ->
-                                Integer ->
-                                Integer ->
-                                Integer ->
-                                Integer ->
-                                T_Statement 
-sem_Statement_CreateSequence ann_ name_ incr_ min_ max_ start_ cache_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _nameOcat :: Catalog
-              _nameOidenv :: IDEnv
-              _nameOlib :: LocalBindings
-              _nameIannotatedTree :: Name 
-              _nameIfixedUpIdentifiersTree :: Name 
-              _nameIoriginalTree :: Name 
-              _nameItbAnnotatedTree :: Name 
-              _nameItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  CreateSequence ann_ _nameIannotatedTree incr_ min_ max_ start_ cache_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  CreateSequence ann_ _nameIfixedUpIdentifiersTree incr_ min_ max_ start_ cache_
-              -- self rule
-              _originalTree =
-                  CreateSequence ann_ _nameIoriginalTree incr_ min_ max_ start_ cache_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _nameOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _nameOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _nameOlib =
-                  _lhsIlib
-              ( _nameIannotatedTree,_nameIfixedUpIdentifiersTree,_nameIoriginalTree,_nameItbAnnotatedTree,_nameItbUType) =
-                  name_ _nameOcat _nameOidenv _nameOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_CreateTable :: Annotation ->
-                             T_Name  ->
-                             T_AttributeDefList  ->
-                             T_ConstraintList  ->
-                             T_Statement 
-sem_Statement_CreateTable ann_ name_ atts_ cons_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: Statement 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _tpe :: (Either [TypeError] Type)
-              _catUpdates :: ([CatalogUpdate])
-              _attrs :: ([(String,Type)])
-              _statementType :: (Maybe ParameterizedStatementType)
-              _consOlib :: LocalBindings
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _nameOcat :: Catalog
-              _nameOidenv :: IDEnv
-              _nameOlib :: LocalBindings
-              _attsOcat :: Catalog
-              _attsOidenv :: IDEnv
-              _attsOlib :: LocalBindings
-              _consOcat :: Catalog
-              _consOidenv :: IDEnv
-              _nameIannotatedTree :: Name 
-              _nameIfixedUpIdentifiersTree :: Name 
-              _nameIoriginalTree :: Name 
-              _nameItbAnnotatedTree :: Name 
-              _nameItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _attsIannotatedTree :: AttributeDefList 
-              _attsIattrs :: ([(String, Maybe Type)])
-              _attsIfixedUpIdentifiersTree :: AttributeDefList 
-              _attsIoriginalTree :: AttributeDefList 
-              _consIannotatedTree :: ConstraintList 
-              _consIfixedUpIdentifiersTree :: ConstraintList 
-              _consIoriginalTree :: ConstraintList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 82, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {stType = _statementType
-                               ,catUpd = _catUpdates    }) $
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 88, column 9)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 89, column 9)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateTable.ag"(line 31, column 9)
-              _tpe =
-                  Right $ Pseudo Void
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateTable.ag"(line 32, column 9)
-              _catUpdates =
-                  [CatCreateTable (getTName _nameIoriginalTree) _attrs     defaultSystemColumns]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateTable.ag"(line 35, column 9)
-              _attrs =
-                  mapMaybe okAt _attsIattrs
-                  where
-                    okAt (s, Just t) = Just (s,t)
-                    okAt (_,Nothing) = Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateTable.ag"(line 40, column 9)
-              _statementType =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateTable.ag"(line 41, column 9)
-              _backTree =
-                  CreateTable ann_
-                              _nameIoriginalTree
-                              _attsIannotatedTree
-                              _consIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateTable.ag"(line 45, column 9)
-              _consOlib =
-                  case lbUpdate _lhsIcat
-                         (LBIds "attributedefs" Nothing _attrs    )
-                         _lhsIlib of
-                     Left x -> error $ "statement-createtable-cons.lib " ++ show x
-                     Right e -> e
-              -- self rule
-              _annotatedTree =
-                  CreateTable ann_ _nameIannotatedTree _attsIannotatedTree _consIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  CreateTable ann_ _nameIfixedUpIdentifiersTree _attsIfixedUpIdentifiersTree _consIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  CreateTable ann_ _nameIoriginalTree _attsIoriginalTree _consIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _nameOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _nameOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _nameOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _attsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _attsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _attsOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _consOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _consOidenv =
-                  _lhsIidenv
-              ( _nameIannotatedTree,_nameIfixedUpIdentifiersTree,_nameIoriginalTree,_nameItbAnnotatedTree,_nameItbUType) =
-                  name_ _nameOcat _nameOidenv _nameOlib 
-              ( _attsIannotatedTree,_attsIattrs,_attsIfixedUpIdentifiersTree,_attsIoriginalTree) =
-                  atts_ _attsOcat _attsOidenv _attsOlib 
-              ( _consIannotatedTree,_consIfixedUpIdentifiersTree,_consIoriginalTree) =
-                  cons_ _consOcat _consOidenv _consOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_CreateTableAs :: Annotation ->
-                               T_Name  ->
-                               T_QueryExpr  ->
-                               T_Statement 
-sem_Statement_CreateTableAs ann_ name_ expr_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: Statement 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _exprOcsql :: LocalBindings
-              _tpe :: (Either [TypeError] Type)
-              _catUpdates :: ([CatalogUpdate])
-              _attrs :: (Either [TypeError] [(String,Type)])
-              _statementType :: (Maybe ParameterizedStatementType)
-              _exprOexpectedTypes :: ([Maybe Type])
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _nameOcat :: Catalog
-              _nameOidenv :: IDEnv
-              _nameOlib :: LocalBindings
-              _exprOcat :: Catalog
-              _exprOidenv :: IDEnv
-              _exprOlib :: LocalBindings
-              _nameIannotatedTree :: Name 
-              _nameIfixedUpIdentifiersTree :: Name 
-              _nameIoriginalTree :: Name 
-              _nameItbAnnotatedTree :: Name 
-              _nameItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _exprIannotatedTree :: QueryExpr 
-              _exprIcidenv :: IDEnv
-              _exprIfixedUpIdentifiersTree :: QueryExpr 
-              _exprIlibUpdates :: ([LocalBindingsUpdate])
-              _exprIoriginalTree :: QueryExpr 
-              _exprIuType :: (Maybe [(String,Type)])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 82, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {stType = _statementType
-                               ,catUpd = _catUpdates    }) $
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 88, column 9)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 89, column 9)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 122, column 21)
-              _exprOcsql =
-                  emptyBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateTable.ag"(line 64, column 9)
-              _tpe =
-                  CompositeType <$> lmt _exprIuType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateTable.ag"(line 65, column 9)
-              _catUpdates =
-                  either (const []) id $ do
-                  ats <- _attrs
-                  return [CatCreateTable (getTName _nameIoriginalTree) ats defaultSystemColumns]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateTable.ag"(line 71, column 9)
-              _attrs =
-                  lmt _exprIuType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateTable.ag"(line 73, column 9)
-              _backTree =
-                  CreateTableAs ann_ _nameIoriginalTree _exprIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/CreateTable.ag"(line 74, column 9)
-              _statementType =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 173, column 32)
-              _exprOexpectedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  CreateTableAs ann_ _nameIannotatedTree _exprIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  CreateTableAs ann_ _nameIfixedUpIdentifiersTree _exprIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  CreateTableAs ann_ _nameIoriginalTree _exprIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _nameOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _nameOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _nameOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _exprOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exprOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exprOlib =
-                  _lhsIlib
-              ( _nameIannotatedTree,_nameIfixedUpIdentifiersTree,_nameIoriginalTree,_nameItbAnnotatedTree,_nameItbUType) =
-                  name_ _nameOcat _nameOidenv _nameOlib 
-              ( _exprIannotatedTree,_exprIcidenv,_exprIfixedUpIdentifiersTree,_exprIlibUpdates,_exprIoriginalTree,_exprIuType) =
-                  expr_ _exprOcat _exprOcsql _exprOexpectedTypes _exprOidenv _exprOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_CreateTrigger :: Annotation ->
-                               NameComponent ->
-                               TriggerWhen ->
-                               ([TriggerEvent]) ->
-                               T_Name  ->
-                               TriggerFire ->
-                               T_Name  ->
-                               T_ScalarExprList  ->
-                               T_Statement 
-sem_Statement_CreateTrigger ann_ name_ wh_ events_ tbl_ firing_ fnName_ fnArgs_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _fnArgsOexpectedTypes :: ([Maybe Type])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _tblOcat :: Catalog
-              _tblOidenv :: IDEnv
-              _tblOlib :: LocalBindings
-              _fnNameOcat :: Catalog
-              _fnNameOidenv :: IDEnv
-              _fnNameOlib :: LocalBindings
-              _fnArgsOcat :: Catalog
-              _fnArgsOidenv :: IDEnv
-              _fnArgsOlib :: LocalBindings
-              _tblIannotatedTree :: Name 
-              _tblIfixedUpIdentifiersTree :: Name 
-              _tblIoriginalTree :: Name 
-              _tblItbAnnotatedTree :: Name 
-              _tblItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _fnNameIannotatedTree :: Name 
-              _fnNameIfixedUpIdentifiersTree :: Name 
-              _fnNameIoriginalTree :: Name 
-              _fnNameItbAnnotatedTree :: Name 
-              _fnNameItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _fnArgsIannotatedTree :: ScalarExprList 
-              _fnArgsIfixedUpIdentifiersTree :: ScalarExprList 
-              _fnArgsIoriginalTree :: ScalarExprList 
-              _fnArgsIuType :: ([Maybe Type])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 151, column 21)
-              _fnArgsOexpectedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  CreateTrigger ann_ name_ wh_ events_ _tblIannotatedTree firing_ _fnNameIannotatedTree _fnArgsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  CreateTrigger ann_ name_ wh_ events_ _tblIfixedUpIdentifiersTree firing_ _fnNameIfixedUpIdentifiersTree _fnArgsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  CreateTrigger ann_ name_ wh_ events_ _tblIoriginalTree firing_ _fnNameIoriginalTree _fnArgsIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _tblOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tblOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tblOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _fnNameOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _fnNameOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _fnNameOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _fnArgsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _fnArgsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _fnArgsOlib =
-                  _lhsIlib
-              ( _tblIannotatedTree,_tblIfixedUpIdentifiersTree,_tblIoriginalTree,_tblItbAnnotatedTree,_tblItbUType) =
-                  tbl_ _tblOcat _tblOidenv _tblOlib 
-              ( _fnNameIannotatedTree,_fnNameIfixedUpIdentifiersTree,_fnNameIoriginalTree,_fnNameItbAnnotatedTree,_fnNameItbUType) =
-                  fnName_ _fnNameOcat _fnNameOidenv _fnNameOlib 
-              ( _fnArgsIannotatedTree,_fnArgsIfixedUpIdentifiersTree,_fnArgsIoriginalTree,_fnArgsIuType) =
-                  fnArgs_ _fnArgsOcat _fnArgsOexpectedTypes _fnArgsOidenv _fnArgsOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_CreateType :: Annotation ->
-                            T_Name  ->
-                            T_TypeAttributeDefList  ->
-                            T_Statement 
-sem_Statement_CreateType ann_ name_ atts_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: Statement 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _tpe :: (Either [TypeError] Type)
-              _statementType :: (Maybe ParameterizedStatementType)
-              _catUpdates :: ([CatalogUpdate])
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _nameOcat :: Catalog
-              _nameOidenv :: IDEnv
-              _nameOlib :: LocalBindings
-              _attsOcat :: Catalog
-              _attsOidenv :: IDEnv
-              _attsOlib :: LocalBindings
-              _nameIannotatedTree :: Name 
-              _nameIfixedUpIdentifiersTree :: Name 
-              _nameIoriginalTree :: Name 
-              _nameItbAnnotatedTree :: Name 
-              _nameItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _attsIannotatedTree :: TypeAttributeDefList 
-              _attsIattrs :: ([(String, Maybe Type)])
-              _attsIfixedUpIdentifiersTree :: TypeAttributeDefList 
-              _attsIoriginalTree :: TypeAttributeDefList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 82, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {stType = _statementType
-                               ,catUpd = _catUpdates    }) $
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 88, column 9)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 89, column 9)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 48, column 9)
-              _tpe =
-                  Right $ Pseudo Void
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 49, column 9)
-              _attrs =
-                  mapMaybe okAt _attsIattrs
-                  where
-                    okAt (s, Just t) = Just (s,t)
-                    okAt (_,Nothing) = Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 53, column 9)
-              _backTree =
-                  CreateType ann_ _nameIoriginalTree _attsIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 54, column 9)
-              _statementType =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 55, column 9)
-              _catUpdates =
-                  [CatCreateComposite (getTName _nameIoriginalTree) _attrs    ]
-              -- self rule
-              _annotatedTree =
-                  CreateType ann_ _nameIannotatedTree _attsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  CreateType ann_ _nameIfixedUpIdentifiersTree _attsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  CreateType ann_ _nameIoriginalTree _attsIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _nameOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _nameOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _nameOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _attsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _attsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _attsOlib =
-                  _lhsIlib
-              ( _nameIannotatedTree,_nameIfixedUpIdentifiersTree,_nameIoriginalTree,_nameItbAnnotatedTree,_nameItbUType) =
-                  name_ _nameOcat _nameOidenv _nameOlib 
-              ( _attsIannotatedTree,_attsIattrs,_attsIfixedUpIdentifiersTree,_attsIoriginalTree) =
-                  atts_ _attsOcat _attsOidenv _attsOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_CreateView :: Annotation ->
-                            T_Name  ->
-                            MaybeNameComponentList ->
-                            T_QueryExpr  ->
-                            T_Statement 
-sem_Statement_CreateView ann_ name_ colNames_ expr_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: Statement 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _exprOcsql :: LocalBindings
-              _tpe :: (Either [TypeError] Type)
-              _catUpdates :: ([CatalogUpdate])
-              _statementType :: (Maybe ParameterizedStatementType)
-              _exprOexpectedTypes :: ([Maybe Type])
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _nameOcat :: Catalog
-              _nameOidenv :: IDEnv
-              _nameOlib :: LocalBindings
-              _exprOcat :: Catalog
-              _exprOidenv :: IDEnv
-              _exprOlib :: LocalBindings
-              _nameIannotatedTree :: Name 
-              _nameIfixedUpIdentifiersTree :: Name 
-              _nameIoriginalTree :: Name 
-              _nameItbAnnotatedTree :: Name 
-              _nameItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _exprIannotatedTree :: QueryExpr 
-              _exprIcidenv :: IDEnv
-              _exprIfixedUpIdentifiersTree :: QueryExpr 
-              _exprIlibUpdates :: ([LocalBindingsUpdate])
-              _exprIoriginalTree :: QueryExpr 
-              _exprIuType :: (Maybe [(String,Type)])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 82, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {stType = _statementType
-                               ,catUpd = _catUpdates    }) $
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 88, column 9)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 89, column 9)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 123, column 18)
-              _exprOcsql =
-                  emptyBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 15, column 9)
-              _tpe =
-                  Right $ Pseudo Void
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 16, column 9)
-              _backTree =
-                  CreateView ann_ _nameIoriginalTree colNames_ _exprIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 17, column 9)
-              _catUpdates =
-                  maybe [] (\a -> [CatCreateView (getTName _nameIoriginalTree) a]) _exprIuType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 19, column 9)
-              _statementType =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 173, column 32)
-              _exprOexpectedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  CreateView ann_ _nameIannotatedTree colNames_ _exprIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  CreateView ann_ _nameIfixedUpIdentifiersTree colNames_ _exprIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  CreateView ann_ _nameIoriginalTree colNames_ _exprIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _nameOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _nameOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _nameOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _exprOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exprOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exprOlib =
-                  _lhsIlib
-              ( _nameIannotatedTree,_nameIfixedUpIdentifiersTree,_nameIoriginalTree,_nameItbAnnotatedTree,_nameItbUType) =
-                  name_ _nameOcat _nameOidenv _nameOlib 
-              ( _exprIannotatedTree,_exprIcidenv,_exprIfixedUpIdentifiersTree,_exprIlibUpdates,_exprIoriginalTree,_exprIuType) =
-                  expr_ _exprOcat _exprOcsql _exprOexpectedTypes _exprOidenv _exprOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_Delete :: Annotation ->
-                        T_Name  ->
-                        T_TableRefList  ->
-                        T_MaybeBoolExpr  ->
-                        T_MaybeSelectList  ->
-                        T_Statement 
-sem_Statement_Delete ann_ table_ using_ whr_ returning_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _whrOidenv :: IDEnv
-              _returningOidenv :: IDEnv
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOannotatedTree :: Statement 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _tpe :: (Either [TypeError] Type)
-              _statementType :: (Maybe ParameterizedStatementType)
-              _catUpdates :: ([CatalogUpdate])
-              _whrOlib :: LocalBindings
-              _returningOlib :: LocalBindings
-              _lhsOoriginalTree :: Statement 
-              _tableOcat :: Catalog
-              _tableOidenv :: IDEnv
-              _tableOlib :: LocalBindings
-              _usingOcat :: Catalog
-              _usingOidenv :: IDEnv
-              _usingOlib :: LocalBindings
-              _whrOcat :: Catalog
-              _returningOcat :: Catalog
-              _tableIannotatedTree :: Name 
-              _tableIfixedUpIdentifiersTree :: Name 
-              _tableIoriginalTree :: Name 
-              _tableItbAnnotatedTree :: Name 
-              _tableItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _usingIannotatedTree :: TableRefList 
-              _usingIfixedUpIdentifiersTree :: TableRefList 
-              _usingIlibUpdates :: ([LocalBindingsUpdate])
-              _usingInewLib2 :: LocalBindings
-              _usingIoriginalTree :: TableRefList 
-              _usingItrefIDs :: IDEnv
-              _whrIannotatedTree :: MaybeBoolExpr 
-              _whrIfixedUpIdentifiersTree :: MaybeBoolExpr 
-              _whrIoriginalTree :: MaybeBoolExpr 
-              _returningIannotatedTree :: MaybeSelectList 
-              _returningIfixedUpIdentifiersTree :: MaybeSelectList 
-              _returningIlistType :: ([(String,Maybe Type)])
-              _returningIoriginalTree :: MaybeSelectList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 555, column 9)
-              _trefEnv =
-                  getTableTrefEnv _lhsIcat _tableIoriginalTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 556, column 9)
-              _whrOidenv =
-                  _trefEnv
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 557, column 9)
-              _returningOidenv =
-                  _trefEnv
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 558, column 9)
-              _lhsOfixedUpIdentifiersTree =
-                  Delete ann_
-                         _tableIfixedUpIdentifiersTree
-                         _usingIfixedUpIdentifiersTree
-                         _whrIfixedUpIdentifiersTree
-                         _returningIfixedUpIdentifiersTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 82, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {stType = _statementType
-                               ,catUpd = _catUpdates    }) $
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 88, column 9)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 89, column 9)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Delete.ag"(line 13, column 9)
-              _tpe =
-                  Right $ Pseudo Void
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Delete.ag"(line 14, column 9)
-              _statementType =
-                  do
-                  pt <- sequence $ getPlaceholderTypes _whrIannotatedTree
-                  lt <- liftList _returningIlistType
-                  return (pt,lt)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Delete.ag"(line 19, column 9)
-              _backTree =
-                  Delete ann_ _tableItbAnnotatedTree _usingIannotatedTree _whrIannotatedTree _returningIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Delete.ag"(line 20, column 9)
-              _catUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Delete.ag"(line 22, column 9)
-              _lib =
-                  either (const _lhsIlib) id $ do
-                     makeTrefLib _lhsIcat _tableIannotatedTree _tableItbUType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Delete.ag"(line 25, column 9)
-              _whrOlib =
-                  _lib
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Delete.ag"(line 26, column 9)
-              _returningOlib =
-                  _lib
-              -- self rule
-              _annotatedTree =
-                  Delete ann_ _tableIannotatedTree _usingIannotatedTree _whrIannotatedTree _returningIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Delete ann_ _tableIfixedUpIdentifiersTree _usingIfixedUpIdentifiersTree _whrIfixedUpIdentifiersTree _returningIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Delete ann_ _tableIoriginalTree _usingIoriginalTree _whrIoriginalTree _returningIoriginalTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _tableOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tableOidenv =
-                  _lhsIidenv
-              -- copy rule (from local)
-              _tableOlib =
-                  _lib
-              -- copy rule (down)
-              _usingOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _usingOidenv =
-                  _lhsIidenv
-              -- copy rule (from local)
-              _usingOlib =
-                  _lib
-              -- copy rule (down)
-              _whrOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _returningOcat =
-                  _lhsIcat
-              ( _tableIannotatedTree,_tableIfixedUpIdentifiersTree,_tableIoriginalTree,_tableItbAnnotatedTree,_tableItbUType) =
-                  table_ _tableOcat _tableOidenv _tableOlib 
-              ( _usingIannotatedTree,_usingIfixedUpIdentifiersTree,_usingIlibUpdates,_usingInewLib2,_usingIoriginalTree,_usingItrefIDs) =
-                  using_ _usingOcat _usingOidenv _usingOlib 
-              ( _whrIannotatedTree,_whrIfixedUpIdentifiersTree,_whrIoriginalTree) =
-                  whr_ _whrOcat _whrOidenv _whrOlib 
-              ( _returningIannotatedTree,_returningIfixedUpIdentifiersTree,_returningIlistType,_returningIoriginalTree) =
-                  returning_ _returningOcat _returningOidenv _returningOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_DropFunction :: Annotation ->
-                              IfExists ->
-                              T_NameTypeNameListPairList  ->
-                              Cascade ->
-                              T_Statement 
-sem_Statement_DropFunction ann_ ifE_ sigs_ cascade_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: Statement 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _tpe :: (Either [TypeError] Type)
-              _catUpdates :: ([CatalogUpdate])
-              _statementType :: (Maybe ParameterizedStatementType)
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _sigsOcat :: Catalog
-              _sigsOidenv :: IDEnv
-              _sigsOlib :: LocalBindings
-              _sigsIannotatedTree :: NameTypeNameListPairList 
-              _sigsIfixedUpIdentifiersTree :: NameTypeNameListPairList 
-              _sigsIfnSigs :: ([(Name,[Maybe Type])])
-              _sigsIoriginalTree :: NameTypeNameListPairList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 82, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {stType = _statementType
-                               ,catUpd = _catUpdates    }) $
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 88, column 9)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 89, column 9)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/Drops.ag"(line 10, column 9)
-              _tpe =
-                  Right $ Pseudo Void
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/Drops.ag"(line 11, column 9)
-              _backTree =
-                  DropFunction ann_ ifE_ _sigsIannotatedTree cascade_
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/Drops.ag"(line 12, column 9)
-              _catUpdates =
-                  either (const []) id $
-                  Right $ map mcu $ mapMaybe goodSig _sigsIfnSigs
-                  where
-                    mcu :: (String,[Type]) -> CatalogUpdate
-                    mcu (nm,args) = CatDropFunction ifE nm args
-                    ifE = ifE_ == IfExists
-                    goodSig :: (Name,[Maybe Type]) -> Maybe (String,[Type])
-                    goodSig (s, ts) = do
-                                  ts1 <- sequence ts
-                                  return (getTName s,ts1)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/Drops.ag"(line 23, column 9)
-              _statementType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  DropFunction ann_ ifE_ _sigsIannotatedTree cascade_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  DropFunction ann_ ifE_ _sigsIfixedUpIdentifiersTree cascade_
-              -- self rule
-              _originalTree =
-                  DropFunction ann_ ifE_ _sigsIoriginalTree cascade_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _sigsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _sigsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _sigsOlib =
-                  _lhsIlib
-              ( _sigsIannotatedTree,_sigsIfixedUpIdentifiersTree,_sigsIfnSigs,_sigsIoriginalTree) =
-                  sigs_ _sigsOcat _sigsOidenv _sigsOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_DropSomething :: Annotation ->
-                               DropType ->
-                               IfExists ->
-                               ([Name]) ->
-                               Cascade ->
-                               T_Statement 
-sem_Statement_DropSomething ann_ dropType_ ifE_ names_ cascade_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  DropSomething ann_ dropType_ ifE_ names_ cascade_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  DropSomething ann_ dropType_ ifE_ names_ cascade_
-              -- self rule
-              _originalTree =
-                  DropSomething ann_ dropType_ ifE_ names_ cascade_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_Execute :: Annotation ->
-                         T_ScalarExpr  ->
-                         T_Statement 
-sem_Statement_Execute ann_ expr_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _exprOexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _exprOcat :: Catalog
-              _exprOidenv :: IDEnv
-              _exprOlib :: LocalBindings
-              _exprIannotatedTree :: ScalarExpr 
-              _exprIfixedUpIdentifiersTree :: ScalarExpr 
-              _exprIoriginalTree :: ScalarExpr 
-              _exprIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 112, column 9)
-              _exprOexpectedType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  Execute ann_ _exprIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Execute ann_ _exprIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Execute ann_ _exprIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _exprOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exprOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exprOlib =
-                  _lhsIlib
-              ( _exprIannotatedTree,_exprIfixedUpIdentifiersTree,_exprIoriginalTree,_exprIuType) =
-                  expr_ _exprOcat _exprOexpectedType _exprOidenv _exprOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_ExitStatement :: Annotation ->
-                               (Maybe String) ->
-                               T_Statement 
-sem_Statement_ExitStatement ann_ lb_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  ExitStatement ann_ lb_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  ExitStatement ann_ lb_
-              -- self rule
-              _originalTree =
-                  ExitStatement ann_ lb_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_ForIntegerStatement :: Annotation ->
-                                     (Maybe String) ->
-                                     NameComponent ->
-                                     T_ScalarExpr  ->
-                                     T_ScalarExpr  ->
-                                     T_StatementList  ->
-                                     T_Statement 
-sem_Statement_ForIntegerStatement ann_ lb_ var_ from_ to_ sts_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: Statement 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _stsOcatUpdates :: ([CatalogUpdate])
-              _stsOlibUpdates :: ([LocalBindingsUpdate])
-              _tpe :: (Either [TypeError] Type)
-              _catUpdates :: ([CatalogUpdate])
-              _statementType :: (Maybe ParameterizedStatementType)
-              _fromOexpectedType :: (Maybe Type)
-              _toOexpectedType :: (Maybe Type)
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _fromOcat :: Catalog
-              _fromOidenv :: IDEnv
-              _fromOlib :: LocalBindings
-              _toOcat :: Catalog
-              _toOidenv :: IDEnv
-              _toOlib :: LocalBindings
-              _stsOcat :: Catalog
-              _stsOidenv :: IDEnv
-              _stsOlib :: LocalBindings
-              _fromIannotatedTree :: ScalarExpr 
-              _fromIfixedUpIdentifiersTree :: ScalarExpr 
-              _fromIoriginalTree :: ScalarExpr 
-              _fromIuType :: (Maybe Type)
-              _toIannotatedTree :: ScalarExpr 
-              _toIfixedUpIdentifiersTree :: ScalarExpr 
-              _toIoriginalTree :: ScalarExpr 
-              _toIuType :: (Maybe Type)
-              _stsIannotatedTree :: StatementList 
-              _stsIfixedUpIdentifiersTree :: StatementList 
-              _stsIoriginalTree :: StatementList 
-              _stsIproducedCat :: Catalog
-              _stsIproducedLib :: LocalBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 82, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {stType = _statementType
-                               ,catUpd = _catUpdates    }) $
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 88, column 9)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 89, column 9)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 138, column 9)
-              _stsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 139, column 9)
-              _stsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Plpgsql.ag"(line 33, column 9)
-              _tpe =
-                  Left []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Plpgsql.ag"(line 60, column 9)
-              _backTree =
-                  ForIntegerStatement ann_ lb_ var_ _fromIannotatedTree _toIannotatedTree _stsIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Plpgsql.ag"(line 61, column 9)
-              _catUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Plpgsql.ag"(line 62, column 9)
-              _statementType =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 113, column 27)
-              _fromOexpectedType =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 114, column 27)
-              _toOexpectedType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  ForIntegerStatement ann_ lb_ var_ _fromIannotatedTree _toIannotatedTree _stsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  ForIntegerStatement ann_ lb_ var_ _fromIfixedUpIdentifiersTree _toIfixedUpIdentifiersTree _stsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  ForIntegerStatement ann_ lb_ var_ _fromIoriginalTree _toIoriginalTree _stsIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _fromOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _fromOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _fromOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _toOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _toOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _toOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _stsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _stsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _stsOlib =
-                  _lhsIlib
-              ( _fromIannotatedTree,_fromIfixedUpIdentifiersTree,_fromIoriginalTree,_fromIuType) =
-                  from_ _fromOcat _fromOexpectedType _fromOidenv _fromOlib 
-              ( _toIannotatedTree,_toIfixedUpIdentifiersTree,_toIoriginalTree,_toIuType) =
-                  to_ _toOcat _toOexpectedType _toOidenv _toOlib 
-              ( _stsIannotatedTree,_stsIfixedUpIdentifiersTree,_stsIoriginalTree,_stsIproducedCat,_stsIproducedLib) =
-                  sts_ _stsOcat _stsOcatUpdates _stsOidenv _stsOlib _stsOlibUpdates 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_ForQueryStatement :: Annotation ->
-                                   (Maybe String) ->
-                                   NameComponent ->
-                                   T_QueryExpr  ->
-                                   T_StatementList  ->
-                                   T_Statement 
-sem_Statement_ForQueryStatement ann_ lb_ var_ sel_ sts_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: Statement 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _stsOcatUpdates :: ([CatalogUpdate])
-              _stsOlibUpdates :: ([LocalBindingsUpdate])
-              _selOcsql :: LocalBindings
-              _tpe :: (Either [TypeError] Type)
-              _catUpdates :: ([CatalogUpdate])
-              _statementType :: (Maybe ParameterizedStatementType)
-              _selOexpectedTypes :: ([Maybe Type])
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _selOcat :: Catalog
-              _selOidenv :: IDEnv
-              _selOlib :: LocalBindings
-              _stsOcat :: Catalog
-              _stsOidenv :: IDEnv
-              _stsOlib :: LocalBindings
-              _selIannotatedTree :: QueryExpr 
-              _selIcidenv :: IDEnv
-              _selIfixedUpIdentifiersTree :: QueryExpr 
-              _selIlibUpdates :: ([LocalBindingsUpdate])
-              _selIoriginalTree :: QueryExpr 
-              _selIuType :: (Maybe [(String,Type)])
-              _stsIannotatedTree :: StatementList 
-              _stsIfixedUpIdentifiersTree :: StatementList 
-              _stsIoriginalTree :: StatementList 
-              _stsIproducedCat :: Catalog
-              _stsIproducedLib :: LocalBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 82, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {stType = _statementType
-                               ,catUpd = _catUpdates    }) $
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 88, column 9)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 89, column 9)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 138, column 9)
-              _stsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 139, column 9)
-              _stsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 124, column 25)
-              _selOcsql =
-                  emptyBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Plpgsql.ag"(line 67, column 9)
-              _tpe =
-                  Left []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Plpgsql.ag"(line 84, column 9)
-              _backTree =
-                  ForQueryStatement ann_ lb_ var_ _selIannotatedTree _stsIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Plpgsql.ag"(line 85, column 9)
-              _catUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Plpgsql.ag"(line 86, column 9)
-              _statementType =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 175, column 9)
-              _selOexpectedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  ForQueryStatement ann_ lb_ var_ _selIannotatedTree _stsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  ForQueryStatement ann_ lb_ var_ _selIfixedUpIdentifiersTree _stsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  ForQueryStatement ann_ lb_ var_ _selIoriginalTree _stsIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _selOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _selOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _selOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _stsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _stsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _stsOlib =
-                  _lhsIlib
-              ( _selIannotatedTree,_selIcidenv,_selIfixedUpIdentifiersTree,_selIlibUpdates,_selIoriginalTree,_selIuType) =
-                  sel_ _selOcat _selOcsql _selOexpectedTypes _selOidenv _selOlib 
-              ( _stsIannotatedTree,_stsIfixedUpIdentifiersTree,_stsIoriginalTree,_stsIproducedCat,_stsIproducedLib) =
-                  sts_ _stsOcat _stsOcatUpdates _stsOidenv _stsOlib _stsOlibUpdates 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_If :: Annotation ->
-                    T_ScalarExprStatementListPairList  ->
-                    T_StatementList  ->
-                    T_Statement 
-sem_Statement_If ann_ cases_ els_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _elsOcatUpdates :: ([CatalogUpdate])
-              _elsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _casesOcat :: Catalog
-              _casesOidenv :: IDEnv
-              _casesOlib :: LocalBindings
-              _elsOcat :: Catalog
-              _elsOidenv :: IDEnv
-              _elsOlib :: LocalBindings
-              _casesIannotatedTree :: ScalarExprStatementListPairList 
-              _casesIfixedUpIdentifiersTree :: ScalarExprStatementListPairList 
-              _casesIoriginalTree :: ScalarExprStatementListPairList 
-              _elsIannotatedTree :: StatementList 
-              _elsIfixedUpIdentifiersTree :: StatementList 
-              _elsIoriginalTree :: StatementList 
-              _elsIproducedCat :: Catalog
-              _elsIproducedLib :: LocalBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 134, column 9)
-              _elsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 135, column 9)
-              _elsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  If ann_ _casesIannotatedTree _elsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  If ann_ _casesIfixedUpIdentifiersTree _elsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  If ann_ _casesIoriginalTree _elsIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _casesOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _casesOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _casesOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _elsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _elsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _elsOlib =
-                  _lhsIlib
-              ( _casesIannotatedTree,_casesIfixedUpIdentifiersTree,_casesIoriginalTree) =
-                  cases_ _casesOcat _casesOidenv _casesOlib 
-              ( _elsIannotatedTree,_elsIfixedUpIdentifiersTree,_elsIoriginalTree,_elsIproducedCat,_elsIproducedLib) =
-                  els_ _elsOcat _elsOcatUpdates _elsOidenv _elsOlib _elsOlibUpdates 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_Insert :: Annotation ->
-                        T_Name  ->
-                        ([NameComponent]) ->
-                        T_QueryExpr  ->
-                        T_MaybeSelectList  ->
-                        T_Statement 
-sem_Statement_Insert ann_ table_ targetCols_ insData_ returning_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _returningOidenv :: IDEnv
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOannotatedTree :: Statement 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _insDataOcsql :: LocalBindings
-              _tpe :: (Either [TypeError] Type)
-              _statementType :: (Maybe ParameterizedStatementType)
-              _columnTypes :: (Either [TypeError] [(String,Type)])
-              _catUpdates :: ([CatalogUpdate])
-              _insDataOexpectedTypes :: ([Maybe Type])
-              _returningOlib :: LocalBindings
-              _lhsOoriginalTree :: Statement 
-              _tableOcat :: Catalog
-              _tableOidenv :: IDEnv
-              _tableOlib :: LocalBindings
-              _insDataOcat :: Catalog
-              _insDataOidenv :: IDEnv
-              _insDataOlib :: LocalBindings
-              _returningOcat :: Catalog
-              _tableIannotatedTree :: Name 
-              _tableIfixedUpIdentifiersTree :: Name 
-              _tableIoriginalTree :: Name 
-              _tableItbAnnotatedTree :: Name 
-              _tableItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _insDataIannotatedTree :: QueryExpr 
-              _insDataIcidenv :: IDEnv
-              _insDataIfixedUpIdentifiersTree :: QueryExpr 
-              _insDataIlibUpdates :: ([LocalBindingsUpdate])
-              _insDataIoriginalTree :: QueryExpr 
-              _insDataIuType :: (Maybe [(String,Type)])
-              _returningIannotatedTree :: MaybeSelectList 
-              _returningIfixedUpIdentifiersTree :: MaybeSelectList 
-              _returningIlistType :: ([(String,Maybe Type)])
-              _returningIoriginalTree :: MaybeSelectList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 565, column 9)
-              _trefEnv =
-                  getTableTrefEnv _lhsIcat _tableIoriginalTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 566, column 9)
-              _returningOidenv =
-                  _trefEnv
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 567, column 9)
-              _lhsOfixedUpIdentifiersTree =
-                  Insert ann_
-                         _tableIfixedUpIdentifiersTree
-                         targetCols_
-                         _insDataIfixedUpIdentifiersTree
-                         _returningIfixedUpIdentifiersTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 82, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {stType = _statementType
-                               ,catUpd = _catUpdates    }) $
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 88, column 9)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 89, column 9)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 125, column 14)
-              _insDataOcsql =
-                  emptyBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Insert.ag"(line 14, column 9)
-              _tpe =
-                  either Left (const $ Right $ Pseudo Void) _columnTypes
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Insert.ag"(line 15, column 9)
-              _statementType =
-                  Just (catMaybes $ getPlaceholderTypes _insDataIannotatedTree
-                       ,fromMaybe [] $ liftList _returningIlistType)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Insert.ag"(line 20, column 9)
-              _columnTypes =
-                  do
-                  atts <- lmt (allAtts <$> _tableItbUType)
-                  pAtts <- lmt (fst <$> _tableItbUType)
-                  tAtts <- case targetCols_ of
-                                [] -> return pAtts
-                                _ -> mapM (lkpA atts) (map ncStr targetCols_)
-                  expAtts <- lmt _insDataIuType
-                  checkAssignmentsValid _lhsIcat (map snd expAtts) (map snd tAtts)
-                  return tAtts
-                  where
-                    lkpA :: [(String,Type)] -> String -> E (String,Type)
-                    lkpA m n = maybe (Left [UnrecognisedIdentifier n])
-                                     (\t -> Right (n,t))
-                                     $ lookup n m
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Insert.ag"(line 36, column 9)
-              _backTree =
-                  Insert ann_ _tableItbAnnotatedTree
-                         targetCols_
-                         _insDataIannotatedTree
-                         _returningIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Insert.ag"(line 40, column 9)
-              _catUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Insert.ag"(line 41, column 9)
-              _insDataOexpectedTypes =
-                  maybe [] id $ do
-                  ts <- etmt $ _columnTypes
-                  return $ map (Just . snd) ts
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Insert.ag"(line 45, column 9)
-              _returningOlib =
-                  either (const _lhsIlib) id $ do
-                    makeTrefLib _lhsIcat _tableIannotatedTree _tableItbUType
-              -- self rule
-              _annotatedTree =
-                  Insert ann_ _tableIannotatedTree targetCols_ _insDataIannotatedTree _returningIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Insert ann_ _tableIfixedUpIdentifiersTree targetCols_ _insDataIfixedUpIdentifiersTree _returningIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Insert ann_ _tableIoriginalTree targetCols_ _insDataIoriginalTree _returningIoriginalTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _tableOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tableOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tableOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _insDataOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _insDataOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _insDataOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _returningOcat =
-                  _lhsIcat
-              ( _tableIannotatedTree,_tableIfixedUpIdentifiersTree,_tableIoriginalTree,_tableItbAnnotatedTree,_tableItbUType) =
-                  table_ _tableOcat _tableOidenv _tableOlib 
-              ( _insDataIannotatedTree,_insDataIcidenv,_insDataIfixedUpIdentifiersTree,_insDataIlibUpdates,_insDataIoriginalTree,_insDataIuType) =
-                  insData_ _insDataOcat _insDataOcsql _insDataOexpectedTypes _insDataOidenv _insDataOlib 
-              ( _returningIannotatedTree,_returningIfixedUpIdentifiersTree,_returningIlistType,_returningIoriginalTree) =
-                  returning_ _returningOcat _returningOidenv _returningOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_Into :: Annotation ->
-                      Bool ->
-                      ([Name]) ->
-                      T_Statement  ->
-                      T_Statement 
-sem_Statement_Into ann_ strict_ into_ stmt_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _stmtOcat :: Catalog
-              _stmtOidenv :: IDEnv
-              _stmtOinProducedCat :: Catalog
-              _stmtOlib :: LocalBindings
-              _stmtIannotatedTree :: Statement 
-              _stmtIcatUpdates :: ([CatalogUpdate])
-              _stmtIfixedUpIdentifiersTree :: Statement 
-              _stmtIlibUpdates :: ([LocalBindingsUpdate])
-              _stmtIoriginalTree :: Statement 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  Into ann_ strict_ into_ _stmtIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Into ann_ strict_ into_ _stmtIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Into ann_ strict_ into_ _stmtIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _stmtOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _stmtOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _stmtOinProducedCat =
-                  _lhsIinProducedCat
-              -- copy rule (down)
-              _stmtOlib =
-                  _lhsIlib
-              ( _stmtIannotatedTree,_stmtIcatUpdates,_stmtIfixedUpIdentifiersTree,_stmtIlibUpdates,_stmtIoriginalTree) =
-                  stmt_ _stmtOcat _stmtOidenv _stmtOinProducedCat _stmtOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_LoopStatement :: Annotation ->
-                               (Maybe String) ->
-                               T_StatementList  ->
-                               T_Statement 
-sem_Statement_LoopStatement ann_ lb_ sts_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _stsOcatUpdates :: ([CatalogUpdate])
-              _stsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _stsOcat :: Catalog
-              _stsOidenv :: IDEnv
-              _stsOlib :: LocalBindings
-              _stsIannotatedTree :: StatementList 
-              _stsIfixedUpIdentifiersTree :: StatementList 
-              _stsIoriginalTree :: StatementList 
-              _stsIproducedCat :: Catalog
-              _stsIproducedLib :: LocalBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 138, column 9)
-              _stsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 139, column 9)
-              _stsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  LoopStatement ann_ lb_ _stsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  LoopStatement ann_ lb_ _stsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  LoopStatement ann_ lb_ _stsIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _stsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _stsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _stsOlib =
-                  _lhsIlib
-              ( _stsIannotatedTree,_stsIfixedUpIdentifiersTree,_stsIoriginalTree,_stsIproducedCat,_stsIproducedLib) =
-                  sts_ _stsOcat _stsOcatUpdates _stsOidenv _stsOlib _stsOlibUpdates 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_Notify :: Annotation ->
-                        String ->
-                        T_Statement 
-sem_Statement_Notify ann_ name_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  Notify ann_ name_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Notify ann_ name_
-              -- self rule
-              _originalTree =
-                  Notify ann_ name_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_NullStatement :: Annotation ->
-                               T_Statement 
-sem_Statement_NullStatement ann_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  NullStatement ann_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  NullStatement ann_
-              -- self rule
-              _originalTree =
-                  NullStatement ann_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_Perform :: Annotation ->
-                         T_ScalarExpr  ->
-                         T_Statement 
-sem_Statement_Perform ann_ expr_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _exprOexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _exprOcat :: Catalog
-              _exprOidenv :: IDEnv
-              _exprOlib :: LocalBindings
-              _exprIannotatedTree :: ScalarExpr 
-              _exprIfixedUpIdentifiersTree :: ScalarExpr 
-              _exprIoriginalTree :: ScalarExpr 
-              _exprIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 112, column 9)
-              _exprOexpectedType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  Perform ann_ _exprIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Perform ann_ _exprIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Perform ann_ _exprIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _exprOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exprOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exprOlib =
-                  _lhsIlib
-              ( _exprIannotatedTree,_exprIfixedUpIdentifiersTree,_exprIoriginalTree,_exprIuType) =
-                  expr_ _exprOcat _exprOexpectedType _exprOidenv _exprOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_QueryStatement :: Annotation ->
-                                T_QueryExpr  ->
-                                T_Statement 
-sem_Statement_QueryStatement ann_ ex_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: Statement 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _tpe :: (Either [TypeError] Type)
-              _statementType :: (Maybe ParameterizedStatementType)
-              _catUpdates :: ([CatalogUpdate])
-              _exOcsql :: LocalBindings
-              _exOexpectedTypes :: ([Maybe Type])
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _exOcat :: Catalog
-              _exOidenv :: IDEnv
-              _exOlib :: LocalBindings
-              _exIannotatedTree :: QueryExpr 
-              _exIcidenv :: IDEnv
-              _exIfixedUpIdentifiersTree :: QueryExpr 
-              _exIlibUpdates :: ([LocalBindingsUpdate])
-              _exIoriginalTree :: QueryExpr 
-              _exIuType :: (Maybe [(String,Type)])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 82, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {stType = _statementType
-                               ,catUpd = _catUpdates    }) $
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 88, column 9)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 89, column 9)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 14, column 9)
-              _tpe =
-                  Right $ Pseudo Void
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 15, column 9)
-              _statementType =
-                  do
-                  pt <- sequence $ getPlaceholderTypes _exIannotatedTree
-                  st <- _exIuType
-                  return (pt
-                         ,case st of
-                            [(_,(Pseudo Void))] -> []
-                            t -> t)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 23, column 9)
-              _backTree =
-                  QueryStatement ann_ _exIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 24, column 9)
-              _catUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 126, column 22)
-              _exOcsql =
-                  emptyBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 137, column 9)
-              _libUpdates =
-                  _exIlibUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 176, column 22)
-              _exOexpectedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  QueryStatement ann_ _exIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  QueryStatement ann_ _exIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  QueryStatement ann_ _exIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _exOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exOlib =
-                  _lhsIlib
-              ( _exIannotatedTree,_exIcidenv,_exIfixedUpIdentifiersTree,_exIlibUpdates,_exIoriginalTree,_exIuType) =
-                  ex_ _exOcat _exOcsql _exOexpectedTypes _exOidenv _exOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_Raise :: Annotation ->
-                       RaiseType ->
-                       String ->
-                       T_ScalarExprList  ->
-                       T_Statement 
-sem_Statement_Raise ann_ level_ message_ args_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _argsOexpectedTypes :: ([Maybe Type])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _argsOcat :: Catalog
-              _argsOidenv :: IDEnv
-              _argsOlib :: LocalBindings
-              _argsIannotatedTree :: ScalarExprList 
-              _argsIfixedUpIdentifiersTree :: ScalarExprList 
-              _argsIoriginalTree :: ScalarExprList 
-              _argsIuType :: ([Maybe Type])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 152, column 13)
-              _argsOexpectedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  Raise ann_ level_ message_ _argsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Raise ann_ level_ message_ _argsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Raise ann_ level_ message_ _argsIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _argsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _argsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _argsOlib =
-                  _lhsIlib
-              ( _argsIannotatedTree,_argsIfixedUpIdentifiersTree,_argsIoriginalTree,_argsIuType) =
-                  args_ _argsOcat _argsOexpectedTypes _argsOidenv _argsOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_Return :: Annotation ->
-                        T_MaybeScalarExpr  ->
-                        T_Statement 
-sem_Statement_Return ann_ value_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: Statement 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _tpe :: (Either [TypeError] Type)
-              _catUpdates :: ([CatalogUpdate])
-              _statementType :: (Maybe ParameterizedStatementType)
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _valueOcat :: Catalog
-              _valueOidenv :: IDEnv
-              _valueOlib :: LocalBindings
-              _valueIannotatedTree :: MaybeScalarExpr 
-              _valueIfixedUpIdentifiersTree :: MaybeScalarExpr 
-              _valueIoriginalTree :: MaybeScalarExpr 
-              _valueIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 82, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {stType = _statementType
-                               ,catUpd = _catUpdates    }) $
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 88, column 9)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 89, column 9)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Plpgsql.ag"(line 12, column 9)
-              _tpe =
-                  maybe (Right $ Pseudo Void) Right _valueIuType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Plpgsql.ag"(line 13, column 9)
-              _backTree =
-                  Return ann_ _valueIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Plpgsql.ag"(line 14, column 9)
-              _catUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Plpgsql.ag"(line 15, column 9)
-              _statementType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  Return ann_ _valueIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Return ann_ _valueIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Return ann_ _valueIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _valueOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _valueOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _valueOlib =
-                  _lhsIlib
-              ( _valueIannotatedTree,_valueIfixedUpIdentifiersTree,_valueIoriginalTree,_valueIuType) =
-                  value_ _valueOcat _valueOidenv _valueOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_ReturnNext :: Annotation ->
-                            T_ScalarExpr  ->
-                            T_Statement 
-sem_Statement_ReturnNext ann_ expr_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _exprOexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _exprOcat :: Catalog
-              _exprOidenv :: IDEnv
-              _exprOlib :: LocalBindings
-              _exprIannotatedTree :: ScalarExpr 
-              _exprIfixedUpIdentifiersTree :: ScalarExpr 
-              _exprIoriginalTree :: ScalarExpr 
-              _exprIuType :: (Maybe Type)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 112, column 9)
-              _exprOexpectedType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  ReturnNext ann_ _exprIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  ReturnNext ann_ _exprIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  ReturnNext ann_ _exprIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _exprOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exprOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exprOlib =
-                  _lhsIlib
-              ( _exprIannotatedTree,_exprIfixedUpIdentifiersTree,_exprIoriginalTree,_exprIuType) =
-                  expr_ _exprOcat _exprOexpectedType _exprOidenv _exprOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_ReturnQuery :: Annotation ->
-                             T_QueryExpr  ->
-                             T_Statement 
-sem_Statement_ReturnQuery ann_ sel_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _selOcsql :: LocalBindings
-              _selOexpectedTypes :: ([Maybe Type])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _selOcat :: Catalog
-              _selOidenv :: IDEnv
-              _selOlib :: LocalBindings
-              _selIannotatedTree :: QueryExpr 
-              _selIcidenv :: IDEnv
-              _selIfixedUpIdentifiersTree :: QueryExpr 
-              _selIlibUpdates :: ([LocalBindingsUpdate])
-              _selIoriginalTree :: QueryExpr 
-              _selIuType :: (Maybe [(String,Type)])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 127, column 19)
-              _selOcsql =
-                  emptyBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 175, column 9)
-              _selOexpectedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  ReturnQuery ann_ _selIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  ReturnQuery ann_ _selIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  ReturnQuery ann_ _selIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _selOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _selOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _selOlib =
-                  _lhsIlib
-              ( _selIannotatedTree,_selIcidenv,_selIfixedUpIdentifiersTree,_selIlibUpdates,_selIoriginalTree,_selIuType) =
-                  sel_ _selOcat _selOcsql _selOexpectedTypes _selOidenv _selOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_Set :: Annotation ->
-                     String ->
-                     ([SetValue]) ->
-                     T_Statement 
-sem_Statement_Set ann_ name_ values_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  Set ann_ name_ values_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Set ann_ name_ values_
-              -- self rule
-              _originalTree =
-                  Set ann_ name_ values_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_Truncate :: Annotation ->
-                          ([Name]) ->
-                          RestartIdentity ->
-                          Cascade ->
-                          T_Statement 
-sem_Statement_Truncate ann_ tables_ restartIdentity_ cascade_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- self rule
-              _annotatedTree =
-                  Truncate ann_ tables_ restartIdentity_ cascade_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Truncate ann_ tables_ restartIdentity_ cascade_
-              -- self rule
-              _originalTree =
-                  Truncate ann_ tables_ restartIdentity_ cascade_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_Update :: Annotation ->
-                        T_Name  ->
-                        T_SetClauseList  ->
-                        T_TableRefList  ->
-                        T_MaybeBoolExpr  ->
-                        T_MaybeSelectList  ->
-                        T_Statement 
-sem_Statement_Update ann_ table_ assigns_ fromList_ whr_ returning_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _whrOidenv :: IDEnv
-              _assignsOidenv :: IDEnv
-              _returningOidenv :: IDEnv
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOannotatedTree :: Statement 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _tpe :: (Either [TypeError] Type)
-              _statementType :: (Maybe ParameterizedStatementType)
-              _catUpdates :: ([CatalogUpdate])
-              _whrOlib :: LocalBindings
-              _assignsOlib :: LocalBindings
-              _returningOlib :: LocalBindings
-              _assignsOtbName :: String
-              _lhsOoriginalTree :: Statement 
-              _tableOcat :: Catalog
-              _tableOidenv :: IDEnv
-              _tableOlib :: LocalBindings
-              _assignsOcat :: Catalog
-              _fromListOcat :: Catalog
-              _fromListOidenv :: IDEnv
-              _fromListOlib :: LocalBindings
-              _whrOcat :: Catalog
-              _returningOcat :: Catalog
-              _tableIannotatedTree :: Name 
-              _tableIfixedUpIdentifiersTree :: Name 
-              _tableIoriginalTree :: Name 
-              _tableItbAnnotatedTree :: Name 
-              _tableItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _assignsIannotatedTree :: SetClauseList 
-              _assignsIfixedUpIdentifiersTree :: SetClauseList 
-              _assignsIoriginalTree :: SetClauseList 
-              _fromListIannotatedTree :: TableRefList 
-              _fromListIfixedUpIdentifiersTree :: TableRefList 
-              _fromListIlibUpdates :: ([LocalBindingsUpdate])
-              _fromListInewLib2 :: LocalBindings
-              _fromListIoriginalTree :: TableRefList 
-              _fromListItrefIDs :: IDEnv
-              _whrIannotatedTree :: MaybeBoolExpr 
-              _whrIfixedUpIdentifiersTree :: MaybeBoolExpr 
-              _whrIoriginalTree :: MaybeBoolExpr 
-              _returningIannotatedTree :: MaybeSelectList 
-              _returningIfixedUpIdentifiersTree :: MaybeSelectList 
-              _returningIlistType :: ([(String,Maybe Type)])
-              _returningIoriginalTree :: MaybeSelectList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 543, column 9)
-              _trefEnv =
-                  getTableTrefEnv _lhsIcat _tableIoriginalTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 544, column 9)
-              _whrOidenv =
-                  _trefEnv
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 545, column 9)
-              _assignsOidenv =
-                  _trefEnv
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 546, column 9)
-              _returningOidenv =
-                  _trefEnv
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 547, column 9)
-              _lhsOfixedUpIdentifiersTree =
-                  Update ann_
-                         _tableIfixedUpIdentifiersTree
-                         _assignsIfixedUpIdentifiersTree
-                         _fromListIfixedUpIdentifiersTree
-                         _whrIfixedUpIdentifiersTree
-                         _returningIfixedUpIdentifiersTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 82, column 9)
-              _lhsOannotatedTree =
-                  updateAnnotation
-                      (\a -> a {stType = _statementType
-                               ,catUpd = _catUpdates    }) $
-                  setTypeAddErrors _tpe     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 88, column 9)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 89, column 9)
-              _lhsOlibUpdates =
-                  _libUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 94, column 9)
-              _libUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 25, column 9)
-              _tpe =
-                  Right $ Pseudo Void
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 30, column 9)
-              _statementType =
-                  do
-                  pt <- sequence $ getPlaceholderTypes _assignsIannotatedTree
-                                   ++ getPlaceholderTypes _whrIannotatedTree
-                  return (pt,fromMaybe [] $ liftList _returningIlistType)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 36, column 9)
-              _backTree =
-                  Update ann_
-                         _tableItbAnnotatedTree
-                         _assignsIannotatedTree
-                         _fromListIannotatedTree
-                         _whrIannotatedTree
-                         _returningIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 42, column 9)
-              _catUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 47, column 9)
-              _lib =
-                  either (const _lhsIlib) id $ do
-                    makeTrefLib _lhsIcat _tableIannotatedTree _tableItbUType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 50, column 9)
-              _whrOlib =
-                  _lib
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 51, column 9)
-              _assignsOlib =
-                  _lib
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 52, column 9)
-              _returningOlib =
-                  _lib
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Dml/Update.ag"(line 59, column 9)
-              _assignsOtbName =
-                  getTName _tableIannotatedTree
-              -- self rule
-              _annotatedTree =
-                  Update ann_ _tableIannotatedTree _assignsIannotatedTree _fromListIannotatedTree _whrIannotatedTree _returningIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Update ann_ _tableIfixedUpIdentifiersTree _assignsIfixedUpIdentifiersTree _fromListIfixedUpIdentifiersTree _whrIfixedUpIdentifiersTree _returningIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Update ann_ _tableIoriginalTree _assignsIoriginalTree _fromListIoriginalTree _whrIoriginalTree _returningIoriginalTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _tableOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tableOidenv =
-                  _lhsIidenv
-              -- copy rule (from local)
-              _tableOlib =
-                  _lib
-              -- copy rule (down)
-              _assignsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _fromListOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _fromListOidenv =
-                  _lhsIidenv
-              -- copy rule (from local)
-              _fromListOlib =
-                  _lib
-              -- copy rule (down)
-              _whrOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _returningOcat =
-                  _lhsIcat
-              ( _tableIannotatedTree,_tableIfixedUpIdentifiersTree,_tableIoriginalTree,_tableItbAnnotatedTree,_tableItbUType) =
-                  table_ _tableOcat _tableOidenv _tableOlib 
-              ( _assignsIannotatedTree,_assignsIfixedUpIdentifiersTree,_assignsIoriginalTree) =
-                  assigns_ _assignsOcat _assignsOidenv _assignsOlib _assignsOtbName 
-              ( _fromListIannotatedTree,_fromListIfixedUpIdentifiersTree,_fromListIlibUpdates,_fromListInewLib2,_fromListIoriginalTree,_fromListItrefIDs) =
-                  fromList_ _fromListOcat _fromListOidenv _fromListOlib 
-              ( _whrIannotatedTree,_whrIfixedUpIdentifiersTree,_whrIoriginalTree) =
-                  whr_ _whrOcat _whrOidenv _whrOlib 
-              ( _returningIannotatedTree,_returningIfixedUpIdentifiersTree,_returningIlistType,_returningIoriginalTree) =
-                  returning_ _returningOcat _returningOidenv _returningOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
-sem_Statement_WhileStatement :: Annotation ->
-                                (Maybe String) ->
-                                T_ScalarExpr  ->
-                                T_StatementList  ->
-                                T_Statement 
-sem_Statement_WhileStatement ann_ lb_ expr_ sts_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIinProducedCat
-       _lhsIlib ->
-         (let _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _stsOcatUpdates :: ([CatalogUpdate])
-              _stsOlibUpdates :: ([LocalBindingsUpdate])
-              _exprOexpectedType :: (Maybe Type)
-              _lhsOannotatedTree :: Statement 
-              _lhsOfixedUpIdentifiersTree :: Statement 
-              _lhsOoriginalTree :: Statement 
-              _exprOcat :: Catalog
-              _exprOidenv :: IDEnv
-              _exprOlib :: LocalBindings
-              _stsOcat :: Catalog
-              _stsOidenv :: IDEnv
-              _stsOlib :: LocalBindings
-              _exprIannotatedTree :: ScalarExpr 
-              _exprIfixedUpIdentifiersTree :: ScalarExpr 
-              _exprIoriginalTree :: ScalarExpr 
-              _exprIuType :: (Maybe Type)
-              _stsIannotatedTree :: StatementList 
-              _stsIfixedUpIdentifiersTree :: StatementList 
-              _stsIoriginalTree :: StatementList 
-              _stsIproducedCat :: Catalog
-              _stsIproducedLib :: LocalBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 116, column 9)
-              _lhsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 117, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 138, column 9)
-              _stsOcatUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 139, column 9)
-              _stsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 112, column 9)
-              _exprOexpectedType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  WhileStatement ann_ lb_ _exprIannotatedTree _stsIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  WhileStatement ann_ lb_ _exprIfixedUpIdentifiersTree _stsIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  WhileStatement ann_ lb_ _exprIoriginalTree _stsIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _exprOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exprOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exprOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _stsOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _stsOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _stsOlib =
-                  _lhsIlib
-              ( _exprIannotatedTree,_exprIfixedUpIdentifiersTree,_exprIoriginalTree,_exprIuType) =
-                  expr_ _exprOcat _exprOexpectedType _exprOidenv _exprOlib 
-              ( _stsIannotatedTree,_stsIfixedUpIdentifiersTree,_stsIoriginalTree,_stsIproducedCat,_stsIproducedLib) =
-                  sts_ _stsOcat _stsOcatUpdates _stsOidenv _stsOlib _stsOlibUpdates 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOoriginalTree)))
--- StatementList -----------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         catUpdates           : [CatalogUpdate]
-         idenv                : IDEnv
-         lib                  : LocalBindings
-         libUpdates           : [LocalBindingsUpdate]
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-         producedCat          : Catalog
-         producedLib          : LocalBindings
-   alternatives:
-      alternative Cons:
-         child hd             : Statement 
-         child tl             : StatementList 
-         visit 0:
-            local newCat      : _
-            local newLib      : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local newCat      : _
-            local newLib      : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type StatementList  = [Statement ]
--- cata
-sem_StatementList :: StatementList  ->
-                     T_StatementList 
-sem_StatementList list  =
-    (Prelude.foldr sem_StatementList_Cons sem_StatementList_Nil (Prelude.map sem_Statement list) )
--- semantic domain
-type T_StatementList  = Catalog ->
-                        ([CatalogUpdate]) ->
-                        IDEnv ->
-                        LocalBindings ->
-                        ([LocalBindingsUpdate]) ->
-                        ( StatementList ,StatementList ,StatementList ,Catalog,LocalBindings)
-data Inh_StatementList  = Inh_StatementList {cat_Inh_StatementList :: Catalog,catUpdates_Inh_StatementList :: ([CatalogUpdate]),idenv_Inh_StatementList :: IDEnv,lib_Inh_StatementList :: LocalBindings,libUpdates_Inh_StatementList :: ([LocalBindingsUpdate])}
-data Syn_StatementList  = Syn_StatementList {annotatedTree_Syn_StatementList :: StatementList ,fixedUpIdentifiersTree_Syn_StatementList :: StatementList ,originalTree_Syn_StatementList :: StatementList ,producedCat_Syn_StatementList :: Catalog,producedLib_Syn_StatementList :: LocalBindings}
-wrap_StatementList :: T_StatementList  ->
-                      Inh_StatementList  ->
-                      Syn_StatementList 
-wrap_StatementList sem (Inh_StatementList _lhsIcat _lhsIcatUpdates _lhsIidenv _lhsIlib _lhsIlibUpdates )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOproducedCat,_lhsOproducedLib) = sem _lhsIcat _lhsIcatUpdates _lhsIidenv _lhsIlib _lhsIlibUpdates 
-     in  (Syn_StatementList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree _lhsOproducedCat _lhsOproducedLib ))
-sem_StatementList_Cons :: T_Statement  ->
-                          T_StatementList  ->
-                          T_StatementList 
-sem_StatementList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIcatUpdates
-       _lhsIidenv
-       _lhsIlib
-       _lhsIlibUpdates ->
-         (let _hdOcat :: Catalog
-              _tlOcat :: Catalog
-              _hdOlib :: LocalBindings
-              _tlOlib :: LocalBindings
-              _lhsOproducedCat :: Catalog
-              _lhsOproducedLib :: LocalBindings
-              _tlOcatUpdates :: ([CatalogUpdate])
-              _tlOlibUpdates :: ([LocalBindingsUpdate])
-              _hdOinProducedCat :: Catalog
-              _lhsOannotatedTree :: StatementList 
-              _lhsOfixedUpIdentifiersTree :: StatementList 
-              _lhsOoriginalTree :: StatementList 
-              _hdOidenv :: IDEnv
-              _tlOidenv :: IDEnv
-              _hdIannotatedTree :: Statement 
-              _hdIcatUpdates :: ([CatalogUpdate])
-              _hdIfixedUpIdentifiersTree :: Statement 
-              _hdIlibUpdates :: ([LocalBindingsUpdate])
-              _hdIoriginalTree :: Statement 
-              _tlIannotatedTree :: StatementList 
-              _tlIfixedUpIdentifiersTree :: StatementList 
-              _tlIoriginalTree :: StatementList 
-              _tlIproducedCat :: Catalog
-              _tlIproducedLib :: LocalBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 56, column 9)
-              _newCat =
-                  fromRight _lhsIcat $ updateCatalog _lhsIcat _lhsIcatUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 57, column 9)
-              _newLib =
-                  fromRight _lhsIlib $ foldM (flip $ lbUpdate _lhsIcat) _lhsIlib _lhsIlibUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 59, column 9)
-              _hdOcat =
-                  _newCat
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 60, column 9)
-              _tlOcat =
-                  _newCat
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 61, column 9)
-              _hdOlib =
-                  _newLib
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 62, column 9)
-              _tlOlib =
-                  _newLib
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 66, column 9)
-              _lhsOproducedCat =
-                  _tlIproducedCat
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 67, column 9)
-              _lhsOproducedLib =
-                  _tlIproducedLib
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 70, column 9)
-              _tlOcatUpdates =
-                  _hdIcatUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 71, column 9)
-              _tlOlibUpdates =
-                  _hdIlibUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 97, column 12)
-              _hdOinProducedCat =
-                  _tlIproducedCat
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              ( _hdIannotatedTree,_hdIcatUpdates,_hdIfixedUpIdentifiersTree,_hdIlibUpdates,_hdIoriginalTree) =
-                  hd_ _hdOcat _hdOidenv _hdOinProducedCat _hdOlib 
-              ( _tlIannotatedTree,_tlIfixedUpIdentifiersTree,_tlIoriginalTree,_tlIproducedCat,_tlIproducedLib) =
-                  tl_ _tlOcat _tlOcatUpdates _tlOidenv _tlOlib _tlOlibUpdates 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOproducedCat,_lhsOproducedLib)))
-sem_StatementList_Nil :: T_StatementList 
-sem_StatementList_Nil  =
-    (\ _lhsIcat
-       _lhsIcatUpdates
-       _lhsIidenv
-       _lhsIlib
-       _lhsIlibUpdates ->
-         (let _lhsOproducedCat :: Catalog
-              _lhsOproducedLib :: LocalBindings
-              _lhsOannotatedTree :: StatementList 
-              _lhsOfixedUpIdentifiersTree :: StatementList 
-              _lhsOoriginalTree :: StatementList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 56, column 9)
-              _newCat =
-                  fromRight _lhsIcat $ updateCatalog _lhsIcat _lhsIcatUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 57, column 9)
-              _newLib =
-                  fromRight _lhsIlib $ foldM (flip $ lbUpdate _lhsIcat) _lhsIlib _lhsIlibUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 73, column 9)
-              _lhsOproducedCat =
-                  _newCat
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 74, column 9)
-              _lhsOproducedLib =
-                  _newLib
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOproducedCat,_lhsOproducedLib)))
--- TableAlias --------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         expectedNumCols      : Maybe Int
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative FullAlias:
-         child ann            : {Annotation}
-         child tb             : {NameComponent}
-         child cols           : {[NameComponent]}
-         visit 0:
-            local errs        : _
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative NoAlias:
-         child ann            : {Annotation}
-         visit 0:
-            local backTree    : _
-            local errs        : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative TableAlias:
-         child ann            : {Annotation}
-         child tb             : {NameComponent}
-         visit 0:
-            local backTree    : _
-            local errs        : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data TableAlias  = FullAlias (Annotation) (NameComponent) (([NameComponent])) 
-                 | NoAlias (Annotation) 
-                 | TableAlias (Annotation) (NameComponent) 
-                 deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_TableAlias :: TableAlias  ->
-                  T_TableAlias 
-sem_TableAlias (FullAlias _ann _tb _cols )  =
-    (sem_TableAlias_FullAlias _ann _tb _cols )
-sem_TableAlias (NoAlias _ann )  =
-    (sem_TableAlias_NoAlias _ann )
-sem_TableAlias (TableAlias _ann _tb )  =
-    (sem_TableAlias_TableAlias _ann _tb )
--- semantic domain
-type T_TableAlias  = Catalog ->
-                     (Maybe Int) ->
-                     IDEnv ->
-                     LocalBindings ->
-                     ( TableAlias ,TableAlias ,TableAlias )
-data Inh_TableAlias  = Inh_TableAlias {cat_Inh_TableAlias :: Catalog,expectedNumCols_Inh_TableAlias :: (Maybe Int),idenv_Inh_TableAlias :: IDEnv,lib_Inh_TableAlias :: LocalBindings}
-data Syn_TableAlias  = Syn_TableAlias {annotatedTree_Syn_TableAlias :: TableAlias ,fixedUpIdentifiersTree_Syn_TableAlias :: TableAlias ,originalTree_Syn_TableAlias :: TableAlias }
-wrap_TableAlias :: T_TableAlias  ->
-                   Inh_TableAlias  ->
-                   Syn_TableAlias 
-wrap_TableAlias sem (Inh_TableAlias _lhsIcat _lhsIexpectedNumCols _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIexpectedNumCols _lhsIidenv _lhsIlib 
-     in  (Syn_TableAlias _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_TableAlias_FullAlias :: Annotation ->
-                            NameComponent ->
-                            ([NameComponent]) ->
-                            T_TableAlias 
-sem_TableAlias_FullAlias ann_ tb_ cols_  =
-    (\ _lhsIcat
-       _lhsIexpectedNumCols
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: TableAlias 
-              _lhsOfixedUpIdentifiersTree :: TableAlias 
-              _lhsOoriginalTree :: TableAlias 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 305, column 9)
-              _lhsOannotatedTree =
-                  addTypeErrors _errs     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 307, column 9)
-              _errs =
-                  case _lhsIexpectedNumCols of
-                        Nothing -> []
-                        Just n -> if n == length cols_
-                                  then []
-                                  else [WrongNumberOfAliasCols n $ length cols_]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 312, column 9)
-              _backTree =
-                  FullAlias ann_ tb_ cols_
-              -- self rule
-              _annotatedTree =
-                  FullAlias ann_ tb_ cols_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  FullAlias ann_ tb_ cols_
-              -- self rule
-              _originalTree =
-                  FullAlias ann_ tb_ cols_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_TableAlias_NoAlias :: Annotation ->
-                          T_TableAlias 
-sem_TableAlias_NoAlias ann_  =
-    (\ _lhsIcat
-       _lhsIexpectedNumCols
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: TableAlias 
-              _lhsOfixedUpIdentifiersTree :: TableAlias 
-              _lhsOoriginalTree :: TableAlias 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 305, column 9)
-              _lhsOannotatedTree =
-                  addTypeErrors _errs     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 315, column 15)
-              _backTree =
-                  NoAlias ann_
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 316, column 15)
-              _errs =
-                  []
-              -- self rule
-              _annotatedTree =
-                  NoAlias ann_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  NoAlias ann_
-              -- self rule
-              _originalTree =
-                  NoAlias ann_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_TableAlias_TableAlias :: Annotation ->
-                             NameComponent ->
-                             T_TableAlias 
-sem_TableAlias_TableAlias ann_ tb_  =
-    (\ _lhsIcat
-       _lhsIexpectedNumCols
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOannotatedTree :: TableAlias 
-              _lhsOfixedUpIdentifiersTree :: TableAlias 
-              _lhsOoriginalTree :: TableAlias 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 305, column 9)
-              _lhsOannotatedTree =
-                  addTypeErrors _errs     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 313, column 18)
-              _backTree =
-                  TableAlias ann_ tb_
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 314, column 18)
-              _errs =
-                  []
-              -- self rule
-              _annotatedTree =
-                  TableAlias ann_ tb_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  TableAlias ann_ tb_
-              -- self rule
-              _originalTree =
-                  TableAlias ann_ tb_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- TableRef ----------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         libUpdates           : [LocalBindingsUpdate]
-         newLib2              : LocalBindings
-         originalTree         : SELF 
-         trefIDs              : IDEnv
-   alternatives:
-      alternative FunTref:
-         child ann            : {Annotation}
-         child fn             : ScalarExpr 
-         child alias          : TableAlias 
-         visit 0:
-            local _tup2       : {(IDEnv,TableRef)}
-            local errs        : _
-            local eqfunIdens  : {Either [TypeError] (String,[(String,Type)])}
-            local qfunIdens   : _
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative JoinTref:
-         child ann            : {Annotation}
-         child tbl            : TableRef 
-         child nat            : {Natural}
-         child joinType       : {JoinType}
-         child tbl1           : TableRef 
-         child onExpr         : OnExpr 
-         child alias          : TableAlias 
-         visit 0:
-            local _tup3       : _
-            local trefIDs     : _
-            local errs        : _
-            local joinErrors  : _
-            local libUpdates  : _
-            local newLib      : {Either [TypeError] LocalBindings}
-            local newLib2     : _
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative SubTref:
-         child ann            : {Annotation}
-         child sel            : QueryExpr 
-         child alias          : TableAlias 
-         visit 0:
-            local _tup4       : {(IDEnv,TableRef)}
-            local errs        : _
-            local selectAttrs : {Either [TypeError] [(String,Type)]}
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Tref:
-         child ann            : {Annotation}
-         child tbl            : Name 
-         child alias          : TableAlias 
-         visit 0:
-            local _tup5       : {(IDEnv,TableRef)}
-            local errs        : _
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data TableRef  = FunTref (Annotation) (ScalarExpr ) (TableAlias ) 
-               | JoinTref (Annotation) (TableRef ) (Natural) (JoinType) (TableRef ) (OnExpr ) (TableAlias ) 
-               | SubTref (Annotation) (QueryExpr ) (TableAlias ) 
-               | Tref (Annotation) (Name ) (TableAlias ) 
-               deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_TableRef :: TableRef  ->
-                T_TableRef 
-sem_TableRef (FunTref _ann _fn _alias )  =
-    (sem_TableRef_FunTref _ann (sem_ScalarExpr _fn ) (sem_TableAlias _alias ) )
-sem_TableRef (JoinTref _ann _tbl _nat _joinType _tbl1 _onExpr _alias )  =
-    (sem_TableRef_JoinTref _ann (sem_TableRef _tbl ) _nat _joinType (sem_TableRef _tbl1 ) (sem_OnExpr _onExpr ) (sem_TableAlias _alias ) )
-sem_TableRef (SubTref _ann _sel _alias )  =
-    (sem_TableRef_SubTref _ann (sem_QueryExpr _sel ) (sem_TableAlias _alias ) )
-sem_TableRef (Tref _ann _tbl _alias )  =
-    (sem_TableRef_Tref _ann (sem_Name _tbl ) (sem_TableAlias _alias ) )
--- semantic domain
-type T_TableRef  = Catalog ->
-                   IDEnv ->
-                   LocalBindings ->
-                   ( TableRef ,TableRef ,([LocalBindingsUpdate]),LocalBindings,TableRef ,IDEnv)
-data Inh_TableRef  = Inh_TableRef {cat_Inh_TableRef :: Catalog,idenv_Inh_TableRef :: IDEnv,lib_Inh_TableRef :: LocalBindings}
-data Syn_TableRef  = Syn_TableRef {annotatedTree_Syn_TableRef :: TableRef ,fixedUpIdentifiersTree_Syn_TableRef :: TableRef ,libUpdates_Syn_TableRef :: ([LocalBindingsUpdate]),newLib2_Syn_TableRef :: LocalBindings,originalTree_Syn_TableRef :: TableRef ,trefIDs_Syn_TableRef :: IDEnv}
-wrap_TableRef :: T_TableRef  ->
-                 Inh_TableRef  ->
-                 Syn_TableRef 
-wrap_TableRef sem (Inh_TableRef _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOnewLib2,_lhsOoriginalTree,_lhsOtrefIDs) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_TableRef _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOlibUpdates _lhsOnewLib2 _lhsOoriginalTree _lhsOtrefIDs ))
-sem_TableRef_FunTref :: Annotation ->
-                        T_ScalarExpr  ->
-                        T_TableAlias  ->
-                        T_TableRef 
-sem_TableRef_FunTref ann_ fn_ alias_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let __tup2 :: ((IDEnv,TableRef))
-              _lhsOtrefIDs :: IDEnv
-              _lhsOfixedUpIdentifiersTree :: TableRef 
-              _lhsOannotatedTree :: TableRef 
-              _eqfunIdens :: (Either [TypeError] (String,[(String,Type)]))
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOnewLib2 :: LocalBindings
-              _aliasOexpectedNumCols :: (Maybe Int)
-              _fnOexpectedType :: (Maybe Type)
-              _lhsOoriginalTree :: TableRef 
-              _fnOcat :: Catalog
-              _fnOidenv :: IDEnv
-              _fnOlib :: LocalBindings
-              _aliasOcat :: Catalog
-              _aliasOidenv :: IDEnv
-              _aliasOlib :: LocalBindings
-              _fnIannotatedTree :: ScalarExpr 
-              _fnIfixedUpIdentifiersTree :: ScalarExpr 
-              _fnIoriginalTree :: ScalarExpr 
-              _fnIuType :: (Maybe Type)
-              _aliasIannotatedTree :: TableAlias 
-              _aliasIfixedUpIdentifiersTree :: TableAlias 
-              _aliasIoriginalTree :: TableAlias 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 424, column 15)
-              __tup2 =
-                  let (FunCall _ f _) = _fnIoriginalTree
-                      iea = aliasEnv _aliasIoriginalTree $ FunTrefIDEnv $ getTName f
-                      al = getEnvAlias iea
-                  in (iea, FunTref ann_ _fnIfixedUpIdentifiersTree al)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 424, column 15)
-              (_lhsOtrefIDs,_) =
-                  __tup2
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 424, column 15)
-              (_,_lhsOfixedUpIdentifiersTree) =
-                  __tup2
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 55, column 9)
-              _lhsOannotatedTree =
-                  addTypeErrors _errs     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 106, column 9)
-              _errs =
-                  case _eqfunIdens of
-                    Left e -> e
-                    Right _ -> []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 112, column 9)
-              _eqfunIdens =
-                  funIdens _lhsIcat _aliasIoriginalTree _fnIannotatedTree _fnIuType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 113, column 9)
-              _lhsOlibUpdates =
-                  [LBTref "fn"
-                                  (fst _qfunIdens    )
-                                  (snd _qfunIdens    )
-                                  []]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 117, column 9)
-              _qfunIdens =
-                  fromRight ("",[]) _eqfunIdens
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 263, column 9)
-              _lhsOnewLib2 =
-                  createLocalBindings $ do
-                  (t,cs) <- etmt $ funIdens _lhsIcat _aliasIoriginalTree _fnIannotatedTree _fnIuType
-                  return [(t,map (second Just) cs)]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 279, column 9)
-              _backTree =
-                  FunTref ann_ _fnIannotatedTree _aliasIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 300, column 9)
-              _aliasOexpectedNumCols =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 117, column 15)
-              _fnOexpectedType =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  FunTref ann_ _fnIannotatedTree _aliasIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  FunTref ann_ _fnIfixedUpIdentifiersTree _aliasIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  FunTref ann_ _fnIoriginalTree _aliasIoriginalTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _fnOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _fnOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _fnOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _aliasOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _aliasOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _aliasOlib =
-                  _lhsIlib
-              ( _fnIannotatedTree,_fnIfixedUpIdentifiersTree,_fnIoriginalTree,_fnIuType) =
-                  fn_ _fnOcat _fnOexpectedType _fnOidenv _fnOlib 
-              ( _aliasIannotatedTree,_aliasIfixedUpIdentifiersTree,_aliasIoriginalTree) =
-                  alias_ _aliasOcat _aliasOexpectedNumCols _aliasOidenv _aliasOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOnewLib2,_lhsOoriginalTree,_lhsOtrefIDs)))
-sem_TableRef_JoinTref :: Annotation ->
-                         T_TableRef  ->
-                         Natural ->
-                         JoinType ->
-                         T_TableRef  ->
-                         T_OnExpr  ->
-                         T_TableAlias  ->
-                         T_TableRef 
-sem_TableRef_JoinTref ann_ tbl_ nat_ joinType_ tbl1_ onExpr_ alias_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOtrefIDs :: IDEnv
-              _onExprOidenv :: IDEnv
-              _lhsOfixedUpIdentifiersTree :: TableRef 
-              _lhsOannotatedTree :: TableRef 
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _newLib :: (Either [TypeError] LocalBindings)
-              _lhsOnewLib2 :: LocalBindings
-              _onExprOlib :: LocalBindings
-              _aliasOexpectedNumCols :: (Maybe Int)
-              _lhsOoriginalTree :: TableRef 
-              _tblOcat :: Catalog
-              _tblOidenv :: IDEnv
-              _tblOlib :: LocalBindings
-              _tbl1Ocat :: Catalog
-              _tbl1Oidenv :: IDEnv
-              _tbl1Olib :: LocalBindings
-              _onExprOcat :: Catalog
-              _aliasOcat :: Catalog
-              _aliasOidenv :: IDEnv
-              _aliasOlib :: LocalBindings
-              _tblIannotatedTree :: TableRef 
-              _tblIfixedUpIdentifiersTree :: TableRef 
-              _tblIlibUpdates :: ([LocalBindingsUpdate])
-              _tblInewLib2 :: LocalBindings
-              _tblIoriginalTree :: TableRef 
-              _tblItrefIDs :: IDEnv
-              _tbl1IannotatedTree :: TableRef 
-              _tbl1IfixedUpIdentifiersTree :: TableRef 
-              _tbl1IlibUpdates :: ([LocalBindingsUpdate])
-              _tbl1InewLib2 :: LocalBindings
-              _tbl1IoriginalTree :: TableRef 
-              _tbl1ItrefIDs :: IDEnv
-              _onExprIannotatedTree :: OnExpr 
-              _onExprIfixedUpIdentifiersTree :: OnExpr 
-              _onExprIoriginalTree :: OnExpr 
-              _aliasIannotatedTree :: TableAlias 
-              _aliasIfixedUpIdentifiersTree :: TableAlias 
-              _aliasIoriginalTree :: TableAlias 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 442, column 9)
-              _lhsOtrefIDs =
-                  _trefIDs
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 443, column 9)
-              _onExprOidenv =
-                  _trefIDs
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 460, column 9)
-              __tup3 =
-                  let t0ids = maybe [] id $ fmap (map snd) $ expandStar _tblItrefIDs Nothing
-                      t1ids = maybe [] id $ fmap (map snd) $ expandStar _tbl1ItrefIDs Nothing
-                      jids :: [String]
-                      jids = case (nat_,_onExprIoriginalTree) of
-                               (Natural,_) -> intersect t0ids t1ids
-                               (_,Just (JoinUsing _ fs)) -> map ncStr fs
-                               _ -> []
-                      iea = aliasEnv _aliasIoriginalTree
-                            $ JoinTrefIDEnv jids _tblItrefIDs _tbl1ItrefIDs
-                      al = getEnvAlias iea
-                  in (iea, JoinTref ann_ _tblIfixedUpIdentifiersTree
-                                    nat_ joinType_ _tbl1IfixedUpIdentifiersTree
-                                    _onExprIfixedUpIdentifiersTree al)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 460, column 9)
-              (_trefIDs,_) =
-                  __tup3
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 460, column 9)
-              (_,_lhsOfixedUpIdentifiersTree) =
-                  __tup3
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 55, column 9)
-              _lhsOannotatedTree =
-                  addTypeErrors _errs     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 122, column 9)
-              _errs =
-                  fromLeft [] _newLib
-                  ++ _joinErrors
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 124, column 9)
-              _lhsOlibUpdates =
-                  if _joinErrors     == []
-                  then _libUpdates
-                  else []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 129, column 9)
-              _joinErrors =
-                  fromLeft [] (foldM (flip $ lbUpdate _lhsIcat) _lhsIlib _libUpdates    )
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 130, column 9)
-              _libUpdates =
-                  case (_tblIlibUpdates, _tbl1IlibUpdates) of
-                    ([u1], [u2]) -> [LBJoinTref "join" u1 u2 jids
-                                                    (case _aliasIoriginalTree of
-                                                             NoAlias _ -> Nothing
-                                                             TableAlias _ t -> Just $ ncStr t
-                                                             FullAlias _ t _ -> Just $ ncStr t)]
-                    _ -> []
-                  where
-                    jids = case (nat_, _onExprIoriginalTree) of
-                                (Natural, _) -> Left ()
-                                (_,Just (JoinUsing _ s)) -> Right $ map ncStr s
-                                _ -> Right []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 144, column 9)
-              _newLib =
-                  case (_tblIlibUpdates, _tbl1IlibUpdates) of
-                    ([u1],[u2]) -> lbUpdate _lhsIcat
-                                     (LBJoinTref "join" u1 u2 (Right []) Nothing) _lhsIlib
-                    _ -> Right _lhsIlib
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 237, column 9)
-              _newLib2 =
-                  let t0t :: [(String,Maybe Type)]
-                      t0t = getUnqualifiedBindings _tblInewLib2
-                      t1t = getUnqualifiedBindings _tbl1InewLib2
-                  in case _aliasIoriginalTree of
-                    (FullAlias _ n cs) ->
-                        createLocalBindings $ Just [(ncStr n,zip (map ncStr cs) $ map snd (t0t ++ t1t))]
-                    (TableAlias _ n) ->
-                        createLocalBindings $ Just [(ncStr n, t0t ++ t1t)]
-                    NoAlias _ ->
-                        joinBindings _tblInewLib2 _tbl1InewLib2
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 250, column 9)
-              _lhsOnewLib2 =
-                  _newLib2
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 251, column 9)
-              _onExprOlib =
-                  _newLib2
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 281, column 9)
-              _backTree =
-                  JoinTref ann_
-                             _tblIannotatedTree
-                             nat_
-                             joinType_
-                             _tbl1IannotatedTree
-                             _onExprIannotatedTree
-                             _aliasIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 300, column 9)
-              _aliasOexpectedNumCols =
-                  Nothing
-              -- self rule
-              _annotatedTree =
-                  JoinTref ann_ _tblIannotatedTree nat_ joinType_ _tbl1IannotatedTree _onExprIannotatedTree _aliasIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  JoinTref ann_ _tblIfixedUpIdentifiersTree nat_ joinType_ _tbl1IfixedUpIdentifiersTree _onExprIfixedUpIdentifiersTree _aliasIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  JoinTref ann_ _tblIoriginalTree nat_ joinType_ _tbl1IoriginalTree _onExprIoriginalTree _aliasIoriginalTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _tblOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tblOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tblOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tbl1Ocat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tbl1Oidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tbl1Olib =
-                  _lhsIlib
-              -- copy rule (down)
-              _onExprOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _aliasOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _aliasOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _aliasOlib =
-                  _lhsIlib
-              ( _tblIannotatedTree,_tblIfixedUpIdentifiersTree,_tblIlibUpdates,_tblInewLib2,_tblIoriginalTree,_tblItrefIDs) =
-                  tbl_ _tblOcat _tblOidenv _tblOlib 
-              ( _tbl1IannotatedTree,_tbl1IfixedUpIdentifiersTree,_tbl1IlibUpdates,_tbl1InewLib2,_tbl1IoriginalTree,_tbl1ItrefIDs) =
-                  tbl1_ _tbl1Ocat _tbl1Oidenv _tbl1Olib 
-              ( _onExprIannotatedTree,_onExprIfixedUpIdentifiersTree,_onExprIoriginalTree) =
-                  onExpr_ _onExprOcat _onExprOidenv _onExprOlib 
-              ( _aliasIannotatedTree,_aliasIfixedUpIdentifiersTree,_aliasIoriginalTree) =
-                  alias_ _aliasOcat _aliasOexpectedNumCols _aliasOidenv _aliasOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOnewLib2,_lhsOoriginalTree,_lhsOtrefIDs)))
-sem_TableRef_SubTref :: Annotation ->
-                        T_QueryExpr  ->
-                        T_TableAlias  ->
-                        T_TableRef 
-sem_TableRef_SubTref ann_ sel_ alias_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let __tup4 :: ((IDEnv,TableRef))
-              _lhsOtrefIDs :: IDEnv
-              _lhsOfixedUpIdentifiersTree :: TableRef 
-              _selOcsql :: LocalBindings
-              _lhsOannotatedTree :: TableRef 
-              _selectAttrs :: (Either [TypeError] [(String,Type)])
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOnewLib2 :: LocalBindings
-              _aliasOexpectedNumCols :: (Maybe Int)
-              _selOexpectedTypes :: ([Maybe Type])
-              _lhsOoriginalTree :: TableRef 
-              _selOcat :: Catalog
-              _selOidenv :: IDEnv
-              _selOlib :: LocalBindings
-              _aliasOcat :: Catalog
-              _aliasOidenv :: IDEnv
-              _aliasOlib :: LocalBindings
-              _selIannotatedTree :: QueryExpr 
-              _selIcidenv :: IDEnv
-              _selIfixedUpIdentifiersTree :: QueryExpr 
-              _selIlibUpdates :: ([LocalBindingsUpdate])
-              _selIoriginalTree :: QueryExpr 
-              _selIuType :: (Maybe [(String,Type)])
-              _aliasIannotatedTree :: TableAlias 
-              _aliasIfixedUpIdentifiersTree :: TableAlias 
-              _aliasIoriginalTree :: TableAlias 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 412, column 15)
-              __tup4 =
-                  let iea = aliasEnv _aliasIoriginalTree  _selIcidenv
-                      al = getEnvAlias iea
-                  in (iea, SubTref ann_ _selIfixedUpIdentifiersTree al)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 412, column 15)
-              (_lhsOtrefIDs,_) =
-                  __tup4
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 412, column 15)
-              (_,_lhsOfixedUpIdentifiersTree) =
-                  __tup4
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 129, column 15)
-              _selOcsql =
-                  emptyBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 55, column 9)
-              _lhsOannotatedTree =
-                  addTypeErrors _errs     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 76, column 9)
-              _errs =
-                  case _selectAttrs     of
-                          Left e -> e
-                          Right _ -> []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 80, column 9)
-              _selectAttrs =
-                  lmt _selIuType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 81, column 9)
-              _lhsOlibUpdates =
-                  [LBTref "sub query" (getAlias "" _aliasIoriginalTree)
-                                  (fromRight [] _selectAttrs    ) []]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 254, column 9)
-              _lhsOnewLib2 =
-                  createLocalBindings $ do
-                  pu <- _selIuType
-                  let (n,cs) = case _aliasIoriginalTree of
-                                 (FullAlias _ n cs) -> (ncStr n,map ncStr cs)
-                                 _ -> (n, [])
-                  return [(n,zip cs $ map (Just . snd) pu)]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 275, column 9)
-              _backTree =
-                  SubTref ann_ _selIannotatedTree _aliasIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 300, column 9)
-              _aliasOexpectedNumCols =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 178, column 15)
-              _selOexpectedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  SubTref ann_ _selIannotatedTree _aliasIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  SubTref ann_ _selIfixedUpIdentifiersTree _aliasIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  SubTref ann_ _selIoriginalTree _aliasIoriginalTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _selOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _selOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _selOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _aliasOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _aliasOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _aliasOlib =
-                  _lhsIlib
-              ( _selIannotatedTree,_selIcidenv,_selIfixedUpIdentifiersTree,_selIlibUpdates,_selIoriginalTree,_selIuType) =
-                  sel_ _selOcat _selOcsql _selOexpectedTypes _selOidenv _selOlib 
-              ( _aliasIannotatedTree,_aliasIfixedUpIdentifiersTree,_aliasIoriginalTree) =
-                  alias_ _aliasOcat _aliasOexpectedNumCols _aliasOidenv _aliasOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOnewLib2,_lhsOoriginalTree,_lhsOtrefIDs)))
-sem_TableRef_Tref :: Annotation ->
-                     T_Name  ->
-                     T_TableAlias  ->
-                     T_TableRef 
-sem_TableRef_Tref ann_ tbl_ alias_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let __tup5 :: ((IDEnv,TableRef))
-              _lhsOtrefIDs :: IDEnv
-              _lhsOfixedUpIdentifiersTree :: TableRef 
-              _lhsOannotatedTree :: TableRef 
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOnewLib2 :: LocalBindings
-              _aliasOexpectedNumCols :: (Maybe Int)
-              _lhsOoriginalTree :: TableRef 
-              _tblOcat :: Catalog
-              _tblOidenv :: IDEnv
-              _tblOlib :: LocalBindings
-              _aliasOcat :: Catalog
-              _aliasOidenv :: IDEnv
-              _aliasOlib :: LocalBindings
-              _tblIannotatedTree :: Name 
-              _tblIfixedUpIdentifiersTree :: Name 
-              _tblIoriginalTree :: Name 
-              _tblItbAnnotatedTree :: Name 
-              _tblItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              _aliasIannotatedTree :: TableAlias 
-              _aliasIfixedUpIdentifiersTree :: TableAlias 
-              _aliasIoriginalTree :: TableAlias 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 399, column 12)
-              __tup5 =
-                  let iea = aliasEnv _aliasIoriginalTree $ getTableTrefEnv _lhsIcat _tblIoriginalTree
-                      al = getEnvAlias iea
-                  in (iea,Tref ann_ _tblIfixedUpIdentifiersTree al)
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 399, column 12)
-              (_lhsOtrefIDs,_) =
-                  __tup5
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 399, column 12)
-              (_,_lhsOfixedUpIdentifiersTree) =
-                  __tup5
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 55, column 9)
-              _lhsOannotatedTree =
-                  addTypeErrors _errs     _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 89, column 9)
-              _errs =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 90, column 9)
-              _lhsOlibUpdates =
-                  maybe [] id $ do
-                  let n = getTName _tblIannotatedTree
-                  (pu,pr) <- _tblItbUType
-                  return [LBTref ("tref: " ++ n)
-                            (getAlias n _aliasIoriginalTree)
-                            pu
-                            pr]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 225, column 9)
-              _lhsOnewLib2 =
-                  createLocalBindings $ do
-                  let n = getTName _tblIannotatedTree
-                  (pu,pr) <- _tblItbUType
-                  let (n,cs) = case _aliasIoriginalTree of
-                                 (FullAlias _ n cs) -> (ncStr n,map ncStr cs)
-                                 _ -> (n, [])
-                  return [(n,zip cs $ map (Just . snd) pu)
-                         ,(n,map (second Just) pr)]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 277, column 9)
-              _backTree =
-                  Tref ann_ _tblItbAnnotatedTree _aliasIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 294, column 9)
-              _aliasOexpectedNumCols =
-                  do
-                  let n = getTName _tblIannotatedTree
-                  (pu,_) <- _tblItbUType
-                  return $ length pu
-              -- self rule
-              _annotatedTree =
-                  Tref ann_ _tblIannotatedTree _aliasIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Tref ann_ _tblIfixedUpIdentifiersTree _aliasIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  Tref ann_ _tblIoriginalTree _aliasIoriginalTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _tblOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tblOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tblOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _aliasOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _aliasOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _aliasOlib =
-                  _lhsIlib
-              ( _tblIannotatedTree,_tblIfixedUpIdentifiersTree,_tblIoriginalTree,_tblItbAnnotatedTree,_tblItbUType) =
-                  tbl_ _tblOcat _tblOidenv _tblOlib 
-              ( _aliasIannotatedTree,_aliasIfixedUpIdentifiersTree,_aliasIoriginalTree) =
-                  alias_ _aliasOcat _aliasOexpectedNumCols _aliasOidenv _aliasOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOnewLib2,_lhsOoriginalTree,_lhsOtrefIDs)))
--- TableRefList ------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         libUpdates           : [LocalBindingsUpdate]
-         newLib2              : LocalBindings
-         originalTree         : SELF 
-         trefIDs              : IDEnv
-   alternatives:
-      alternative Cons:
-         child hd             : TableRef 
-         child tl             : TableRefList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type TableRefList  = [TableRef ]
--- cata
-sem_TableRefList :: TableRefList  ->
-                    T_TableRefList 
-sem_TableRefList list  =
-    (Prelude.foldr sem_TableRefList_Cons sem_TableRefList_Nil (Prelude.map sem_TableRef list) )
--- semantic domain
-type T_TableRefList  = Catalog ->
-                       IDEnv ->
-                       LocalBindings ->
-                       ( TableRefList ,TableRefList ,([LocalBindingsUpdate]),LocalBindings,TableRefList ,IDEnv)
-data Inh_TableRefList  = Inh_TableRefList {cat_Inh_TableRefList :: Catalog,idenv_Inh_TableRefList :: IDEnv,lib_Inh_TableRefList :: LocalBindings}
-data Syn_TableRefList  = Syn_TableRefList {annotatedTree_Syn_TableRefList :: TableRefList ,fixedUpIdentifiersTree_Syn_TableRefList :: TableRefList ,libUpdates_Syn_TableRefList :: ([LocalBindingsUpdate]),newLib2_Syn_TableRefList :: LocalBindings,originalTree_Syn_TableRefList :: TableRefList ,trefIDs_Syn_TableRefList :: IDEnv}
-wrap_TableRefList :: T_TableRefList  ->
-                     Inh_TableRefList  ->
-                     Syn_TableRefList 
-wrap_TableRefList sem (Inh_TableRefList _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOnewLib2,_lhsOoriginalTree,_lhsOtrefIDs) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_TableRefList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOlibUpdates _lhsOnewLib2 _lhsOoriginalTree _lhsOtrefIDs ))
-sem_TableRefList_Cons :: T_TableRef  ->
-                         T_TableRefList  ->
-                         T_TableRefList 
-sem_TableRefList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOtrefIDs :: IDEnv
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOnewLib2 :: LocalBindings
-              _lhsOannotatedTree :: TableRefList 
-              _lhsOfixedUpIdentifiersTree :: TableRefList 
-              _lhsOoriginalTree :: TableRefList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: TableRef 
-              _hdIfixedUpIdentifiersTree :: TableRef 
-              _hdIlibUpdates :: ([LocalBindingsUpdate])
-              _hdInewLib2 :: LocalBindings
-              _hdIoriginalTree :: TableRef 
-              _hdItrefIDs :: IDEnv
-              _tlIannotatedTree :: TableRefList 
-              _tlIfixedUpIdentifiersTree :: TableRefList 
-              _tlIlibUpdates :: ([LocalBindingsUpdate])
-              _tlInewLib2 :: LocalBindings
-              _tlIoriginalTree :: TableRefList 
-              _tlItrefIDs :: IDEnv
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 383, column 12)
-              _lhsOtrefIDs =
-                  JoinTrefIDEnv [] _hdItrefIDs _tlItrefIDs
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 61, column 9)
-              _lhsOlibUpdates =
-                  _hdIlibUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 221, column 9)
-              _lhsOnewLib2 =
-                  joinBindings _hdInewLib2 _tlInewLib2
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIfixedUpIdentifiersTree,_hdIlibUpdates,_hdInewLib2,_hdIoriginalTree,_hdItrefIDs) =
-                  hd_ _hdOcat _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIfixedUpIdentifiersTree,_tlIlibUpdates,_tlInewLib2,_tlIoriginalTree,_tlItrefIDs) =
-                  tl_ _tlOcat _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOnewLib2,_lhsOoriginalTree,_lhsOtrefIDs)))
-sem_TableRefList_Nil :: T_TableRefList 
-sem_TableRefList_Nil  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOtrefIDs :: IDEnv
-              _lhsOlibUpdates :: ([LocalBindingsUpdate])
-              _lhsOnewLib2 :: LocalBindings
-              _lhsOannotatedTree :: TableRefList 
-              _lhsOfixedUpIdentifiersTree :: TableRefList 
-              _lhsOoriginalTree :: TableRefList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 384, column 11)
-              _lhsOtrefIDs =
-                  emptyIDEnv "empty tref list"
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 59, column 9)
-              _lhsOlibUpdates =
-                  []
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 219, column 9)
-              _lhsOnewLib2 =
-                  createLocalBindings $ Just []
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOlibUpdates,_lhsOnewLib2,_lhsOoriginalTree,_lhsOtrefIDs)))
--- TypeAttributeDef --------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         attrName             : String
-         fixedUpIdentifiersTree : SELF 
-         namedType            : Maybe Type
-         originalTree         : SELF 
-   alternatives:
-      alternative TypeAttDef:
-         child ann            : {Annotation}
-         child name           : {NameComponent}
-         child typ            : TypeName 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data TypeAttributeDef  = TypeAttDef (Annotation) (NameComponent) (TypeName ) 
-                       deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_TypeAttributeDef :: TypeAttributeDef  ->
-                        T_TypeAttributeDef 
-sem_TypeAttributeDef (TypeAttDef _ann _name _typ )  =
-    (sem_TypeAttributeDef_TypeAttDef _ann _name (sem_TypeName _typ ) )
--- semantic domain
-type T_TypeAttributeDef  = Catalog ->
-                           IDEnv ->
-                           LocalBindings ->
-                           ( TypeAttributeDef ,String,TypeAttributeDef ,(Maybe Type),TypeAttributeDef )
-data Inh_TypeAttributeDef  = Inh_TypeAttributeDef {cat_Inh_TypeAttributeDef :: Catalog,idenv_Inh_TypeAttributeDef :: IDEnv,lib_Inh_TypeAttributeDef :: LocalBindings}
-data Syn_TypeAttributeDef  = Syn_TypeAttributeDef {annotatedTree_Syn_TypeAttributeDef :: TypeAttributeDef ,attrName_Syn_TypeAttributeDef :: String,fixedUpIdentifiersTree_Syn_TypeAttributeDef :: TypeAttributeDef ,namedType_Syn_TypeAttributeDef :: (Maybe Type),originalTree_Syn_TypeAttributeDef :: TypeAttributeDef }
-wrap_TypeAttributeDef :: T_TypeAttributeDef  ->
-                         Inh_TypeAttributeDef  ->
-                         Syn_TypeAttributeDef 
-wrap_TypeAttributeDef sem (Inh_TypeAttributeDef _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOattrName,_lhsOfixedUpIdentifiersTree,_lhsOnamedType,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_TypeAttributeDef _lhsOannotatedTree _lhsOattrName _lhsOfixedUpIdentifiersTree _lhsOnamedType _lhsOoriginalTree ))
-sem_TypeAttributeDef_TypeAttDef :: Annotation ->
-                                   NameComponent ->
-                                   T_TypeName  ->
-                                   T_TypeAttributeDef 
-sem_TypeAttributeDef_TypeAttDef ann_ name_ typ_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOattrName :: String
-              _lhsOnamedType :: (Maybe Type)
-              _lhsOannotatedTree :: TypeAttributeDef 
-              _lhsOfixedUpIdentifiersTree :: TypeAttributeDef 
-              _lhsOoriginalTree :: TypeAttributeDef 
-              _typOcat :: Catalog
-              _typOidenv :: IDEnv
-              _typOlib :: LocalBindings
-              _typIannotatedTree :: TypeName 
-              _typIfixedUpIdentifiersTree :: TypeName 
-              _typInamedType :: (Maybe Type)
-              _typIoriginalTree :: TypeName 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 37, column 9)
-              _lhsOattrName =
-                  ncStr name_
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 38, column 9)
-              _lhsOnamedType =
-                  _typInamedType
-              -- self rule
-              _annotatedTree =
-                  TypeAttDef ann_ name_ _typIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  TypeAttDef ann_ name_ _typIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  TypeAttDef ann_ name_ _typIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _typOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _typOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _typOlib =
-                  _lhsIlib
-              ( _typIannotatedTree,_typIfixedUpIdentifiersTree,_typInamedType,_typIoriginalTree) =
-                  typ_ _typOcat _typOidenv _typOlib 
-          in  ( _lhsOannotatedTree,_lhsOattrName,_lhsOfixedUpIdentifiersTree,_lhsOnamedType,_lhsOoriginalTree)))
--- TypeAttributeDefList ----------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         attrs                : [(String, Maybe Type)]
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative Cons:
-         child hd             : TypeAttributeDef 
-         child tl             : TypeAttributeDefList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type TypeAttributeDefList  = [TypeAttributeDef ]
--- cata
-sem_TypeAttributeDefList :: TypeAttributeDefList  ->
-                            T_TypeAttributeDefList 
-sem_TypeAttributeDefList list  =
-    (Prelude.foldr sem_TypeAttributeDefList_Cons sem_TypeAttributeDefList_Nil (Prelude.map sem_TypeAttributeDef list) )
--- semantic domain
-type T_TypeAttributeDefList  = Catalog ->
-                               IDEnv ->
-                               LocalBindings ->
-                               ( TypeAttributeDefList ,([(String, Maybe Type)]),TypeAttributeDefList ,TypeAttributeDefList )
-data Inh_TypeAttributeDefList  = Inh_TypeAttributeDefList {cat_Inh_TypeAttributeDefList :: Catalog,idenv_Inh_TypeAttributeDefList :: IDEnv,lib_Inh_TypeAttributeDefList :: LocalBindings}
-data Syn_TypeAttributeDefList  = Syn_TypeAttributeDefList {annotatedTree_Syn_TypeAttributeDefList :: TypeAttributeDefList ,attrs_Syn_TypeAttributeDefList :: ([(String, Maybe Type)]),fixedUpIdentifiersTree_Syn_TypeAttributeDefList :: TypeAttributeDefList ,originalTree_Syn_TypeAttributeDefList :: TypeAttributeDefList }
-wrap_TypeAttributeDefList :: T_TypeAttributeDefList  ->
-                             Inh_TypeAttributeDefList  ->
-                             Syn_TypeAttributeDefList 
-wrap_TypeAttributeDefList sem (Inh_TypeAttributeDefList _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOattrs,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_TypeAttributeDefList _lhsOannotatedTree _lhsOattrs _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_TypeAttributeDefList_Cons :: T_TypeAttributeDef  ->
-                                 T_TypeAttributeDefList  ->
-                                 T_TypeAttributeDefList 
-sem_TypeAttributeDefList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOattrs :: ([(String, Maybe Type)])
-              _lhsOannotatedTree :: TypeAttributeDefList 
-              _lhsOfixedUpIdentifiersTree :: TypeAttributeDefList 
-              _lhsOoriginalTree :: TypeAttributeDefList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: TypeAttributeDef 
-              _hdIattrName :: String
-              _hdIfixedUpIdentifiersTree :: TypeAttributeDef 
-              _hdInamedType :: (Maybe Type)
-              _hdIoriginalTree :: TypeAttributeDef 
-              _tlIannotatedTree :: TypeAttributeDefList 
-              _tlIattrs :: ([(String, Maybe Type)])
-              _tlIfixedUpIdentifiersTree :: TypeAttributeDefList 
-              _tlIoriginalTree :: TypeAttributeDefList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 43, column 12)
-              _lhsOattrs =
-                  (_hdIattrName, _hdInamedType) : _tlIattrs
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIattrName,_hdIfixedUpIdentifiersTree,_hdInamedType,_hdIoriginalTree) =
-                  hd_ _hdOcat _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIattrs,_tlIfixedUpIdentifiersTree,_tlIoriginalTree) =
-                  tl_ _tlOcat _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOattrs,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_TypeAttributeDefList_Nil :: T_TypeAttributeDefList 
-sem_TypeAttributeDefList_Nil  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOattrs :: ([(String, Maybe Type)])
-              _lhsOannotatedTree :: TypeAttributeDefList 
-              _lhsOfixedUpIdentifiersTree :: TypeAttributeDefList 
-              _lhsOoriginalTree :: TypeAttributeDefList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/MiscCreates.ag"(line 44, column 11)
-              _lhsOattrs =
-                  []
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOattrs,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- TypeName ----------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         namedType            : Maybe Type
-         originalTree         : SELF 
-   alternatives:
-      alternative ArrayTypeName:
-         child ann            : {Annotation}
-         child typ            : TypeName 
-         visit 0:
-            local tpe         : _
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Prec2TypeName:
-         child ann            : {Annotation}
-         child tn             : {String}
-         child prec           : {Integer}
-         child prec1          : {Integer}
-         visit 0:
-            local tpe         : _
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative PrecTypeName:
-         child ann            : {Annotation}
-         child tn             : {String}
-         child prec           : {Integer}
-         visit 0:
-            local tpe         : _
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative SetOfTypeName:
-         child ann            : {Annotation}
-         child typ            : TypeName 
-         visit 0:
-            local tpe         : _
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative SimpleTypeName:
-         child ann            : {Annotation}
-         child tn             : {String}
-         visit 0:
-            local tpe         : _
-            local backTree    : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data TypeName  = ArrayTypeName (Annotation) (TypeName ) 
-               | Prec2TypeName (Annotation) (String) (Integer) (Integer) 
-               | PrecTypeName (Annotation) (String) (Integer) 
-               | SetOfTypeName (Annotation) (TypeName ) 
-               | SimpleTypeName (Annotation) (String) 
-               deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_TypeName :: TypeName  ->
-                T_TypeName 
-sem_TypeName (ArrayTypeName _ann _typ )  =
-    (sem_TypeName_ArrayTypeName _ann (sem_TypeName _typ ) )
-sem_TypeName (Prec2TypeName _ann _tn _prec _prec1 )  =
-    (sem_TypeName_Prec2TypeName _ann _tn _prec _prec1 )
-sem_TypeName (PrecTypeName _ann _tn _prec )  =
-    (sem_TypeName_PrecTypeName _ann _tn _prec )
-sem_TypeName (SetOfTypeName _ann _typ )  =
-    (sem_TypeName_SetOfTypeName _ann (sem_TypeName _typ ) )
-sem_TypeName (SimpleTypeName _ann _tn )  =
-    (sem_TypeName_SimpleTypeName _ann _tn )
--- semantic domain
-type T_TypeName  = Catalog ->
-                   IDEnv ->
-                   LocalBindings ->
-                   ( TypeName ,TypeName ,(Maybe Type),TypeName )
-data Inh_TypeName  = Inh_TypeName {cat_Inh_TypeName :: Catalog,idenv_Inh_TypeName :: IDEnv,lib_Inh_TypeName :: LocalBindings}
-data Syn_TypeName  = Syn_TypeName {annotatedTree_Syn_TypeName :: TypeName ,fixedUpIdentifiersTree_Syn_TypeName :: TypeName ,namedType_Syn_TypeName :: (Maybe Type),originalTree_Syn_TypeName :: TypeName }
-wrap_TypeName :: T_TypeName  ->
-                 Inh_TypeName  ->
-                 Syn_TypeName 
-wrap_TypeName sem (Inh_TypeName _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOnamedType,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_TypeName _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOnamedType _lhsOoriginalTree ))
-sem_TypeName_ArrayTypeName :: Annotation ->
-                              T_TypeName  ->
-                              T_TypeName 
-sem_TypeName_ArrayTypeName ann_ typ_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOnamedType :: (Maybe Type)
-              _lhsOannotatedTree :: TypeName 
-              _lhsOfixedUpIdentifiersTree :: TypeName 
-              _lhsOoriginalTree :: TypeName 
-              _typOcat :: Catalog
-              _typOidenv :: IDEnv
-              _typOlib :: LocalBindings
-              _typIannotatedTree :: TypeName 
-              _typIfixedUpIdentifiersTree :: TypeName 
-              _typInamedType :: (Maybe Type)
-              _typIoriginalTree :: TypeName 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 19, column 10)
-              _lhsOnamedType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 20, column 10)
-              _lhsOannotatedTree =
-                  addTypeErrors (tes _tpe    ) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 27, column 9)
-              _tpe =
-                  lmt _typInamedType >>=  Right . ArrayType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 28, column 9)
-              _backTree =
-                  ArrayTypeName ann_ _typIannotatedTree
-              -- self rule
-              _annotatedTree =
-                  ArrayTypeName ann_ _typIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  ArrayTypeName ann_ _typIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  ArrayTypeName ann_ _typIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _typOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _typOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _typOlib =
-                  _lhsIlib
-              ( _typIannotatedTree,_typIfixedUpIdentifiersTree,_typInamedType,_typIoriginalTree) =
-                  typ_ _typOcat _typOidenv _typOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOnamedType,_lhsOoriginalTree)))
-sem_TypeName_Prec2TypeName :: Annotation ->
-                              String ->
-                              Integer ->
-                              Integer ->
-                              T_TypeName 
-sem_TypeName_Prec2TypeName ann_ tn_ prec_ prec1_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOnamedType :: (Maybe Type)
-              _lhsOannotatedTree :: TypeName 
-              _lhsOfixedUpIdentifiersTree :: TypeName 
-              _lhsOoriginalTree :: TypeName 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 19, column 10)
-              _lhsOnamedType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 20, column 10)
-              _lhsOannotatedTree =
-                  addTypeErrors (tes _tpe    ) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 36, column 9)
-              _tpe =
-                  catLookupType _lhsIcat $ canonicalizeTypeName tn_
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 37, column 9)
-              _backTree =
-                  Prec2TypeName ann_ tn_ prec_ prec1_
-              -- self rule
-              _annotatedTree =
-                  Prec2TypeName ann_ tn_ prec_ prec1_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  Prec2TypeName ann_ tn_ prec_ prec1_
-              -- self rule
-              _originalTree =
-                  Prec2TypeName ann_ tn_ prec_ prec1_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOnamedType,_lhsOoriginalTree)))
-sem_TypeName_PrecTypeName :: Annotation ->
-                             String ->
-                             Integer ->
-                             T_TypeName 
-sem_TypeName_PrecTypeName ann_ tn_ prec_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOnamedType :: (Maybe Type)
-              _lhsOannotatedTree :: TypeName 
-              _lhsOfixedUpIdentifiersTree :: TypeName 
-              _lhsOoriginalTree :: TypeName 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 19, column 10)
-              _lhsOnamedType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 20, column 10)
-              _lhsOannotatedTree =
-                  addTypeErrors (tes _tpe    ) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 33, column 9)
-              _tpe =
-                  catLookupType _lhsIcat $ canonicalizeTypeName tn_
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 34, column 9)
-              _backTree =
-                  PrecTypeName ann_ tn_ prec_
-              -- self rule
-              _annotatedTree =
-                  PrecTypeName ann_ tn_ prec_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  PrecTypeName ann_ tn_ prec_
-              -- self rule
-              _originalTree =
-                  PrecTypeName ann_ tn_ prec_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOnamedType,_lhsOoriginalTree)))
-sem_TypeName_SetOfTypeName :: Annotation ->
-                              T_TypeName  ->
-                              T_TypeName 
-sem_TypeName_SetOfTypeName ann_ typ_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOnamedType :: (Maybe Type)
-              _lhsOannotatedTree :: TypeName 
-              _lhsOfixedUpIdentifiersTree :: TypeName 
-              _lhsOoriginalTree :: TypeName 
-              _typOcat :: Catalog
-              _typOidenv :: IDEnv
-              _typOlib :: LocalBindings
-              _typIannotatedTree :: TypeName 
-              _typIfixedUpIdentifiersTree :: TypeName 
-              _typInamedType :: (Maybe Type)
-              _typIoriginalTree :: TypeName 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 19, column 10)
-              _lhsOnamedType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 20, column 10)
-              _lhsOannotatedTree =
-                  addTypeErrors (tes _tpe    ) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 30, column 9)
-              _tpe =
-                  lmt _typInamedType >>=  Right . SetOfType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 31, column 9)
-              _backTree =
-                  SetOfTypeName ann_ _typIannotatedTree
-              -- self rule
-              _annotatedTree =
-                  SetOfTypeName ann_ _typIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  SetOfTypeName ann_ _typIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  SetOfTypeName ann_ _typIoriginalTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _typOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _typOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _typOlib =
-                  _lhsIlib
-              ( _typIannotatedTree,_typIfixedUpIdentifiersTree,_typInamedType,_typIoriginalTree) =
-                  typ_ _typOcat _typOidenv _typOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOnamedType,_lhsOoriginalTree)))
-sem_TypeName_SimpleTypeName :: Annotation ->
-                               String ->
-                               T_TypeName 
-sem_TypeName_SimpleTypeName ann_ tn_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOnamedType :: (Maybe Type)
-              _lhsOannotatedTree :: TypeName 
-              _lhsOfixedUpIdentifiersTree :: TypeName 
-              _lhsOoriginalTree :: TypeName 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 19, column 10)
-              _lhsOnamedType =
-                  etmt _tpe
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 20, column 10)
-              _lhsOannotatedTree =
-                  addTypeErrors (tes _tpe    ) _backTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 24, column 9)
-              _tpe =
-                  catLookupType _lhsIcat $ canonicalizeTypeName tn_
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 25, column 9)
-              _backTree =
-                  SimpleTypeName ann_ tn_
-              -- self rule
-              _annotatedTree =
-                  SimpleTypeName ann_ tn_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  SimpleTypeName ann_ tn_
-              -- self rule
-              _originalTree =
-                  SimpleTypeName ann_ tn_
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOnamedType,_lhsOoriginalTree)))
--- TypeNameList ------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         fixedUpIdentifiersTree : SELF 
-         namedTypes           : [Maybe Type]
-         originalTree         : SELF 
-   alternatives:
-      alternative Cons:
-         child hd             : TypeName 
-         child tl             : TypeNameList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type TypeNameList  = [TypeName ]
--- cata
-sem_TypeNameList :: TypeNameList  ->
-                    T_TypeNameList 
-sem_TypeNameList list  =
-    (Prelude.foldr sem_TypeNameList_Cons sem_TypeNameList_Nil (Prelude.map sem_TypeName list) )
--- semantic domain
-type T_TypeNameList  = Catalog ->
-                       IDEnv ->
-                       LocalBindings ->
-                       ( TypeNameList ,TypeNameList ,([Maybe Type]),TypeNameList )
-data Inh_TypeNameList  = Inh_TypeNameList {cat_Inh_TypeNameList :: Catalog,idenv_Inh_TypeNameList :: IDEnv,lib_Inh_TypeNameList :: LocalBindings}
-data Syn_TypeNameList  = Syn_TypeNameList {annotatedTree_Syn_TypeNameList :: TypeNameList ,fixedUpIdentifiersTree_Syn_TypeNameList :: TypeNameList ,namedTypes_Syn_TypeNameList :: ([Maybe Type]),originalTree_Syn_TypeNameList :: TypeNameList }
-wrap_TypeNameList :: T_TypeNameList  ->
-                     Inh_TypeNameList  ->
-                     Syn_TypeNameList 
-wrap_TypeNameList sem (Inh_TypeNameList _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOnamedTypes,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_TypeNameList _lhsOannotatedTree _lhsOfixedUpIdentifiersTree _lhsOnamedTypes _lhsOoriginalTree ))
-sem_TypeNameList_Cons :: T_TypeName  ->
-                         T_TypeNameList  ->
-                         T_TypeNameList 
-sem_TypeNameList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOnamedTypes :: ([Maybe Type])
-              _lhsOannotatedTree :: TypeNameList 
-              _lhsOfixedUpIdentifiersTree :: TypeNameList 
-              _lhsOoriginalTree :: TypeNameList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: TypeName 
-              _hdIfixedUpIdentifiersTree :: TypeName 
-              _hdInamedType :: (Maybe Type)
-              _hdIoriginalTree :: TypeName 
-              _tlIannotatedTree :: TypeNameList 
-              _tlIfixedUpIdentifiersTree :: TypeNameList 
-              _tlInamedTypes :: ([Maybe Type])
-              _tlIoriginalTree :: TypeNameList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/Drops.ag"(line 37, column 12)
-              _lhsOnamedTypes =
-                  _hdInamedType : _tlInamedTypes
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIfixedUpIdentifiersTree,_hdInamedType,_hdIoriginalTree) =
-                  hd_ _hdOcat _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIfixedUpIdentifiersTree,_tlInamedTypes,_tlIoriginalTree) =
-                  tl_ _tlOcat _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOnamedTypes,_lhsOoriginalTree)))
-sem_TypeNameList_Nil :: T_TypeNameList 
-sem_TypeNameList_Nil  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOnamedTypes :: ([Maybe Type])
-              _lhsOannotatedTree :: TypeNameList 
-              _lhsOfixedUpIdentifiersTree :: TypeNameList 
-              _lhsOoriginalTree :: TypeNameList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Ddl/Drops.ag"(line 38, column 11)
-              _lhsOnamedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOfixedUpIdentifiersTree,_lhsOnamedTypes,_lhsOoriginalTree)))
--- VarDef ------------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         def                  : (String,Maybe Type)
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative ParamAlias:
-         child ann            : {Annotation}
-         child name           : {NameComponent}
-         child i              : {Integer}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative VarAlias:
-         child ann            : {Annotation}
-         child name           : {NameComponent}
-         child aliased        : Name 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative VarDef:
-         child ann            : {Annotation}
-         child name           : {NameComponent}
-         child typ            : TypeName 
-         child value          : {Maybe ScalarExpr}
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data VarDef  = ParamAlias (Annotation) (NameComponent) (Integer) 
-             | VarAlias (Annotation) (NameComponent) (Name ) 
-             | VarDef (Annotation) (NameComponent) (TypeName ) ((Maybe ScalarExpr)) 
-             deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_VarDef :: VarDef  ->
-              T_VarDef 
-sem_VarDef (ParamAlias _ann _name _i )  =
-    (sem_VarDef_ParamAlias _ann _name _i )
-sem_VarDef (VarAlias _ann _name _aliased )  =
-    (sem_VarDef_VarAlias _ann _name (sem_Name _aliased ) )
-sem_VarDef (VarDef _ann _name _typ _value )  =
-    (sem_VarDef_VarDef _ann _name (sem_TypeName _typ ) _value )
--- semantic domain
-type T_VarDef  = Catalog ->
-                 IDEnv ->
-                 LocalBindings ->
-                 ( VarDef ,((String,Maybe Type)),VarDef ,VarDef )
-data Inh_VarDef  = Inh_VarDef {cat_Inh_VarDef :: Catalog,idenv_Inh_VarDef :: IDEnv,lib_Inh_VarDef :: LocalBindings}
-data Syn_VarDef  = Syn_VarDef {annotatedTree_Syn_VarDef :: VarDef ,def_Syn_VarDef :: ((String,Maybe Type)),fixedUpIdentifiersTree_Syn_VarDef :: VarDef ,originalTree_Syn_VarDef :: VarDef }
-wrap_VarDef :: T_VarDef  ->
-               Inh_VarDef  ->
-               Syn_VarDef 
-wrap_VarDef sem (Inh_VarDef _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOdef,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_VarDef _lhsOannotatedTree _lhsOdef _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_VarDef_ParamAlias :: Annotation ->
-                         NameComponent ->
-                         Integer ->
-                         T_VarDef 
-sem_VarDef_ParamAlias ann_ name_ i_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOdef :: ((String,Maybe Type))
-              _lhsOannotatedTree :: VarDef 
-              _lhsOfixedUpIdentifiersTree :: VarDef 
-              _lhsOoriginalTree :: VarDef 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Block.ag"(line 14, column 18)
-              _lhsOdef =
-                  (ncStr name_, Nothing)
-              -- self rule
-              _annotatedTree =
-                  ParamAlias ann_ name_ i_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  ParamAlias ann_ name_ i_
-              -- self rule
-              _originalTree =
-                  ParamAlias ann_ name_ i_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOdef,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_VarDef_VarAlias :: Annotation ->
-                       NameComponent ->
-                       T_Name  ->
-                       T_VarDef 
-sem_VarDef_VarAlias ann_ name_ aliased_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOdef :: ((String,Maybe Type))
-              _lhsOannotatedTree :: VarDef 
-              _lhsOfixedUpIdentifiersTree :: VarDef 
-              _lhsOoriginalTree :: VarDef 
-              _aliasedOcat :: Catalog
-              _aliasedOidenv :: IDEnv
-              _aliasedOlib :: LocalBindings
-              _aliasedIannotatedTree :: Name 
-              _aliasedIfixedUpIdentifiersTree :: Name 
-              _aliasedIoriginalTree :: Name 
-              _aliasedItbAnnotatedTree :: Name 
-              _aliasedItbUType :: (Maybe ([(String,Type)],[(String,Type)]))
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Block.ag"(line 13, column 16)
-              _lhsOdef =
-                  (ncStr name_, Nothing)
-              -- self rule
-              _annotatedTree =
-                  VarAlias ann_ name_ _aliasedIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  VarAlias ann_ name_ _aliasedIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  VarAlias ann_ name_ _aliasedIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _aliasedOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _aliasedOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _aliasedOlib =
-                  _lhsIlib
-              ( _aliasedIannotatedTree,_aliasedIfixedUpIdentifiersTree,_aliasedIoriginalTree,_aliasedItbAnnotatedTree,_aliasedItbUType) =
-                  aliased_ _aliasedOcat _aliasedOidenv _aliasedOlib 
-          in  ( _lhsOannotatedTree,_lhsOdef,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_VarDef_VarDef :: Annotation ->
-                     NameComponent ->
-                     T_TypeName  ->
-                     (Maybe ScalarExpr) ->
-                     T_VarDef 
-sem_VarDef_VarDef ann_ name_ typ_ value_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOdef :: ((String,Maybe Type))
-              _lhsOannotatedTree :: VarDef 
-              _lhsOfixedUpIdentifiersTree :: VarDef 
-              _lhsOoriginalTree :: VarDef 
-              _typOcat :: Catalog
-              _typOidenv :: IDEnv
-              _typOlib :: LocalBindings
-              _typIannotatedTree :: TypeName 
-              _typIfixedUpIdentifiersTree :: TypeName 
-              _typInamedType :: (Maybe Type)
-              _typIoriginalTree :: TypeName 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Block.ag"(line 10, column 14)
-              _lhsOdef =
-                  (ncStr name_, if _typInamedType == Just (Pseudo Record)
-                                then Just (PgRecord Nothing)
-                                else _typInamedType)
-              -- self rule
-              _annotatedTree =
-                  VarDef ann_ name_ _typIannotatedTree value_
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  VarDef ann_ name_ _typIfixedUpIdentifiersTree value_
-              -- self rule
-              _originalTree =
-                  VarDef ann_ name_ _typIoriginalTree value_
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _typOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _typOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _typOlib =
-                  _lhsIlib
-              ( _typIannotatedTree,_typIfixedUpIdentifiersTree,_typInamedType,_typIoriginalTree) =
-                  typ_ _typOcat _typOidenv _typOlib 
-          in  ( _lhsOannotatedTree,_lhsOdef,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- VarDefList --------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         defs                 : [(String,Maybe Type)]
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative Cons:
-         child hd             : VarDef 
-         child tl             : VarDefList 
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type VarDefList  = [VarDef ]
--- cata
-sem_VarDefList :: VarDefList  ->
-                  T_VarDefList 
-sem_VarDefList list  =
-    (Prelude.foldr sem_VarDefList_Cons sem_VarDefList_Nil (Prelude.map sem_VarDef list) )
--- semantic domain
-type T_VarDefList  = Catalog ->
-                     IDEnv ->
-                     LocalBindings ->
-                     ( VarDefList ,([(String,Maybe Type)]),VarDefList ,VarDefList )
-data Inh_VarDefList  = Inh_VarDefList {cat_Inh_VarDefList :: Catalog,idenv_Inh_VarDefList :: IDEnv,lib_Inh_VarDefList :: LocalBindings}
-data Syn_VarDefList  = Syn_VarDefList {annotatedTree_Syn_VarDefList :: VarDefList ,defs_Syn_VarDefList :: ([(String,Maybe Type)]),fixedUpIdentifiersTree_Syn_VarDefList :: VarDefList ,originalTree_Syn_VarDefList :: VarDefList }
-wrap_VarDefList :: T_VarDefList  ->
-                   Inh_VarDefList  ->
-                   Syn_VarDefList 
-wrap_VarDefList sem (Inh_VarDefList _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOdefs,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_VarDefList _lhsOannotatedTree _lhsOdefs _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_VarDefList_Cons :: T_VarDef  ->
-                       T_VarDefList  ->
-                       T_VarDefList 
-sem_VarDefList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOdefs :: ([(String,Maybe Type)])
-              _lhsOannotatedTree :: VarDefList 
-              _lhsOfixedUpIdentifiersTree :: VarDefList 
-              _lhsOoriginalTree :: VarDefList 
-              _hdOcat :: Catalog
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOcat :: Catalog
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: VarDef 
-              _hdIdef :: ((String,Maybe Type))
-              _hdIfixedUpIdentifiersTree :: VarDef 
-              _hdIoriginalTree :: VarDef 
-              _tlIannotatedTree :: VarDefList 
-              _tlIdefs :: ([(String,Maybe Type)])
-              _tlIfixedUpIdentifiersTree :: VarDefList 
-              _tlIoriginalTree :: VarDefList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Block.ag"(line 17, column 12)
-              _lhsOdefs =
-                  _hdIdef : _tlIdefs
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIdef,_hdIfixedUpIdentifiersTree,_hdIoriginalTree) =
-                  hd_ _hdOcat _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIdefs,_tlIfixedUpIdentifiersTree,_tlIoriginalTree) =
-                  tl_ _tlOcat _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOdefs,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
-sem_VarDefList_Nil :: T_VarDefList 
-sem_VarDefList_Nil  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOdefs :: ([(String,Maybe Type)])
-              _lhsOannotatedTree :: VarDefList 
-              _lhsOfixedUpIdentifiersTree :: VarDefList 
-              _lhsOoriginalTree :: VarDefList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/Plpgsql/Block.ag"(line 18, column 11)
-              _lhsOdefs =
-                  []
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOdefs,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- WithQuery ---------------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         catUpdates           : [CatalogUpdate]
-         cidenv               : IDEnv
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-   alternatives:
-      alternative WithQuery:
-         child ann            : {Annotation}
-         child name           : {NameComponent}
-         child colAliases     : {Maybe [NameComponent]}
-         child ex             : QueryExpr 
-         visit 0:
-            local tpe         : _
-            local backTree    : _
-            local attrs       : _
-            local catUpdates  : _
-            local statementType : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-data WithQuery  = WithQuery (Annotation) (NameComponent) ((Maybe [NameComponent])) (QueryExpr ) 
-                deriving ( Data,Eq,Show,Typeable)
--- cata
-sem_WithQuery :: WithQuery  ->
-                 T_WithQuery 
-sem_WithQuery (WithQuery _ann _name _colAliases _ex )  =
-    (sem_WithQuery_WithQuery _ann _name _colAliases (sem_QueryExpr _ex ) )
--- semantic domain
-type T_WithQuery  = Catalog ->
-                    IDEnv ->
-                    LocalBindings ->
-                    ( WithQuery ,([CatalogUpdate]),IDEnv,WithQuery ,WithQuery )
-data Inh_WithQuery  = Inh_WithQuery {cat_Inh_WithQuery :: Catalog,idenv_Inh_WithQuery :: IDEnv,lib_Inh_WithQuery :: LocalBindings}
-data Syn_WithQuery  = Syn_WithQuery {annotatedTree_Syn_WithQuery :: WithQuery ,catUpdates_Syn_WithQuery :: ([CatalogUpdate]),cidenv_Syn_WithQuery :: IDEnv,fixedUpIdentifiersTree_Syn_WithQuery :: WithQuery ,originalTree_Syn_WithQuery :: WithQuery }
-wrap_WithQuery :: T_WithQuery  ->
-                  Inh_WithQuery  ->
-                  Syn_WithQuery 
-wrap_WithQuery sem (Inh_WithQuery _lhsIcat _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOcidenv,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIidenv _lhsIlib 
-     in  (Syn_WithQuery _lhsOannotatedTree _lhsOcatUpdates _lhsOcidenv _lhsOfixedUpIdentifiersTree _lhsOoriginalTree ))
-sem_WithQuery_WithQuery :: Annotation ->
-                           NameComponent ->
-                           (Maybe [NameComponent]) ->
-                           T_QueryExpr  ->
-                           T_WithQuery 
-sem_WithQuery_WithQuery ann_ name_ colAliases_ ex_  =
-    (\ _lhsIcat
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOfixedUpIdentifiersTree :: WithQuery 
-              _exOcsql :: LocalBindings
-              _exOexpectedTypes :: ([Maybe Type])
-              _lhsOannotatedTree :: WithQuery 
-              _lhsOoriginalTree :: WithQuery 
-              _lhsOcatUpdates :: ([CatalogUpdate])
-              _lhsOcidenv :: IDEnv
-              _exOcat :: Catalog
-              _exOidenv :: IDEnv
-              _exOlib :: LocalBindings
-              _exIannotatedTree :: QueryExpr 
-              _exIcidenv :: IDEnv
-              _exIfixedUpIdentifiersTree :: QueryExpr 
-              _exIlibUpdates :: ([LocalBindingsUpdate])
-              _exIoriginalTree :: QueryExpr 
-              _exIuType :: (Maybe [(String,Type)])
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 245, column 9)
-              _lhsOfixedUpIdentifiersTree =
-                  undefined
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 131, column 17)
-              _exOcsql =
-                  emptyBindings
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 272, column 9)
-              _tpe =
-                  Right $ Pseudo Void
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 273, column 9)
-              _backTree =
-                  WithQuery ann_ name_ colAliases_ _exIannotatedTree
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 274, column 9)
-              _attrs =
-                  maybe [] id $ _exIuType
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 275, column 9)
-              _catUpdates =
-                  [CatCreateView (ncStr name_) _attrs    ]
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 276, column 9)
-              _statementType =
-                  Nothing
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/ParameterizedStatements.ag"(line 180, column 17)
-              _exOexpectedTypes =
-                  []
-              -- self rule
-              _annotatedTree =
-                  WithQuery ann_ name_ colAliases_ _exIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  WithQuery ann_ name_ colAliases_ _exIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  WithQuery ann_ name_ colAliases_ _exIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (from local)
-              _lhsOcatUpdates =
-                  _catUpdates
-              -- copy rule (up)
-              _lhsOcidenv =
-                  _exIcidenv
-              -- copy rule (down)
-              _exOcat =
-                  _lhsIcat
-              -- copy rule (down)
-              _exOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _exOlib =
-                  _lhsIlib
-              ( _exIannotatedTree,_exIcidenv,_exIfixedUpIdentifiersTree,_exIlibUpdates,_exIoriginalTree,_exIuType) =
-                  ex_ _exOcat _exOcsql _exOexpectedTypes _exOidenv _exOlib 
-          in  ( _lhsOannotatedTree,_lhsOcatUpdates,_lhsOcidenv,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree)))
--- WithQueryList -----------------------------------------------
-{-
-   visit 0:
-      inherited attributes:
-         cat                  : Catalog
-         catUpdates           : [CatalogUpdate]
-         idenv                : IDEnv
-         lib                  : LocalBindings
-      synthesized attributes:
-         annotatedTree        : SELF 
-         cidenv               : IDEnv
-         fixedUpIdentifiersTree : SELF 
-         originalTree         : SELF 
-         producedCat          : Catalog
-   alternatives:
-      alternative Cons:
-         child hd             : WithQuery 
-         child tl             : WithQueryList 
-         visit 0:
-            local newCat      : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
-      alternative Nil:
-         visit 0:
-            local newCat      : _
-            local annotatedTree : _
-            local fixedUpIdentifiersTree : _
-            local originalTree : _
--}
-type WithQueryList  = [WithQuery ]
--- cata
-sem_WithQueryList :: WithQueryList  ->
-                     T_WithQueryList 
-sem_WithQueryList list  =
-    (Prelude.foldr sem_WithQueryList_Cons sem_WithQueryList_Nil (Prelude.map sem_WithQuery list) )
--- semantic domain
-type T_WithQueryList  = Catalog ->
-                        ([CatalogUpdate]) ->
-                        IDEnv ->
-                        LocalBindings ->
-                        ( WithQueryList ,IDEnv,WithQueryList ,WithQueryList ,Catalog)
-data Inh_WithQueryList  = Inh_WithQueryList {cat_Inh_WithQueryList :: Catalog,catUpdates_Inh_WithQueryList :: ([CatalogUpdate]),idenv_Inh_WithQueryList :: IDEnv,lib_Inh_WithQueryList :: LocalBindings}
-data Syn_WithQueryList  = Syn_WithQueryList {annotatedTree_Syn_WithQueryList :: WithQueryList ,cidenv_Syn_WithQueryList :: IDEnv,fixedUpIdentifiersTree_Syn_WithQueryList :: WithQueryList ,originalTree_Syn_WithQueryList :: WithQueryList ,producedCat_Syn_WithQueryList :: Catalog}
-wrap_WithQueryList :: T_WithQueryList  ->
-                      Inh_WithQueryList  ->
-                      Syn_WithQueryList 
-wrap_WithQueryList sem (Inh_WithQueryList _lhsIcat _lhsIcatUpdates _lhsIidenv _lhsIlib )  =
-    (let ( _lhsOannotatedTree,_lhsOcidenv,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOproducedCat) = sem _lhsIcat _lhsIcatUpdates _lhsIidenv _lhsIlib 
-     in  (Syn_WithQueryList _lhsOannotatedTree _lhsOcidenv _lhsOfixedUpIdentifiersTree _lhsOoriginalTree _lhsOproducedCat ))
-sem_WithQueryList_Cons :: T_WithQuery  ->
-                          T_WithQueryList  ->
-                          T_WithQueryList 
-sem_WithQueryList_Cons hd_ tl_  =
-    (\ _lhsIcat
-       _lhsIcatUpdates
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOcidenv :: IDEnv
-              _hdOcat :: Catalog
-              _tlOcat :: Catalog
-              _lhsOproducedCat :: Catalog
-              _tlOcatUpdates :: ([CatalogUpdate])
-              _lhsOannotatedTree :: WithQueryList 
-              _lhsOfixedUpIdentifiersTree :: WithQueryList 
-              _lhsOoriginalTree :: WithQueryList 
-              _hdOidenv :: IDEnv
-              _hdOlib :: LocalBindings
-              _tlOidenv :: IDEnv
-              _tlOlib :: LocalBindings
-              _hdIannotatedTree :: WithQuery 
-              _hdIcatUpdates :: ([CatalogUpdate])
-              _hdIcidenv :: IDEnv
-              _hdIfixedUpIdentifiersTree :: WithQuery 
-              _hdIoriginalTree :: WithQuery 
-              _tlIannotatedTree :: WithQueryList 
-              _tlIcidenv :: IDEnv
-              _tlIfixedUpIdentifiersTree :: WithQueryList 
-              _tlIoriginalTree :: WithQueryList 
-              _tlIproducedCat :: Catalog
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 253, column 12)
-              _lhsOcidenv =
-                  undefined
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 256, column 9)
-              _newCat =
-                  fromRight _lhsIcat $ updateCatalog _lhsIcat _lhsIcatUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 258, column 9)
-              _hdOcat =
-                  _newCat
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 259, column 9)
-              _tlOcat =
-                  _newCat
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 263, column 9)
-              _lhsOproducedCat =
-                  _tlIproducedCat
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 266, column 9)
-              _tlOcatUpdates =
-                  _hdIcatUpdates
-              -- self rule
-              _annotatedTree =
-                  (:) _hdIannotatedTree _tlIannotatedTree
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  (:) _hdIfixedUpIdentifiersTree _tlIfixedUpIdentifiersTree
-              -- self rule
-              _originalTree =
-                  (:) _hdIoriginalTree _tlIoriginalTree
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-              -- copy rule (down)
-              _hdOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _hdOlib =
-                  _lhsIlib
-              -- copy rule (down)
-              _tlOidenv =
-                  _lhsIidenv
-              -- copy rule (down)
-              _tlOlib =
-                  _lhsIlib
-              ( _hdIannotatedTree,_hdIcatUpdates,_hdIcidenv,_hdIfixedUpIdentifiersTree,_hdIoriginalTree) =
-                  hd_ _hdOcat _hdOidenv _hdOlib 
-              ( _tlIannotatedTree,_tlIcidenv,_tlIfixedUpIdentifiersTree,_tlIoriginalTree,_tlIproducedCat) =
-                  tl_ _tlOcat _tlOcatUpdates _tlOidenv _tlOlib 
-          in  ( _lhsOannotatedTree,_lhsOcidenv,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOproducedCat)))
-sem_WithQueryList_Nil :: T_WithQueryList 
-sem_WithQueryList_Nil  =
-    (\ _lhsIcat
-       _lhsIcatUpdates
-       _lhsIidenv
-       _lhsIlib ->
-         (let _lhsOcidenv :: IDEnv
-              _lhsOproducedCat :: Catalog
-              _lhsOannotatedTree :: WithQueryList 
-              _lhsOfixedUpIdentifiersTree :: WithQueryList 
-              _lhsOoriginalTree :: WithQueryList 
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/FixUpIdentifiers.ag"(line 256, column 11)
-              _lhsOcidenv =
-                  emptyIDEnv "empty with query list"
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 256, column 9)
-              _newCat =
-                  fromRight _lhsIcat $ updateCatalog _lhsIcat _lhsIcatUpdates
-              -- "src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryStatement.ag"(line 268, column 9)
-              _lhsOproducedCat =
-                  _newCat
-              -- self rule
-              _annotatedTree =
-                  []
-              -- self rule
-              _fixedUpIdentifiersTree =
-                  []
-              -- self rule
-              _originalTree =
-                  []
-              -- self rule
-              _lhsOannotatedTree =
-                  _annotatedTree
-              -- self rule
-              _lhsOfixedUpIdentifiersTree =
-                  _fixedUpIdentifiersTree
-              -- self rule
-              _lhsOoriginalTree =
-                  _originalTree
-          in  ( _lhsOannotatedTree,_lhsOcidenv,_lhsOfixedUpIdentifiersTree,_lhsOoriginalTree,_lhsOproducedCat)))
+{-# LANGUAGE TupleSections,ScopedTypeVariables,DeriveDataTypeable,OverloadedStrings #-}
+-- UUAGC 0.9.52.1 (hssqlppp/src/Database/HsSqlPpp/Internals/AstInterna)
+module Database.HsSqlPpp.Internals.AstInternal(
+    --from the ag files:
+    --ast nodes
+    Statement (..)
+   ,QueryExpr (..)
+   ,WithQueryList
+   ,WithQuery(..)
+   ,FnBody (..)
+   ,SetClause (..)
+   ,SetClauseList
+   ,TableRef (..)
+   ,JoinExpr (..)
+   ,JoinType (..)
+   ,JoinHint (..)
+   ,SelectList (..)
+   ,SelectItem (..)
+   ,CopyFromSource (..)
+   ,CopyToSource(..)
+   ,CopyToOption(..)
+   ,CopyFromOption(..)
+   ,TablePartitionDef(..)
+   ,TablePartitionDateTimeInterval(..)
+   ,AttributeDef (..)
+   ,RowConstraint (..)
+   ,AlterDatabaseOperation(..)
+   ,AlterTableOperation(..)
+   ,AlterTableAction(..)
+   ,AlterSequenceOperation(..)
+   ,AlterSequenceAction(..)
+   ,AlterColumnAction(..)
+   ,AlterSchemaOperation(..)
+   ,Constraint (..)
+   ,TypeAttributeDef (..)
+   ,ParamDef (..)
+   ,VarDef (..)
+   ,RaiseType (..)
+   ,CombineType (..)
+   ,Volatility (..)
+   ,Language (..)
+   ,TypeName (..)
+   ,DropType (..)
+   ,Cascade (..)
+   ,Direction (..)
+   ,Distinct (..)
+   ,NullsOrder(..)
+   ,Natural (..)
+   ,IfExists (..)
+   ,Replace(..)
+   ,RestartIdentity (..)
+   ,ScalarExpr (..)
+   ,Name(..)
+   ,nameComponents
+   ,NameComponent(..)
+   ,ncStr
+   ,IntervalField(..)
+   ,ExtractField(..)
+   ,FrameClause(..)
+   ,OdbcLiteralType(..)
+   ,InList (..)
+   ,LiftFlavour(..)
+   ,TriggerWhen(..)
+   ,TriggerEvent(..)
+   ,TriggerFire(..)
+   ,QueryHint(..)
+   ,StatementList
+   ,ScalarExprListStatementListTripleList
+   ,ScalarExprListStatementListTriple
+   ,ScalarExprList
+   ,ParamDefList
+   ,AttributeDefList
+   ,ConstraintList
+   ,TypeAttributeDefList
+   ,TypeNameList
+   ,NameTypeNameListPair
+   ,NameTypeNameListPairList
+   ,ScalarExprStatementListPairList
+   --,SetClauseList
+   ,CaseScalarExprListScalarExprPairList
+   ,MaybeScalarExpr
+   ,TableRefList
+   ,ScalarExprListList
+   ,SelectItemList
+   ,OnExpr
+   ,RowConstraintList
+   ,VarDefList
+   ,ScalarExprStatementListPair
+   ,CaseScalarExprListScalarExprPair
+   ,ScalarExprDirectionPair
+   ,ScalarExprDirectionPairList
+   ,MaybeBoolExpr
+   ,MaybeSelectList
+   ,SetValue(..)
+   ,AlterTableActionList
+   ,NameComponentList
+   ,MaybeNameComponentList
+   -- typechecking
+   ,typeCheckStatements
+   --,typeCheckParameterizedStatement
+   ,typeCheckScalarExpr
+   --,typeCheckScalarExprEnv
+   ,typeCheckQueryExpr
+   ,TypeCheckFlags(..)
+   ,addExplicitCasts
+   ,addImplicitCasts
+   -- annotation
+   ,Annotation(..)
+   --,TypeExtra(..)
+   ,SourcePosition
+   ,ParameterizedStatementType
+   ,getAnnotation
+   ,updateAnnotation
+   ,emptyAnnotation
+   ,makeSelect
+   --,canonicalizeTypeNames
+) where
+
+--import Data.Maybe
+--import Data.Either
+--import Data.List
+--import Control.Applicative
+import Data.Data
+--import Data.Char
+--import Control.Monad.State
+--import Control.Arrow
+
+import Data.Generics
+import Data.Generics.Uniplate.Data
+--import Debug.Trace
+--import Text.Show.Pretty
+
+
+--import Database.HsSqlPpp.Internals.TypesInternal
+
+--import Database.HsSqlPpp.Internals.TypeChecking.TypeConversion
+--import Database.HsSqlPpp.Internals.TypeChecking.Environment hiding (JoinType(..))
+
+--import Database.HsSqlPpp.Internals.Catalog.CatalogInternal (NameComponent(..),ncStr)
+
+--import Database.HsSqlPpp.Utils.Utils
+--import Database.HsSqlPpp.Internals.Dialect
+--import Data.Text (Text)
+import qualified Data.Text as T
+--import qualified Data.Text.Lazy as LT
+
+-- very bad, we use types in the syntax outside of the already exception
+-- in the annotation (which can be removed when the annotation type
+-- becomes a type parameters
+-- can replace the use of type extra with (typename,int,int) triple
+-- to fix this
+--import Database.HsSqlPpp.Internals.TypesInternal (TypeExtra)
+
+
+
+{-# LINE 2 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+
+import Data.Text (Text)
+import qualified Database.HsSqlPpp.Internals.TypeChecking.Environment as E
+import Database.HsSqlPpp.Internals.TypeChecking.Environment (Environment)
+import Database.HsSqlPpp.Internals.TypesInternal
+import Database.HsSqlPpp.Internals.Dialect
+import Database.HsSqlPpp.Internals.Catalog.CatalogInternal
+import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+import Database.HsSqlPpp.Internals.Catalog.CatalogBuilder
+import Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.TypeConversion
+
+-- todo: find a better way to do this, this information should come
+-- via the dialect or catalog in the attributes
+import Database.HsSqlPpp.Dialects.OdbcCatalog
+
+import Control.Monad
+import Data.List
+import Data.Maybe
+import Data.Char
+import Text.Read
+import Control.Applicative
+{-# LINE 181 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 14 "hssqlppp/src/Database/HsSqlPpp/Internals/Annotation.ag" #-}
+
+import qualified Database.HsSqlPpp.Internals.TypesInternal as T
+import qualified Database.HsSqlPpp.Internals.Catalog.CatalogTypes as C
+
+{-# LINE 188 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+{-# LINE 62 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag" #-}
+
+-- todo: replace the other nmcString function with this one
+-- which uses either instead of error
+xnmcString :: NameComponent -> Either [TypeError] Text
+xnmcString (QNmc n) = Right $ T.pack n
+xnmcString (Nmc n) = Right $ T.pack $ map toLower n
+xnmcString (AntiNameComponent _) = Left [InternalError "tried to get nmc string from antinamecomponent"]
+{-# LINE 197 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 191 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+
+splitTypeExtraList:: Maybe [TypeExtra] -> Maybe (TypeExtra,[TypeExtra])
+splitTypeExtraList mte = mte >>= f
+  where
+    f [] = Nothing
+    f (et:ets') = Just (et,ets')
+{-# LINE 206 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 212 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+
+
+-- | thet name to choose for a column in a select list which doesn't
+-- have an explicit name - these are postgresql's rules
+columnName :: ScalarExpr -> NameComponent
+columnName (Identifier _ i) = last $ nameComponents i
+columnName (App _ (Name _ ncs) _) = last ncs
+columnName (Cast _ _ (SimpleTypeName _ (Name _ ncs))) = last ncs
+columnName (ImplicitCast _ e _) = columnName e
+columnName (WindowApp _ (App _ (Name _ ncs) _) _ _ _) = last ncs
+columnName (AggregateApp _ _ (App _ (Name _ ncs) _) _) = last ncs
+columnName _ = QNmc "?column?"
+{-# LINE 221 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 160 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+
+convertJoinType:: JoinType -> E.JoinType
+convertJoinType LeftOuter = E.LeftOuter
+convertJoinType RightOuter = E.RightOuter
+convertJoinType FullOuter = E.FullOuter
+convertJoinType _ = E.Inner
+{-# LINE 230 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 82 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+
+secondM :: Functor f => (t -> f a) -> (t1, t) -> f (t1, a)
+secondM f (a,b) = (a,) <$> f b
+{-# LINE 236 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 47 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+
+needsImplicitCast:: Bool -> TypeExtra -> TypeExtra -> Bool
+needsImplicitCast expectedCast upType expType
+    = tePrecision upType /= tePrecision expType
+      || teScale upType /= teScale expType
+      || teNullable upType /= teNullable expType
+          && nullabilityCast
+      ||  teType upType /= teType expType
+          && (not . null) (nub [teType upType, teType expType] \\ [ScalarType "varchar", ScalarType "text",ScalarType "nvarchar"])
+  where
+    nullabilityCast = expectedCast
+-- this function appeared because nullability does not always influence the type to cast to
+implicitCastType:: Bool -> TypeExtra -> TypeExtra -> TypeExtra
+implicitCastType expectedCast upType expType
+    = expType{tePrecision = precision, teScale = scale, teNullable = nullability}
+  where
+    nullabilityCast = expectedCast
+    nullabilitySource = if nullabilityCast then expType else upType
+    precisionSource = expType
+    nullability = teNullable nullabilitySource
+    precision = tePrecision precisionSource
+    scale = teScale precisionSource
+{-# LINE 261 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 512 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+
+getMaybeIntsFromLiterals :: [ScalarExpr] -> MatchAppLiteralList
+getMaybeIntsFromLiterals sel = map extractor sel
+  where
+   extractor :: ScalarExpr -> Maybe Int
+   extractor (NumberLit _ s) = readMaybe s :: Maybe Int
+   extractor _ = Nothing
+{-# LINE 271 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 795 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+
+classifyInteger :: Dialect -> String -> Either [TypeError] Text
+classifyInteger d s = maybe (Left []) Right $ case (readMaybe s :: Maybe Integer) of
+                      -- assuming number literals are always positive
+                      Just n | n < (2 ^ (31 :: Integer)) -> ansiTypeNameToDialect d "int"
+                             | n < (2 ^ (63 :: Integer)) -> ansiTypeNameToDialect d "bigint"
+                      _ -> ansiTypeNameToDialect d "numeric"
+{-# LINE 281 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 26 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+
+
+-- | some options when typechecking
+data TypeCheckFlags =
+    TypeCheckFlags
+    { -- | add qualifiers to unqualified ids where possible
+     tcfAddQualifiers :: Bool
+     -- | add full aliases to every tableref and subselect
+    ,tcfAddFullTablerefAliases :: Bool
+     -- | add explicit aliases to all select items
+    ,tcfAddSelectItemAliases :: Bool
+     -- | expand stars in select lists to explicit list columns
+    ,tcfExpandStars :: Bool
+    ,tcfDialect :: Dialect}
+    deriving (Show,Eq)
+
+-- | Typechecks the ast, and returns the updated catalog (which
+-- includes changes from any ddl statements in the ast).
+typeCheckStatements :: TypeCheckFlags -> Catalog -> [Statement] -> (Catalog,[Statement])
+typeCheckStatements f cat sts =
+    let t = _sem_Root (Root sts)
+        ta = _wrap_Root t Inh_Root {_cat_Inh_Root = cat
+                                  ,_flags_Inh_Root = f
+                                  {-,_lib_Inh_Root = emptyBindings
+                                  ,_idenv_Inh_Root = emptyIDEnv "tcs"-}}
+        tl = _annotatedTree_Syn_Root ta
+        cat1 = cat --_producedCat_Syn_Root ta
+    in case tl of
+         Root r -> (cat1,fixTree (tcfDialect f) r)
+-- | Typecheck a query expr
+typeCheckQueryExpr :: TypeCheckFlags -> Catalog -> QueryExpr -> QueryExpr
+typeCheckQueryExpr f cat qe =
+   let (_,[QueryStatement _ qe']) = typeCheckStatements f cat [QueryStatement emptyAnnotation qe]
+   in qe'
+
+-- | Not working yet. Typechecks a statement possibly containing ?
+-- placeholders. These are annotated with the 'inferred type', and the
+-- stType annotation on the return value can be used to get this info
+-- easily. Returns Left if the statement is not a query,insert,update or delete
+-- statement
+{-typeCheckParameterizedStatement :: TypeCheckFlags -> Catalog -> Statement -> Either String Statement
+typeCheckParameterizedStatement f cat st =
+    case st of
+      QueryStatement _ _ -> tc
+      Insert _ _ _ _ _ -> tc
+      Update _ _ _ _ _ _ -> tc
+      Delete _ _ _ _ _ -> tc
+      _ -> Left "requires select, update, insert or delete statement"
+    where
+      tc = let tl = typeCheckStatements f cat [st]
+           in case tl of
+                (_,[st1]) -> Right st1
+                _ -> error "impossible happened in typeCheckPS!"
+-}
+{-
+-- | type check a scalar expr
+typeCheckScalarExpr :: TypeCheckFlags -> Catalog -> ScalarExpr -> ScalarExpr
+typeCheckScalarExpr f cat ex =
+    let t = _sem_ScalarExprRoot (ScalarExprRoot ex)
+        rt = (_annotatedTree_Syn_ScalarExprRoot
+              (_wrap_ScalarExprRoot t Inh_ScalarExprRoot {_cat_Inh_ScalarExprRoot = cat
+                                                        ,_flags_Inh_ScalarExprRoot = f
+                                                        ,_downEnv_Inh_ScalarExprRoot = E.emptyEnvironment
+                                                        {-,_lib_Inh_ScalarExprRoot = emptyBindings
+                                                        ,_idenv_Inh_ScalarExprRoot = emptyIDEnv "t
+cse"-}}))
+    in case rt of
+         ScalarExprRoot e -> fixTree e -}
+
+typeCheckScalarExpr ::  TypeCheckFlags -> Catalog -> Environment
+                          -> ScalarExpr -> ScalarExpr
+typeCheckScalarExpr f cat env ex =
+    let t = _sem_ScalarExprRoot (ScalarExprRoot ex)
+        rt = _annotatedTree_Syn_ScalarExprRoot
+                $ _wrap_ScalarExprRoot t
+                    Inh_ScalarExprRoot{_cat_Inh_ScalarExprRoot = cat
+                                      ,_flags_Inh_ScalarExprRoot = f
+                                      ,_downEnv_Inh_ScalarExprRoot = env}
+    in case rt of
+         ScalarExprRoot e -> fixTree (tcfDialect f) e
+
+{-# LINE 365 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 158 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+
+
+-- | run on a typechecked tree. Finds all the places where an implicit
+-- cast has been used in the typechecking and inserts an explicit cast
+addExplicitCasts :: Data a => a -> a
+addExplicitCasts = transformBi removeDoubleCasts . transformBi addCast
+  where
+    addCast :: ScalarExpr -> ScalarExpr
+    addCast e = fromMaybe e $ do
+                  t <- anImplicitCast (getAnnotation e)
+                  n <- nameOfType $ teType t
+                  return $ Cast emptyAnnotation e n
+    -- addCast isn't very smart, so remove any unneeded casts
+    -- that it has inserted. Only do this when have two
+    -- nested casts which cast to the same type, so this
+    -- shouldn't cause problems with sane sql
+    removeDoubleCasts :: ScalarExpr -> ScalarExpr
+    removeDoubleCasts e = case e of
+      (Cast a (Cast _ e' t1) t)
+         | resetAnnotations t1 == resetAnnotations t -> Cast a e' t
+      e' -> e'
+    resetAnnotations = transformBi (const emptyAnnotation)
+-- | variation of the above, which uses ImplicitCast ctor
+addImplicitCasts :: Data a => Catalog -> a -> a
+addImplicitCasts cat = transformBi removeDoubleCasts . transformBi addCast
+  where
+    addCast:: ScalarExpr -> ScalarExpr
+    addCast e = fromMaybe e $ do
+                  te <- anImplicitCast ann'
+                  -- ImplicitCastToDo: why anImplicitCast is not Nothing above Star
+                  _ <- nameOfType $ teType te -- in order to preserve the old logic
+                  -- guard $ isCastable e $ teType te
+                  guard $ anType ann' /= Just te
+                  return $ ImplicitCast emptyAnnotation e te
+      where
+        _isCastable:: ScalarExpr -> Type -> Bool
+        _isCastable e' to = fromMaybe False $ do
+            from <- liftM teType $ anType $ getAnnotation e'
+            either  (const $ if from == UnknownType then Just True else Nothing) Just
+                    $ catCast cat ImplicitCastContext from to
+        ann' = getAnnotation e
+    removeDoubleCasts:: ScalarExpr -> ScalarExpr
+    removeDoubleCasts e = fst $ accumulateCasts e
+    -- For each implicit cast, if there is a sequence of implicit casts right under it,
+    --    that remained after bottom-up application of the algorithm being described:
+    --  1. Check if there is a type in the sequence (of argument types of implicit casts),
+    --      which is implicitly castable to the target type of the current implicit cast,
+    --      according to the current catalog.
+    --  2. If there is such a type, replace a sequence of casts that starts at this type with
+    --      a single cast, and shorten the list of casts to be further investigated (snd of
+    --      output type of this function).
+    --    2.1. Analyze the list bottom-up, so that the longest possible sequence of casts is
+    --      replaced.
+    --  3. If there is no such a type, just add the current cast to the list.
+    -- Reset the list on a node other than ImplicitCast.
+    accumulateCasts:: ScalarExpr -> (ScalarExpr,[(ScalarExpr,Type)])
+    accumulateCasts e = case e of
+        ImplicitCast a e' te
+          ->  let (e1,ets) = accumulateCasts e'
+                  eStart = ImplicitCast a e1 te
+                  isCastable (_,t) = either (const False) id
+                      $ catCast cat ImplicitCastContext t $ teType te
+                  f z xs = case dropWhile (not . isCastable) xs of
+                      [] -> z
+                      xs'@((e'',_):rest) -> f (ImplicitCast a e'' te, xs') rest
+              in case anType $ getAnnotation e1 of
+                    Nothing -> (eStart,[]) -- cut here (should not happen in practice)
+                    Just te1 -> f (eStart, (e1, teType te1):ets) ets
+        _ -> (e,[])
+
+nameOfType :: Type -> Maybe TypeName
+nameOfType (ScalarType t) = Just $ SimpleTypeName emptyAnnotation (Name emptyAnnotation [Nmc $ T.unpack t])
+-- a hack to support precision cast from string literals
+nameOfType UnknownType = Just $ SimpleTypeName emptyAnnotation (Name emptyAnnotation [Nmc "unknown"])
+nameOfType (DomainType t) = Just $ SimpleTypeName emptyAnnotation (Name emptyAnnotation [Nmc $ T.unpack t])
+nameOfType (EnumType t) = Just $ SimpleTypeName emptyAnnotation (Name emptyAnnotation [Nmc $ T.unpack t])
+nameOfType (NamedCompositeType t) = Just $ SimpleTypeName emptyAnnotation (Name emptyAnnotation [Nmc $ T.unpack t])
+nameOfType _ = Nothing
+
+-- hack for various fixups
+fixTree :: Data a => Dialect -> a -> a
+fixTree = fixMssqlDates
+
+{-
+
+
+disgusting hack to fix up datediff,datepart, convert and other
+functions which accept a fixed list of keywords for one or more of the
+arguments for sql server: set the type for the first argument to type
+in if it is in the acceptable list.
+
+This is really bad. What happens is that the normal typechecker will
+check the keyword as an identifier and (usually!) put in unknown
+identifier error. Then, when the function is typechecked, it will
+ignore the type for this argument. After we've finished, the type
+error is replaced with int type here.
+
+The proper fix:
+
+I think a good way to look at these is to consider them fixed enums
+which can only accept a literal (and not an enum valued
+expression). We set a flag/enum thing in the typecheck environment of
+the identifier, so that it can check the identifier fits one of the
+valid functions in the identifier itself. Then, there doesn't need to
+be a fix here, and typechecking the function should work without a
+hack here too. The typechecking of the function itself still needs
+some special casing (e.g. for the convert function in odbc (and
+similar in regular sql server syntax), the result type depends on the
+value of the 'enum'. This can be implemented in a similar way to the
+literal ints being passed to the function type checker.
+
+This will be fixed with the rewrite of the findcallmatch/matchapp/a
+million different fns for precision and nullability/tcApplike mess.
+
+-}
+
+fixMssqlDates :: Data a => Dialect -> a -> a
+fixMssqlDates d = transformBi $ \x -> case x of
+  App aa nm@(Name _ [Nmc fn]) [Identifier ai tn@(Name _ [Nmc tnn]),a,b]
+    | map toLower fn `elem` ["datediff","dateadd"]
+    , map toLower tnn `elem` dateparts ->
+      App aa nm [Identifier (nai ai) tn,a,b]
+  App aa nm@(Name _ [Nmc fn]) [Identifier ai tn@(Name _ [Nmc tnn]),a]
+    | map toLower fn == "datepart"
+    , map toLower tnn `elem` dateparts ->
+      App aa nm [Identifier (nai ai) tn,a]
+  App aa nm@(Name _ [Nmc fn]) [a,Identifier ai tn@(Name _ [Nmc tnn])]
+    | map toLower fn == "convert"
+    , map toLower tnn `elem` map fst odbcConvertTypes ->
+      App aa nm [a,Identifier (nai ai) tn]
+  App aa nm@(Name _ [Nmc fn]) (Identifier ai tn@(Name _ [Nmc tnn]):as)
+    | map toLower fn `elem` ["timestampadd","timestampdiff"]
+    , map toLower tnn `elem` odbcIntervalTypes ->
+      App aa nm (Identifier (nai ai) tn:as)
+  x' -> x'
+  where
+      dateparts :: [String]
+      dateparts = ["day","dd","d","month","mm","m","year","yyyy"
+                  ,"yy","quarter","qq","q","dayofyear","doy","dy","y"
+                  ,"weekday","dw","week","ww","wk","hour","hh"
+                  ,"minute","mi","n","second","ss","s","millisecond","ms"
+                  ,"microsecond","mcs","nanosecond","ns"]
+      -- todo: use canonical tsql name for typeInt
+      nai ai = ai {anType = (mkTypeExtraNN . ScalarType) <$> ansiTypeNameToDialect d "int"
+                  ,anErrs = []}
+
+
+-- temp utility function
+
+{-canonicalizeType :: Dialect -> Type -> Type
+canonicalizeType d (ScalarType t) = ScalarType $ canonicalizeTypeName d t
+canonicalizeType _ t = t-}
+
+{-# LINE 521 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 20 "hssqlppp/src/Database/HsSqlPpp/Internals/Annotation.ag" #-}
+
+-- | Represents a source file position, usually set by the parser.
+type SourcePosition = (FilePath,Int,Int)
+
+-- | Statement type is used for getting type information for a
+-- parameterized statement. The first part is the args that the
+-- parameterized statement needs, and the second is the names and types
+-- of the output columns. No way to signal that a statement returns
+-- exactly one row at the moment
+type ParameterizedStatementType = ([T.Type],[(String,T.Type)])
+
+{-# LINE 535 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 52 "hssqlppp/src/Database/HsSqlPpp/Internals/Annotation.ag" #-}
+
+
+--some simple wrappers around uniplate for internal use. I'm not sure
+--which of these are actually used
+
+-- | An annotation value with no information.
+emptyAnnotation :: Annotation
+emptyAnnotation = Annotation Nothing Nothing [] Nothing []
+
+-- | get the annotation for the root element of the tree passed
+getAnnotation :: Data a => a -> Annotation
+getAnnotation = head . childrenBi
+
+--don't know how to do this one with uniplate
+
+-- | Update the first annotation in a tree using the function supplied
+updateAnnotation :: Data a => (Annotation -> Annotation) -> a -> a
+updateAnnotation f = gmapT (mkT f)
+
+{-# LINE 557 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 518 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.ag" #-}
+
+nameComponents :: Name -> [NameComponent]
+nameComponents (Name _ is) = is
+-- todo: don't use error
+nameComponents (AntiName _) = error "tried to get namecomponents of antiname"
+{-# LINE 565 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 538 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.ag" #-}
+
+
+
+data LiftFlavour = LiftAny | LiftAll
+                   deriving (Show,Eq,Typeable,Data)
+
+data Direction = Asc | Desc
+                 deriving (Show,Eq,Typeable,Data)
+
+data NullsOrder = NullsDefault | NullsFirst | NullsLast
+                 deriving (Show,Eq,Typeable,Data)
+
+data Distinct = Distinct | All
+                deriving (Show,Eq,Typeable,Data)
+
+-- maybe should improve this, since you can have at least union
+-- distinct and union all just like select distinct and select all
+
+data CombineType = Except | Union | Intersect | UnionAll
+                   deriving (Show,Eq,Typeable,Data)
+
+data IntervalField = IntervalYear
+                   | IntervalMonth
+                   | IntervalDay
+                   | IntervalHour
+                   | IntervalMinute
+                   | IntervalSecond
+                   | IntervalYearToMonth
+                   | IntervalDayToHour
+                   | IntervalDayToMinute
+                   | IntervalDayToSecond
+                   | IntervalHourToMinute
+                   | IntervalHourToSecond
+                   | IntervalMinuteToSecond
+                     deriving (Show,Eq,Typeable,Data)
+
+data ExtractField = ExtractCentury
+                  | ExtractDay
+                  | ExtractDecade
+                  | ExtractDow
+                  | ExtractDoy
+                  | ExtractEpoch
+                  | ExtractHour
+                  | ExtractIsodow
+                  | ExtractIsoyear
+                  | ExtractMicroseconds
+                  | ExtractMillennium
+                  | ExtractMilliseconds
+                  | ExtractMinute
+                  | ExtractMonth
+                  | ExtractQuarter
+                  | ExtractSecond
+                  | ExtractTimezone
+                  | ExtractTimezoneHour
+                  | ExtractTimezoneMinute
+                  | ExtractWeek
+                  | ExtractYear
+                    deriving (Show,Eq,Typeable,Data)
+
+-- todo: this needs fixing, it is currently based on limited frame options
+data FrameClause = FrameUnboundedPreceding
+                 | FrameUnboundedFull
+                 | FrameRowsUnboundedPreceding
+                   deriving (Show,Eq,Typeable,Data)
+
+
+data OdbcLiteralType = OLDate
+                     | OLTime
+                     | OLTimestamp
+                       deriving (Show,Eq,Typeable,Data)
+{-# LINE 638 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 692 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.ag" #-}
+
+data JoinType = Inner | LeftOuter| RightOuter | FullOuter | Cross
+                deriving (Show,Eq,Typeable,Data)
+data JoinHint = Loop | Hash | Merge
+                deriving (Show,Eq,Typeable,Data)
+data Natural = Natural | Unnatural
+               deriving (Show,Eq,Typeable,Data)
+{-# LINE 648 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 710 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.ag" #-}
+
+-- | 'default' valued select, use for creating select values
+--
+-- > makeSelect :: QueryExpr
+-- > makeSelect = Select
+-- >              {ann = emptyAnnotation
+-- >              ,selDistinct = All
+-- >              ,selSelectList = (SelectList emptyAnnotation [])
+-- >              ,selTref = []
+-- >              ,selWhere = Nothing
+-- >              ,selGroupBy = []
+-- >              ,selHaving = Nothing
+-- >              ,selOrderBy = []
+-- >              ,selLimit = Nothing
+-- >              ,selOffset = Nothing
+-- >              ,selOption = []}
+--
+-- On its own, it isn't valid syntax: to use it you have to replace
+-- the select list at minimum
+--
+-- use something like this
+--
+-- > s = makeSelect {selSelectList = sl [se $ i "a"]
+-- >                ,selTref = [tref "t"]}
+-- >     where
+-- >         a = emptyAnnotation
+-- >         sl = SelectList a
+-- >         se = SelExp a
+-- >         i = Identifier a
+-- >         tref t = Tref a (Name a [Nmc t])
+
+makeSelect :: QueryExpr
+makeSelect = Select
+             {ann = emptyAnnotation
+             ,selDistinct = All
+             ,selSelectList = (SelectList emptyAnnotation [])
+             ,selTref = []
+             ,selWhere = Nothing
+             ,selGroupBy = []
+             ,selHaving = Nothing
+             ,selOrderBy = []
+             ,selLimit = Nothing
+             ,selOffset = Nothing
+             ,selOption = []}
+{-# LINE 695 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 1019 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.ag" #-}
+
+data CopyFromSource = CopyFilename String
+                    | Stdin
+                      deriving (Show,Eq,Typeable,Data)
+data CopyToSource = CopyTable Name [NameComponent]
+                  | CopyQuery QueryExpr
+                    deriving (Show,Eq,Typeable,Data)
+
+data CopyFromOption = CopyFromFormat String
+                    | CopyFromDelimiter String
+                    | CopyFromErrorLog String
+                    | CopyFromErrorVerbosity Int
+                    | CopyFromParsers String
+                    | CopyFromDirectory
+                    | CopyFromOffset Integer
+                    | CopyFromLimit Integer
+                    | CopyFromErrorThreshold Int
+                    | CopyFromNewlineFormat String
+                  deriving (Show,Eq,Typeable,Data)
+
+data CopyToOption = CopyToFormat String
+                  | CopyToDelimiter String
+                  | CopyToErrorLog String
+                  | CopyToErrorVerbosity Int
+                  deriving (Show,Eq,Typeable,Data)
+
+{-# LINE 724 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 1110 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.ag" #-}
+
+data TablePartitionDateTimeInterval = Year | Month | Day | Hour | Minute | Second | Millisecond
+                                 deriving (Show,Eq,Typeable,Data)
+{-# LINE 730 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 1173 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.ag" #-}
+
+data SetValue
+    = SetStr Annotation String
+    | SetId Annotation String
+    | SetNum Annotation Double
+      deriving (Show,Eq,Typeable,Data)
+
+
+data TriggerWhen = TriggerBefore | TriggerAfter
+                   deriving (Show,Eq,Typeable,Data)
+data TriggerEvent = TInsert| TUpdate | TDelete | AntiTriggerEvent String
+                    deriving (Show,Eq,Typeable,Data)
+data TriggerFire = EachRow | EachStatement
+                   deriving (Show,Eq,Typeable,Data)
+
+data DropType = Table
+              | Domain
+              | View
+              | Type
+              | Database
+              | User
+              | Login
+              | Schema
+                deriving (Show,Eq,Typeable,Data)
+
+data Cascade = Cascade | Restrict
+               deriving (Show,Eq,Typeable,Data)
+
+
+
+data IfExists = Require | IfExists
+                deriving (Show,Eq,Typeable,Data)
+
+
+data RestartIdentity = RestartIdentity | ContinueIdentity
+                       deriving (Show,Eq,Typeable,Data)
+
+{-# LINE 770 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 1216 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.ag" #-}
+
+data Replace = Replace | NoReplace
+               deriving (Show,Eq,Typeable,Data)
+
+data Volatility = Volatile | Stable | Immutable
+                  deriving (Show,Eq,Typeable,Data)
+
+-- todo: fix the fn body to support to support other languages
+-- just as as string for now
+-- probably change Language to be a string also
+
+data Language = Sql | Plpgsql
+                deriving (Show,Eq,Typeable,Data)
+{-# LINE 786 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 1255 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.ag" #-}
+
+data RaiseType = RNotice | RException | RError
+                 deriving (Show,Eq,Typeable,Data)
+
+{-# LINE 793 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 1269 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.ag" #-}
+
+data QueryHint = QueryHintPartitionGroup | QueryHintColumnarHostGroup
+                 deriving (Show,Eq,Typeable,Data)
+
+{-# LINE 800 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+
+{-# LINE 1375 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.ag" #-}
+
+-- TODO: move this somewhere better
+-- | run canonicalizeTypeName on all the TypeName nodes in an ast
+{-canonicalizeTypeNames :: Data a => Dialect -> a -> a
+canonicalizeTypeNames d =
+   (transformBi $ \x ->
+       case x of
+         ScalarType s -> ScalarType $ canonicalizeTypeName d s
+         x' -> x')
+   . (transformBi $ \x ->
+       case x of
+         SimpleTypeName a tn -> SimpleTypeName a (c tn)
+         PrecTypeName a tn i -> PrecTypeName a (c tn) i
+         Prec2TypeName a tn i i1 -> Prec2TypeName a (c tn) i i1
+         x' -> x')
+   where
+     c (Name a [Nmc nc]) = Name a [Nmc $ T.unpack $ canonicalizeTypeName d $ T.pack nc]
+     c z = z-}
+
+{-# LINE 822 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+-- AlterColumnAction -------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : AlterColumnAction 
+         originalTree         : AlterColumnAction 
+   alternatives:
+      alternative SetDataType:
+         child ann            : Annotation 
+         child typ            : TypeName 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative SetNotNull:
+         child ann            : Annotation 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative DropNotNull:
+         child ann            : Annotation 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative SetDefault:
+         child ann            : Annotation 
+         child def            : ScalarExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative DropDefault:
+         child ann            : Annotation 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data AlterColumnAction = SetDataType (Annotation) (TypeName)
+                       | SetNotNull (Annotation)
+                       | DropNotNull (Annotation)
+                       | SetDefault (Annotation) (ScalarExpr)
+                       | DropDefault (Annotation)
+                       deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_AlterColumnAction :: AlterColumnAction ->
+                         T_AlterColumnAction
+_sem_AlterColumnAction (SetDataType _ann _typ) =
+    (_sem_AlterColumnAction_SetDataType (_sem_Annotation _ann) (_sem_TypeName _typ))
+_sem_AlterColumnAction (SetNotNull _ann) =
+    (_sem_AlterColumnAction_SetNotNull (_sem_Annotation _ann))
+_sem_AlterColumnAction (DropNotNull _ann) =
+    (_sem_AlterColumnAction_DropNotNull (_sem_Annotation _ann))
+_sem_AlterColumnAction (SetDefault _ann _def) =
+    (_sem_AlterColumnAction_SetDefault (_sem_Annotation _ann) (_sem_ScalarExpr _def))
+_sem_AlterColumnAction (DropDefault _ann) =
+    (_sem_AlterColumnAction_DropDefault (_sem_Annotation _ann))
+-- semantic domain
+type T_AlterColumnAction = Catalog ->
+                           TypeCheckFlags ->
+                           (Maybe TypeExtra) ->
+                           ( AlterColumnAction,AlterColumnAction)
+data Inh_AlterColumnAction = Inh_AlterColumnAction {_cat_Inh_AlterColumnAction :: Catalog,_flags_Inh_AlterColumnAction :: TypeCheckFlags,_imCast_Inh_AlterColumnAction :: (Maybe TypeExtra)}
+data Syn_AlterColumnAction = Syn_AlterColumnAction {_annotatedTree_Syn_AlterColumnAction :: AlterColumnAction,_originalTree_Syn_AlterColumnAction :: AlterColumnAction}
+_wrap_AlterColumnAction :: T_AlterColumnAction ->
+                          Inh_AlterColumnAction ->
+                          Syn_AlterColumnAction
+_wrap_AlterColumnAction sem (Inh_AlterColumnAction _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_AlterColumnAction _lhsOannotatedTree _lhsOoriginalTree))
+_sem_AlterColumnAction_SetDataType :: T_Annotation ->
+                                     T_TypeName ->
+                                     T_AlterColumnAction
+_sem_AlterColumnAction_SetDataType ann_ typ_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterColumnAction
+              _lhsOoriginalTree :: AlterColumnAction
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _typOcat :: Catalog
+              _typOflags :: TypeCheckFlags
+              _typOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _typIannotatedTree :: TypeName
+              _typInamedType :: (Maybe TypeExtra)
+              _typIoriginalTree :: TypeName
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 24, column 37)
+              _annOtpe =
+                  ({-# LINE 24 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 919 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SetDataType _annIannotatedTree _typIannotatedTree
+                   {-# LINE 925 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SetDataType _annIoriginalTree _typIoriginalTree
+                   {-# LINE 931 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 937 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 943 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 949 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 955 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 961 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 967 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 973 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 979 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _typIannotatedTree,_typInamedType,_typIoriginalTree) =
+                  typ_ _typOcat _typOflags _typOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterColumnAction_SetNotNull :: T_Annotation ->
+                                    T_AlterColumnAction
+_sem_AlterColumnAction_SetNotNull ann_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterColumnAction
+              _lhsOoriginalTree :: AlterColumnAction
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 29, column 36)
+              _annOtpe =
+                  ({-# LINE 29 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 1004 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SetNotNull _annIannotatedTree
+                   {-# LINE 1010 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SetNotNull _annIoriginalTree
+                   {-# LINE 1016 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 1022 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 1028 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 1034 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 1040 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 1046 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterColumnAction_DropNotNull :: T_Annotation ->
+                                     T_AlterColumnAction
+_sem_AlterColumnAction_DropNotNull ann_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterColumnAction
+              _lhsOoriginalTree :: AlterColumnAction
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 23, column 37)
+              _annOtpe =
+                  ({-# LINE 23 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 1069 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   DropNotNull _annIannotatedTree
+                   {-# LINE 1075 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   DropNotNull _annIoriginalTree
+                   {-# LINE 1081 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 1087 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 1093 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 1099 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 1105 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 1111 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterColumnAction_SetDefault :: T_Annotation ->
+                                    T_ScalarExpr ->
+                                    T_AlterColumnAction
+_sem_AlterColumnAction_SetDefault ann_ def_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _defOdownEnv :: Environment
+              _defOexpectedCast :: Bool
+              _defOexpectedType :: (Maybe TypeExtra)
+              _defOodbcFunction :: Bool
+              _defOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: AlterColumnAction
+              _lhsOoriginalTree :: AlterColumnAction
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _defOcat :: Catalog
+              _defOflags :: TypeCheckFlags
+              _defOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _defIannotatedTree :: ScalarExpr
+              _defIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _defIoriginalTree :: ScalarExpr
+              _defIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 25, column 36)
+              _annOtpe =
+                  ({-# LINE 25 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 1147 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 26, column 36)
+              _defOdownEnv =
+                  ({-# LINE 26 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 1153 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 27, column 36)
+              _defOexpectedCast =
+                  ({-# LINE 27 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 1159 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 28, column 36)
+              _defOexpectedType =
+                  ({-# LINE 28 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 1165 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 131, column 18)
+              _defOodbcFunction =
+                  ({-# LINE 131 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 1171 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 806, column 36)
+              _defOassignmentCastContext =
+                  ({-# LINE 806 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 1177 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SetDefault _annIannotatedTree _defIannotatedTree
+                   {-# LINE 1183 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SetDefault _annIoriginalTree _defIoriginalTree
+                   {-# LINE 1189 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 1195 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 1201 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 1207 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 1213 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 1219 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _defOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 1225 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _defOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 1231 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _defOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 1237 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _defIannotatedTree,_defIcolExprs,_defIoriginalTree,_defIupType) =
+                  def_ _defOassignmentCastContext _defOcat _defOdownEnv _defOexpectedCast _defOexpectedType _defOflags _defOimCast _defOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterColumnAction_DropDefault :: T_Annotation ->
+                                     T_AlterColumnAction
+_sem_AlterColumnAction_DropDefault ann_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterColumnAction
+              _lhsOoriginalTree :: AlterColumnAction
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 22, column 37)
+              _annOtpe =
+                  ({-# LINE 22 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 1262 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   DropDefault _annIannotatedTree
+                   {-# LINE 1268 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   DropDefault _annIoriginalTree
+                   {-# LINE 1274 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 1280 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 1286 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 1292 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 1298 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 1304 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- AlterDatabaseOperation --------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : AlterDatabaseOperation 
+         originalTree         : AlterDatabaseOperation 
+   alternatives:
+      alternative RenameDatabase:
+         child ann            : Annotation 
+         child newName        : Name 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data AlterDatabaseOperation = RenameDatabase (Annotation) (Name)
+                            deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_AlterDatabaseOperation :: AlterDatabaseOperation ->
+                              T_AlterDatabaseOperation
+_sem_AlterDatabaseOperation (RenameDatabase _ann _newName) =
+    (_sem_AlterDatabaseOperation_RenameDatabase (_sem_Annotation _ann) (_sem_Name _newName))
+-- semantic domain
+type T_AlterDatabaseOperation = Catalog ->
+                                TypeCheckFlags ->
+                                (Maybe TypeExtra) ->
+                                ( AlterDatabaseOperation,AlterDatabaseOperation)
+data Inh_AlterDatabaseOperation = Inh_AlterDatabaseOperation {_cat_Inh_AlterDatabaseOperation :: Catalog,_flags_Inh_AlterDatabaseOperation :: TypeCheckFlags,_imCast_Inh_AlterDatabaseOperation :: (Maybe TypeExtra)}
+data Syn_AlterDatabaseOperation = Syn_AlterDatabaseOperation {_annotatedTree_Syn_AlterDatabaseOperation :: AlterDatabaseOperation,_originalTree_Syn_AlterDatabaseOperation :: AlterDatabaseOperation}
+_wrap_AlterDatabaseOperation :: T_AlterDatabaseOperation ->
+                               Inh_AlterDatabaseOperation ->
+                               Syn_AlterDatabaseOperation
+_wrap_AlterDatabaseOperation sem (Inh_AlterDatabaseOperation _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_AlterDatabaseOperation _lhsOannotatedTree _lhsOoriginalTree))
+_sem_AlterDatabaseOperation_RenameDatabase :: T_Annotation ->
+                                             T_Name ->
+                                             T_AlterDatabaseOperation
+_sem_AlterDatabaseOperation_RenameDatabase ann_ newName_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _newNameOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterDatabaseOperation
+              _lhsOoriginalTree :: AlterDatabaseOperation
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _newNameOcat :: Catalog
+              _newNameOflags :: TypeCheckFlags
+              _newNameOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _newNameIannotatedTree :: Name
+              _newNameIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 30, column 45)
+              _annOtpe =
+                  ({-# LINE 30 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 1372 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 31, column 45)
+              _newNameOtpe =
+                  ({-# LINE 31 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 1378 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   RenameDatabase _annIannotatedTree _newNameIannotatedTree
+                   {-# LINE 1384 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   RenameDatabase _annIoriginalTree _newNameIoriginalTree
+                   {-# LINE 1390 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 1396 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 1402 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 1408 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 1414 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 1420 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _newNameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 1426 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _newNameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 1432 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _newNameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 1438 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _newNameIannotatedTree,_newNameIoriginalTree) =
+                  newName_ _newNameOcat _newNameOflags _newNameOimCast _newNameOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- AlterSchemaOperation ----------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : AlterSchemaOperation 
+         originalTree         : AlterSchemaOperation 
+   alternatives:
+      alternative AlterSchemaName:
+         child ann            : Annotation 
+         child newName        : {NameComponent}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterSchemaOwner:
+         child ann            : Annotation 
+         child newName        : Name 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data AlterSchemaOperation = AlterSchemaName (Annotation) (NameComponent)
+                          | AlterSchemaOwner (Annotation) (Name)
+                          deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_AlterSchemaOperation :: AlterSchemaOperation ->
+                            T_AlterSchemaOperation
+_sem_AlterSchemaOperation (AlterSchemaName _ann _newName) =
+    (_sem_AlterSchemaOperation_AlterSchemaName (_sem_Annotation _ann) _newName)
+_sem_AlterSchemaOperation (AlterSchemaOwner _ann _newName) =
+    (_sem_AlterSchemaOperation_AlterSchemaOwner (_sem_Annotation _ann) (_sem_Name _newName))
+-- semantic domain
+type T_AlterSchemaOperation = Catalog ->
+                              TypeCheckFlags ->
+                              (Maybe TypeExtra) ->
+                              ( AlterSchemaOperation,AlterSchemaOperation)
+data Inh_AlterSchemaOperation = Inh_AlterSchemaOperation {_cat_Inh_AlterSchemaOperation :: Catalog,_flags_Inh_AlterSchemaOperation :: TypeCheckFlags,_imCast_Inh_AlterSchemaOperation :: (Maybe TypeExtra)}
+data Syn_AlterSchemaOperation = Syn_AlterSchemaOperation {_annotatedTree_Syn_AlterSchemaOperation :: AlterSchemaOperation,_originalTree_Syn_AlterSchemaOperation :: AlterSchemaOperation}
+_wrap_AlterSchemaOperation :: T_AlterSchemaOperation ->
+                             Inh_AlterSchemaOperation ->
+                             Syn_AlterSchemaOperation
+_wrap_AlterSchemaOperation sem (Inh_AlterSchemaOperation _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_AlterSchemaOperation _lhsOannotatedTree _lhsOoriginalTree))
+_sem_AlterSchemaOperation_AlterSchemaName :: T_Annotation ->
+                                            NameComponent ->
+                                            T_AlterSchemaOperation
+_sem_AlterSchemaOperation_AlterSchemaName ann_ newName_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterSchemaOperation
+              _lhsOoriginalTree :: AlterSchemaOperation
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 32, column 44)
+              _annOtpe =
+                  ({-# LINE 32 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 1511 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSchemaName _annIannotatedTree newName_
+                   {-# LINE 1517 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSchemaName _annIoriginalTree newName_
+                   {-# LINE 1523 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 1529 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 1535 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 1541 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 1547 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 1553 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterSchemaOperation_AlterSchemaOwner :: T_Annotation ->
+                                             T_Name ->
+                                             T_AlterSchemaOperation
+_sem_AlterSchemaOperation_AlterSchemaOwner ann_ newName_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _newNameOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterSchemaOperation
+              _lhsOoriginalTree :: AlterSchemaOperation
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _newNameOcat :: Catalog
+              _newNameOflags :: TypeCheckFlags
+              _newNameOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _newNameIannotatedTree :: Name
+              _newNameIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 33, column 45)
+              _annOtpe =
+                  ({-# LINE 33 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 1583 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 34, column 45)
+              _newNameOtpe =
+                  ({-# LINE 34 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 1589 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSchemaOwner _annIannotatedTree _newNameIannotatedTree
+                   {-# LINE 1595 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSchemaOwner _annIoriginalTree _newNameIoriginalTree
+                   {-# LINE 1601 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 1607 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 1613 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 1619 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 1625 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 1631 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _newNameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 1637 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _newNameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 1643 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _newNameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 1649 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _newNameIannotatedTree,_newNameIoriginalTree) =
+                  newName_ _newNameOcat _newNameOflags _newNameOimCast _newNameOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- AlterSequenceAction -----------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : AlterSequenceAction 
+         originalTree         : AlterSequenceAction 
+   alternatives:
+      alternative AlterSequenceIncrement:
+         child ann            : Annotation 
+         child incr           : {Integer}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterSequenceMin:
+         child ann            : Annotation 
+         child min            : {Maybe Integer}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterSequenceMax:
+         child ann            : Annotation 
+         child max            : {Maybe Integer}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterSequenceStart:
+         child ann            : Annotation 
+         child start          : {Integer}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterSequenceRestart:
+         child ann            : Annotation 
+         child restart        : {Maybe Integer}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterSequenceCache:
+         child ann            : Annotation 
+         child cache          : {Integer}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data AlterSequenceAction = AlterSequenceIncrement (Annotation) (Integer)
+                         | AlterSequenceMin (Annotation) ((Maybe Integer))
+                         | AlterSequenceMax (Annotation) ((Maybe Integer))
+                         | AlterSequenceStart (Annotation) (Integer)
+                         | AlterSequenceRestart (Annotation) ((Maybe Integer))
+                         | AlterSequenceCache (Annotation) (Integer)
+                         deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_AlterSequenceAction :: AlterSequenceAction ->
+                           T_AlterSequenceAction
+_sem_AlterSequenceAction (AlterSequenceIncrement _ann _incr) =
+    (_sem_AlterSequenceAction_AlterSequenceIncrement (_sem_Annotation _ann) _incr)
+_sem_AlterSequenceAction (AlterSequenceMin _ann _min) =
+    (_sem_AlterSequenceAction_AlterSequenceMin (_sem_Annotation _ann) _min)
+_sem_AlterSequenceAction (AlterSequenceMax _ann _max) =
+    (_sem_AlterSequenceAction_AlterSequenceMax (_sem_Annotation _ann) _max)
+_sem_AlterSequenceAction (AlterSequenceStart _ann _start) =
+    (_sem_AlterSequenceAction_AlterSequenceStart (_sem_Annotation _ann) _start)
+_sem_AlterSequenceAction (AlterSequenceRestart _ann _restart) =
+    (_sem_AlterSequenceAction_AlterSequenceRestart (_sem_Annotation _ann) _restart)
+_sem_AlterSequenceAction (AlterSequenceCache _ann _cache) =
+    (_sem_AlterSequenceAction_AlterSequenceCache (_sem_Annotation _ann) _cache)
+-- semantic domain
+type T_AlterSequenceAction = Catalog ->
+                             TypeCheckFlags ->
+                             (Maybe TypeExtra) ->
+                             ( AlterSequenceAction,AlterSequenceAction)
+data Inh_AlterSequenceAction = Inh_AlterSequenceAction {_cat_Inh_AlterSequenceAction :: Catalog,_flags_Inh_AlterSequenceAction :: TypeCheckFlags,_imCast_Inh_AlterSequenceAction :: (Maybe TypeExtra)}
+data Syn_AlterSequenceAction = Syn_AlterSequenceAction {_annotatedTree_Syn_AlterSequenceAction :: AlterSequenceAction,_originalTree_Syn_AlterSequenceAction :: AlterSequenceAction}
+_wrap_AlterSequenceAction :: T_AlterSequenceAction ->
+                            Inh_AlterSequenceAction ->
+                            Syn_AlterSequenceAction
+_wrap_AlterSequenceAction sem (Inh_AlterSequenceAction _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_AlterSequenceAction _lhsOannotatedTree _lhsOoriginalTree))
+_sem_AlterSequenceAction_AlterSequenceIncrement :: T_Annotation ->
+                                                  Integer ->
+                                                  T_AlterSequenceAction
+_sem_AlterSequenceAction_AlterSequenceIncrement ann_ incr_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterSequenceAction
+              _lhsOoriginalTree :: AlterSequenceAction
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 35, column 50)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 1758 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceIncrement _annIannotatedTree incr_
+                   {-# LINE 1764 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceIncrement _annIoriginalTree incr_
+                   {-# LINE 1770 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 1776 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 1782 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 1788 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 1794 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 1800 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterSequenceAction_AlterSequenceMin :: T_Annotation ->
+                                            (Maybe Integer) ->
+                                            T_AlterSequenceAction
+_sem_AlterSequenceAction_AlterSequenceMin ann_ min_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterSequenceAction
+              _lhsOoriginalTree :: AlterSequenceAction
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 36, column 44)
+              _annOtpe =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 1824 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceMin _annIannotatedTree min_
+                   {-# LINE 1830 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceMin _annIoriginalTree min_
+                   {-# LINE 1836 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 1842 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 1848 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 1854 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 1860 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 1866 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterSequenceAction_AlterSequenceMax :: T_Annotation ->
+                                            (Maybe Integer) ->
+                                            T_AlterSequenceAction
+_sem_AlterSequenceAction_AlterSequenceMax ann_ max_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterSequenceAction
+              _lhsOoriginalTree :: AlterSequenceAction
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 37, column 44)
+              _annOtpe =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 1890 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceMax _annIannotatedTree max_
+                   {-# LINE 1896 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceMax _annIoriginalTree max_
+                   {-# LINE 1902 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 1908 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 1914 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 1920 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 1926 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 1932 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterSequenceAction_AlterSequenceStart :: T_Annotation ->
+                                              Integer ->
+                                              T_AlterSequenceAction
+_sem_AlterSequenceAction_AlterSequenceStart ann_ start_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterSequenceAction
+              _lhsOoriginalTree :: AlterSequenceAction
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 38, column 46)
+              _annOtpe =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 1956 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceStart _annIannotatedTree start_
+                   {-# LINE 1962 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceStart _annIoriginalTree start_
+                   {-# LINE 1968 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 1974 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 1980 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 1986 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 1992 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 1998 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterSequenceAction_AlterSequenceRestart :: T_Annotation ->
+                                                (Maybe Integer) ->
+                                                T_AlterSequenceAction
+_sem_AlterSequenceAction_AlterSequenceRestart ann_ restart_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterSequenceAction
+              _lhsOoriginalTree :: AlterSequenceAction
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 39, column 48)
+              _annOtpe =
+                  ({-# LINE 39 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 2022 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceRestart _annIannotatedTree restart_
+                   {-# LINE 2028 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceRestart _annIoriginalTree restart_
+                   {-# LINE 2034 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 2040 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 2046 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 2052 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 2058 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 2064 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterSequenceAction_AlterSequenceCache :: T_Annotation ->
+                                              Integer ->
+                                              T_AlterSequenceAction
+_sem_AlterSequenceAction_AlterSequenceCache ann_ cache_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterSequenceAction
+              _lhsOoriginalTree :: AlterSequenceAction
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 40, column 46)
+              _annOtpe =
+                  ({-# LINE 40 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 2088 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceCache _annIannotatedTree cache_
+                   {-# LINE 2094 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceCache _annIoriginalTree cache_
+                   {-# LINE 2100 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 2106 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 2112 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 2118 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 2124 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 2130 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- AlterSequenceActionList -------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : AlterSequenceActionList 
+         originalTree         : AlterSequenceActionList 
+   alternatives:
+      alternative Cons:
+         child hd             : AlterSequenceAction 
+         child tl             : AlterSequenceActionList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type AlterSequenceActionList = [AlterSequenceAction]
+-- cata
+_sem_AlterSequenceActionList :: AlterSequenceActionList ->
+                               T_AlterSequenceActionList
+_sem_AlterSequenceActionList list =
+    (Prelude.foldr _sem_AlterSequenceActionList_Cons _sem_AlterSequenceActionList_Nil (Prelude.map _sem_AlterSequenceAction list))
+-- semantic domain
+type T_AlterSequenceActionList = Catalog ->
+                                 TypeCheckFlags ->
+                                 (Maybe TypeExtra) ->
+                                 ( AlterSequenceActionList,AlterSequenceActionList)
+data Inh_AlterSequenceActionList = Inh_AlterSequenceActionList {_cat_Inh_AlterSequenceActionList :: Catalog,_flags_Inh_AlterSequenceActionList :: TypeCheckFlags,_imCast_Inh_AlterSequenceActionList :: (Maybe TypeExtra)}
+data Syn_AlterSequenceActionList = Syn_AlterSequenceActionList {_annotatedTree_Syn_AlterSequenceActionList :: AlterSequenceActionList,_originalTree_Syn_AlterSequenceActionList :: AlterSequenceActionList}
+_wrap_AlterSequenceActionList :: T_AlterSequenceActionList ->
+                                Inh_AlterSequenceActionList ->
+                                Syn_AlterSequenceActionList
+_wrap_AlterSequenceActionList sem (Inh_AlterSequenceActionList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_AlterSequenceActionList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_AlterSequenceActionList_Cons :: T_AlterSequenceAction ->
+                                    T_AlterSequenceActionList ->
+                                    T_AlterSequenceActionList
+_sem_AlterSequenceActionList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: AlterSequenceActionList
+              _lhsOoriginalTree :: AlterSequenceActionList
+              _hdOcat :: Catalog
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: AlterSequenceAction
+              _hdIoriginalTree :: AlterSequenceAction
+              _tlIannotatedTree :: AlterSequenceActionList
+              _tlIoriginalTree :: AlterSequenceActionList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 2199 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 2205 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 2211 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 2217 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 2223 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 2229 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 2235 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 2241 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 2247 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 2253 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree) =
+                  hd_ _hdOcat _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterSequenceActionList_Nil :: T_AlterSequenceActionList
+_sem_AlterSequenceActionList_Nil =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: AlterSequenceActionList
+              _lhsOoriginalTree :: AlterSequenceActionList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 2271 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 2277 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 2283 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 2289 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- AlterSequenceOperation --------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : AlterSequenceOperation 
+         originalTree         : AlterSequenceOperation 
+   alternatives:
+      alternative AlterSequenceOwned:
+         child ann            : Annotation 
+         child owned          : Name 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterSequenceRename:
+         child ann            : Annotation 
+         child name           : Name 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterSequenceActions:
+         child ann            : Annotation 
+         child actions        : AlterSequenceActionList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data AlterSequenceOperation = AlterSequenceOwned (Annotation) (Name)
+                            | AlterSequenceRename (Annotation) (Name)
+                            | AlterSequenceActions (Annotation) (AlterSequenceActionList)
+                            deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_AlterSequenceOperation :: AlterSequenceOperation ->
+                              T_AlterSequenceOperation
+_sem_AlterSequenceOperation (AlterSequenceOwned _ann _owned) =
+    (_sem_AlterSequenceOperation_AlterSequenceOwned (_sem_Annotation _ann) (_sem_Name _owned))
+_sem_AlterSequenceOperation (AlterSequenceRename _ann _name) =
+    (_sem_AlterSequenceOperation_AlterSequenceRename (_sem_Annotation _ann) (_sem_Name _name))
+_sem_AlterSequenceOperation (AlterSequenceActions _ann _actions) =
+    (_sem_AlterSequenceOperation_AlterSequenceActions (_sem_Annotation _ann) (_sem_AlterSequenceActionList _actions))
+-- semantic domain
+type T_AlterSequenceOperation = Catalog ->
+                                TypeCheckFlags ->
+                                (Maybe TypeExtra) ->
+                                ( AlterSequenceOperation,AlterSequenceOperation)
+data Inh_AlterSequenceOperation = Inh_AlterSequenceOperation {_cat_Inh_AlterSequenceOperation :: Catalog,_flags_Inh_AlterSequenceOperation :: TypeCheckFlags,_imCast_Inh_AlterSequenceOperation :: (Maybe TypeExtra)}
+data Syn_AlterSequenceOperation = Syn_AlterSequenceOperation {_annotatedTree_Syn_AlterSequenceOperation :: AlterSequenceOperation,_originalTree_Syn_AlterSequenceOperation :: AlterSequenceOperation}
+_wrap_AlterSequenceOperation :: T_AlterSequenceOperation ->
+                               Inh_AlterSequenceOperation ->
+                               Syn_AlterSequenceOperation
+_wrap_AlterSequenceOperation sem (Inh_AlterSequenceOperation _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_AlterSequenceOperation _lhsOannotatedTree _lhsOoriginalTree))
+_sem_AlterSequenceOperation_AlterSequenceOwned :: T_Annotation ->
+                                                 T_Name ->
+                                                 T_AlterSequenceOperation
+_sem_AlterSequenceOperation_AlterSequenceOwned ann_ owned_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _ownedOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterSequenceOperation
+              _lhsOoriginalTree :: AlterSequenceOperation
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _ownedOcat :: Catalog
+              _ownedOflags :: TypeCheckFlags
+              _ownedOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _ownedIannotatedTree :: Name
+              _ownedIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 41, column 49)
+              _annOtpe =
+                  ({-# LINE 41 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 2373 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 42, column 49)
+              _ownedOtpe =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 2379 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceOwned _annIannotatedTree _ownedIannotatedTree
+                   {-# LINE 2385 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceOwned _annIoriginalTree _ownedIoriginalTree
+                   {-# LINE 2391 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 2397 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 2403 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 2409 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 2415 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 2421 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _ownedOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 2427 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _ownedOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 2433 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _ownedOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 2439 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _ownedIannotatedTree,_ownedIoriginalTree) =
+                  owned_ _ownedOcat _ownedOflags _ownedOimCast _ownedOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterSequenceOperation_AlterSequenceRename :: T_Annotation ->
+                                                  T_Name ->
+                                                  T_AlterSequenceOperation
+_sem_AlterSequenceOperation_AlterSequenceRename ann_ name_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _nameOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterSequenceOperation
+              _lhsOoriginalTree :: AlterSequenceOperation
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nameOcat :: Catalog
+              _nameOflags :: TypeCheckFlags
+              _nameOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nameIannotatedTree :: Name
+              _nameIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 43, column 50)
+              _annOtpe =
+                  ({-# LINE 43 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 2471 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 44, column 50)
+              _nameOtpe =
+                  ({-# LINE 44 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 2477 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceRename _annIannotatedTree _nameIannotatedTree
+                   {-# LINE 2483 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceRename _annIoriginalTree _nameIoriginalTree
+                   {-# LINE 2489 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 2495 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 2501 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 2507 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 2513 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 2519 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 2525 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 2531 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 2537 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nameIannotatedTree,_nameIoriginalTree) =
+                  name_ _nameOcat _nameOflags _nameOimCast _nameOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterSequenceOperation_AlterSequenceActions :: T_Annotation ->
+                                                   T_AlterSequenceActionList ->
+                                                   T_AlterSequenceOperation
+_sem_AlterSequenceOperation_AlterSequenceActions ann_ actions_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterSequenceOperation
+              _lhsOoriginalTree :: AlterSequenceOperation
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _actionsOcat :: Catalog
+              _actionsOflags :: TypeCheckFlags
+              _actionsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _actionsIannotatedTree :: AlterSequenceActionList
+              _actionsIoriginalTree :: AlterSequenceActionList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 45, column 51)
+              _annOtpe =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 2568 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceActions _annIannotatedTree _actionsIannotatedTree
+                   {-# LINE 2574 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequenceActions _annIoriginalTree _actionsIoriginalTree
+                   {-# LINE 2580 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 2586 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 2592 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 2598 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 2604 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 2610 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _actionsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 2616 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _actionsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 2622 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _actionsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 2628 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _actionsIannotatedTree,_actionsIoriginalTree) =
+                  actions_ _actionsOcat _actionsOflags _actionsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- AlterTableAction --------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : AlterTableAction 
+         originalTree         : AlterTableAction 
+   alternatives:
+      alternative AddColumn:
+         child ann            : Annotation 
+         child att            : AttributeDef 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative DropColumn:
+         child ann            : Annotation 
+         child nm             : {NameComponent}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterColumn:
+         child ann            : Annotation 
+         child nm             : {NameComponent}
+         child act            : AlterColumnAction 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AddConstraint:
+         child ann            : Annotation 
+         child con            : Constraint 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data AlterTableAction = AddColumn (Annotation) (AttributeDef)
+                      | DropColumn (Annotation) (NameComponent)
+                      | AlterColumn (Annotation) (NameComponent) (AlterColumnAction)
+                      | AddConstraint (Annotation) (Constraint)
+                      deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_AlterTableAction :: AlterTableAction ->
+                        T_AlterTableAction
+_sem_AlterTableAction (AddColumn _ann _att) =
+    (_sem_AlterTableAction_AddColumn (_sem_Annotation _ann) (_sem_AttributeDef _att))
+_sem_AlterTableAction (DropColumn _ann _nm) =
+    (_sem_AlterTableAction_DropColumn (_sem_Annotation _ann) _nm)
+_sem_AlterTableAction (AlterColumn _ann _nm _act) =
+    (_sem_AlterTableAction_AlterColumn (_sem_Annotation _ann) _nm (_sem_AlterColumnAction _act))
+_sem_AlterTableAction (AddConstraint _ann _con) =
+    (_sem_AlterTableAction_AddConstraint (_sem_Annotation _ann) (_sem_Constraint _con))
+-- semantic domain
+type T_AlterTableAction = Catalog ->
+                          TypeCheckFlags ->
+                          (Maybe TypeExtra) ->
+                          ( AlterTableAction,AlterTableAction)
+data Inh_AlterTableAction = Inh_AlterTableAction {_cat_Inh_AlterTableAction :: Catalog,_flags_Inh_AlterTableAction :: TypeCheckFlags,_imCast_Inh_AlterTableAction :: (Maybe TypeExtra)}
+data Syn_AlterTableAction = Syn_AlterTableAction {_annotatedTree_Syn_AlterTableAction :: AlterTableAction,_originalTree_Syn_AlterTableAction :: AlterTableAction}
+_wrap_AlterTableAction :: T_AlterTableAction ->
+                         Inh_AlterTableAction ->
+                         Syn_AlterTableAction
+_wrap_AlterTableAction sem (Inh_AlterTableAction _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_AlterTableAction _lhsOannotatedTree _lhsOoriginalTree))
+_sem_AlterTableAction_AddColumn :: T_Annotation ->
+                                  T_AttributeDef ->
+                                  T_AlterTableAction
+_sem_AlterTableAction_AddColumn ann_ att_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterTableAction
+              _lhsOoriginalTree :: AlterTableAction
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _attOcat :: Catalog
+              _attOflags :: TypeCheckFlags
+              _attOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _attIannotatedTree :: AttributeDef
+              _attIoriginalTree :: AttributeDef
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 46, column 34)
+              _annOtpe =
+                  ({-# LINE 46 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 2725 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AddColumn _annIannotatedTree _attIannotatedTree
+                   {-# LINE 2731 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AddColumn _annIoriginalTree _attIoriginalTree
+                   {-# LINE 2737 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 2743 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 2749 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 2755 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 2761 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 2767 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _attOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 2773 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _attOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 2779 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _attOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 2785 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _attIannotatedTree,_attIoriginalTree) =
+                  att_ _attOcat _attOflags _attOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterTableAction_DropColumn :: T_Annotation ->
+                                   NameComponent ->
+                                   T_AlterTableAction
+_sem_AlterTableAction_DropColumn ann_ nm_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterTableAction
+              _lhsOoriginalTree :: AlterTableAction
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 49, column 35)
+              _annOtpe =
+                  ({-# LINE 49 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 2811 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   DropColumn _annIannotatedTree nm_
+                   {-# LINE 2817 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   DropColumn _annIoriginalTree nm_
+                   {-# LINE 2823 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 2829 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 2835 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 2841 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 2847 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 2853 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterTableAction_AlterColumn :: T_Annotation ->
+                                    NameComponent ->
+                                    T_AlterColumnAction ->
+                                    T_AlterTableAction
+_sem_AlterTableAction_AlterColumn ann_ nm_ act_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterTableAction
+              _lhsOoriginalTree :: AlterTableAction
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _actOcat :: Catalog
+              _actOflags :: TypeCheckFlags
+              _actOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _actIannotatedTree :: AlterColumnAction
+              _actIoriginalTree :: AlterColumnAction
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 48, column 36)
+              _annOtpe =
+                  ({-# LINE 48 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 2883 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterColumn _annIannotatedTree nm_ _actIannotatedTree
+                   {-# LINE 2889 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterColumn _annIoriginalTree nm_ _actIoriginalTree
+                   {-# LINE 2895 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 2901 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 2907 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 2913 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 2919 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 2925 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _actOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 2931 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _actOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 2937 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _actOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 2943 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _actIannotatedTree,_actIoriginalTree) =
+                  act_ _actOcat _actOflags _actOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterTableAction_AddConstraint :: T_Annotation ->
+                                      T_Constraint ->
+                                      T_AlterTableAction
+_sem_AlterTableAction_AddConstraint ann_ con_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterTableAction
+              _lhsOoriginalTree :: AlterTableAction
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _conOcat :: Catalog
+              _conOflags :: TypeCheckFlags
+              _conOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _conIannotatedTree :: Constraint
+              _conIoriginalTree :: Constraint
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 47, column 38)
+              _annOtpe =
+                  ({-# LINE 47 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 2974 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AddConstraint _annIannotatedTree _conIannotatedTree
+                   {-# LINE 2980 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AddConstraint _annIoriginalTree _conIoriginalTree
+                   {-# LINE 2986 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 2992 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 2998 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 3004 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 3010 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 3016 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _conOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 3022 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _conOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 3028 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _conOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 3034 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _conIannotatedTree,_conIoriginalTree) =
+                  con_ _conOcat _conOflags _conOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- AlterTableActionList ----------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : AlterTableActionList 
+         originalTree         : AlterTableActionList 
+   alternatives:
+      alternative Cons:
+         child hd             : AlterTableAction 
+         child tl             : AlterTableActionList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type AlterTableActionList = [AlterTableAction]
+-- cata
+_sem_AlterTableActionList :: AlterTableActionList ->
+                            T_AlterTableActionList
+_sem_AlterTableActionList list =
+    (Prelude.foldr _sem_AlterTableActionList_Cons _sem_AlterTableActionList_Nil (Prelude.map _sem_AlterTableAction list))
+-- semantic domain
+type T_AlterTableActionList = Catalog ->
+                              TypeCheckFlags ->
+                              (Maybe TypeExtra) ->
+                              ( AlterTableActionList,AlterTableActionList)
+data Inh_AlterTableActionList = Inh_AlterTableActionList {_cat_Inh_AlterTableActionList :: Catalog,_flags_Inh_AlterTableActionList :: TypeCheckFlags,_imCast_Inh_AlterTableActionList :: (Maybe TypeExtra)}
+data Syn_AlterTableActionList = Syn_AlterTableActionList {_annotatedTree_Syn_AlterTableActionList :: AlterTableActionList,_originalTree_Syn_AlterTableActionList :: AlterTableActionList}
+_wrap_AlterTableActionList :: T_AlterTableActionList ->
+                             Inh_AlterTableActionList ->
+                             Syn_AlterTableActionList
+_wrap_AlterTableActionList sem (Inh_AlterTableActionList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_AlterTableActionList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_AlterTableActionList_Cons :: T_AlterTableAction ->
+                                 T_AlterTableActionList ->
+                                 T_AlterTableActionList
+_sem_AlterTableActionList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: AlterTableActionList
+              _lhsOoriginalTree :: AlterTableActionList
+              _hdOcat :: Catalog
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: AlterTableAction
+              _hdIoriginalTree :: AlterTableAction
+              _tlIannotatedTree :: AlterTableActionList
+              _tlIoriginalTree :: AlterTableActionList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 3105 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 3111 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 3117 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 3123 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 3129 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 3135 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 3141 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 3147 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 3153 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 3159 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree) =
+                  hd_ _hdOcat _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterTableActionList_Nil :: T_AlterTableActionList
+_sem_AlterTableActionList_Nil =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: AlterTableActionList
+              _lhsOoriginalTree :: AlterTableActionList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 3177 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 3183 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 3189 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 3195 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- AlterTableOperation -----------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : AlterTableOperation 
+         originalTree         : AlterTableOperation 
+   alternatives:
+      alternative RenameTable:
+         child ann            : Annotation 
+         child newName        : Name 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative RenameColumn:
+         child ann            : Annotation 
+         child oldName        : {NameComponent}
+         child newName        : {NameComponent}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterTableActions:
+         child ann            : Annotation 
+         child actions        : AlterTableActionList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data AlterTableOperation = RenameTable (Annotation) (Name)
+                         | RenameColumn (Annotation) (NameComponent) (NameComponent)
+                         | AlterTableActions (Annotation) (AlterTableActionList)
+                         deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_AlterTableOperation :: AlterTableOperation ->
+                           T_AlterTableOperation
+_sem_AlterTableOperation (RenameTable _ann _newName) =
+    (_sem_AlterTableOperation_RenameTable (_sem_Annotation _ann) (_sem_Name _newName))
+_sem_AlterTableOperation (RenameColumn _ann _oldName _newName) =
+    (_sem_AlterTableOperation_RenameColumn (_sem_Annotation _ann) _oldName _newName)
+_sem_AlterTableOperation (AlterTableActions _ann _actions) =
+    (_sem_AlterTableOperation_AlterTableActions (_sem_Annotation _ann) (_sem_AlterTableActionList _actions))
+-- semantic domain
+type T_AlterTableOperation = Catalog ->
+                             TypeCheckFlags ->
+                             (Maybe TypeExtra) ->
+                             ( AlterTableOperation,AlterTableOperation)
+data Inh_AlterTableOperation = Inh_AlterTableOperation {_cat_Inh_AlterTableOperation :: Catalog,_flags_Inh_AlterTableOperation :: TypeCheckFlags,_imCast_Inh_AlterTableOperation :: (Maybe TypeExtra)}
+data Syn_AlterTableOperation = Syn_AlterTableOperation {_annotatedTree_Syn_AlterTableOperation :: AlterTableOperation,_originalTree_Syn_AlterTableOperation :: AlterTableOperation}
+_wrap_AlterTableOperation :: T_AlterTableOperation ->
+                            Inh_AlterTableOperation ->
+                            Syn_AlterTableOperation
+_wrap_AlterTableOperation sem (Inh_AlterTableOperation _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_AlterTableOperation _lhsOannotatedTree _lhsOoriginalTree))
+_sem_AlterTableOperation_RenameTable :: T_Annotation ->
+                                       T_Name ->
+                                       T_AlterTableOperation
+_sem_AlterTableOperation_RenameTable ann_ newName_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _newNameOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterTableOperation
+              _lhsOoriginalTree :: AlterTableOperation
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _newNameOcat :: Catalog
+              _newNameOflags :: TypeCheckFlags
+              _newNameOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _newNameIannotatedTree :: Name
+              _newNameIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 52, column 39)
+              _annOtpe =
+                  ({-# LINE 52 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 3280 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 53, column 39)
+              _newNameOtpe =
+                  ({-# LINE 53 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 3286 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   RenameTable _annIannotatedTree _newNameIannotatedTree
+                   {-# LINE 3292 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   RenameTable _annIoriginalTree _newNameIoriginalTree
+                   {-# LINE 3298 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 3304 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 3310 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 3316 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 3322 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 3328 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _newNameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 3334 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _newNameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 3340 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _newNameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 3346 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _newNameIannotatedTree,_newNameIoriginalTree) =
+                  newName_ _newNameOcat _newNameOflags _newNameOimCast _newNameOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterTableOperation_RenameColumn :: T_Annotation ->
+                                        NameComponent ->
+                                        NameComponent ->
+                                        T_AlterTableOperation
+_sem_AlterTableOperation_RenameColumn ann_ oldName_ newName_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterTableOperation
+              _lhsOoriginalTree :: AlterTableOperation
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 51, column 40)
+              _annOtpe =
+                  ({-# LINE 51 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 3373 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   RenameColumn _annIannotatedTree oldName_ newName_
+                   {-# LINE 3379 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   RenameColumn _annIoriginalTree oldName_ newName_
+                   {-# LINE 3385 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 3391 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 3397 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 3403 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 3409 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 3415 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AlterTableOperation_AlterTableActions :: T_Annotation ->
+                                             T_AlterTableActionList ->
+                                             T_AlterTableOperation
+_sem_AlterTableOperation_AlterTableActions ann_ actions_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: AlterTableOperation
+              _lhsOoriginalTree :: AlterTableOperation
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _actionsOcat :: Catalog
+              _actionsOflags :: TypeCheckFlags
+              _actionsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _actionsIannotatedTree :: AlterTableActionList
+              _actionsIoriginalTree :: AlterTableActionList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 50, column 45)
+              _annOtpe =
+                  ({-# LINE 50 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 3444 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterTableActions _annIannotatedTree _actionsIannotatedTree
+                   {-# LINE 3450 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterTableActions _annIoriginalTree _actionsIoriginalTree
+                   {-# LINE 3456 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 3462 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 3468 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 3474 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 3480 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 3486 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _actionsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 3492 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _actionsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 3498 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _actionsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 3504 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _actionsIannotatedTree,_actionsIoriginalTree) =
+                  actions_ _actionsOcat _actionsOflags _actionsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- Annotation --------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+         tpe                  : Either [TypeError] TypeExtra
+      synthesized attributes:
+         annotatedTree        : Annotation 
+         originalTree         : Annotation 
+   alternatives:
+      alternative Annotation:
+         child anSrc          : {Maybe SourcePosition}
+         child anType         : {Maybe T.TypeExtra}
+         child anErrs         : {[T.TypeError]}
+         child anImplicitCast : {Maybe T.TypeExtra}
+         child anCatUpd       : {[C.CatalogUpdate]}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+
+-- | Annotation type - one of these is attached to most of the
+-- data types used in the ast.
+-- the fields in order are:
+data Annotation = Annotation {
+                             -- | source position for this node
+                             anSrc :: ( Maybe SourcePosition)
+                             -- | type of the node, 'Nothing' if the tree hasn't been typechecked or if a type error elsewhere prevents determining this node's type
+                             ,anType :: ( Maybe T.TypeExtra)
+                             -- | any type errors
+                             ,anErrs :: ( [T.TypeError])
+                             -- | if an implicit cast is needed between this node an its parent, this the target type of cast. If no implicit cast is needed, this is Nothing
+                             ,anImplicitCast :: ( Maybe T.TypeExtra)
+                             -- | any catalog updates that a statement produces, used only for ddl Statements
+                             ,anCatUpd :: ( [C.CatalogUpdate])
+
+    } deriving (Eq,Show,Data,Typeable)
+
+-- cata
+_sem_Annotation :: Annotation ->
+                  T_Annotation
+_sem_Annotation (Annotation _anSrc _anType _anErrs _anImplicitCast _anCatUpd) =
+    (_sem_Annotation_Annotation _anSrc _anType _anErrs _anImplicitCast _anCatUpd)
+-- semantic domain
+type T_Annotation = Catalog ->
+                    TypeCheckFlags ->
+                    (Maybe TypeExtra) ->
+                    (Either [TypeError] TypeExtra) ->
+                    ( Annotation,Annotation)
+data Inh_Annotation = Inh_Annotation {_cat_Inh_Annotation :: Catalog,_flags_Inh_Annotation :: TypeCheckFlags,_imCast_Inh_Annotation :: (Maybe TypeExtra),_tpe_Inh_Annotation :: (Either [TypeError] TypeExtra)}
+data Syn_Annotation = Syn_Annotation {_annotatedTree_Syn_Annotation :: Annotation,_originalTree_Syn_Annotation :: Annotation}
+_wrap_Annotation :: T_Annotation ->
+                   Inh_Annotation ->
+                   Syn_Annotation
+_wrap_Annotation sem (Inh_Annotation _lhsIcat _lhsIflags _lhsIimCast _lhsItpe) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast _lhsItpe
+     in  (Syn_Annotation _lhsOannotatedTree _lhsOoriginalTree))
+_sem_Annotation_Annotation :: (Maybe SourcePosition) ->
+                             (Maybe T.TypeExtra) ->
+                             ([T.TypeError]) ->
+                             (Maybe T.TypeExtra) ->
+                             ([C.CatalogUpdate]) ->
+                             T_Annotation
+_sem_Annotation_Annotation anSrc_ anType_ anErrs_ anImplicitCast_ anCatUpd_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast
+       _lhsItpe ->
+         (let _lhsOannotatedTree :: Annotation
+              _lhsOoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag"(line 140, column 7)
+              _lhsOannotatedTree =
+                  ({-# LINE 140 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   let t = either (const Nothing) Just _lhsItpe
+                       es = either id (const []) _lhsItpe
+                   in Annotation anSrc_ t es _lhsIimCast anCatUpd_
+                   {-# LINE 3573 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Annotation anSrc_ anType_ anErrs_ anImplicitCast_ anCatUpd_
+                   {-# LINE 3579 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Annotation anSrc_ anType_ anErrs_ anImplicitCast_ anCatUpd_
+                   {-# LINE 3585 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 3591 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- AttributeDef ------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : AttributeDef 
+         originalTree         : AttributeDef 
+   alternatives:
+      alternative AttributeDef:
+         child ann            : Annotation 
+         child name           : {NameComponent}
+         child typ            : TypeName 
+         child def            : MaybeScalarExpr 
+         child cons           : RowConstraintList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data AttributeDef = AttributeDef (Annotation) (NameComponent) (TypeName) (MaybeScalarExpr) (RowConstraintList)
+                  deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_AttributeDef :: AttributeDef ->
+                    T_AttributeDef
+_sem_AttributeDef (AttributeDef _ann _name _typ _def _cons) =
+    (_sem_AttributeDef_AttributeDef (_sem_Annotation _ann) _name (_sem_TypeName _typ) (_sem_MaybeScalarExpr _def) (_sem_RowConstraintList _cons))
+-- semantic domain
+type T_AttributeDef = Catalog ->
+                      TypeCheckFlags ->
+                      (Maybe TypeExtra) ->
+                      ( AttributeDef,AttributeDef)
+data Inh_AttributeDef = Inh_AttributeDef {_cat_Inh_AttributeDef :: Catalog,_flags_Inh_AttributeDef :: TypeCheckFlags,_imCast_Inh_AttributeDef :: (Maybe TypeExtra)}
+data Syn_AttributeDef = Syn_AttributeDef {_annotatedTree_Syn_AttributeDef :: AttributeDef,_originalTree_Syn_AttributeDef :: AttributeDef}
+_wrap_AttributeDef :: T_AttributeDef ->
+                     Inh_AttributeDef ->
+                     Syn_AttributeDef
+_wrap_AttributeDef sem (Inh_AttributeDef _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_AttributeDef _lhsOannotatedTree _lhsOoriginalTree))
+_sem_AttributeDef_AttributeDef :: T_Annotation ->
+                                 NameComponent ->
+                                 T_TypeName ->
+                                 T_MaybeScalarExpr ->
+                                 T_RowConstraintList ->
+                                 T_AttributeDef
+_sem_AttributeDef_AttributeDef ann_ name_ typ_ def_ cons_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _defOdownEnv :: Environment
+              _defOexpectedCast :: Bool
+              _defOexpectedType :: (Maybe TypeExtra)
+              _defOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: AttributeDef
+              _lhsOoriginalTree :: AttributeDef
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _typOcat :: Catalog
+              _typOflags :: TypeCheckFlags
+              _typOimCast :: (Maybe TypeExtra)
+              _defOcat :: Catalog
+              _defOflags :: TypeCheckFlags
+              _defOimCast :: (Maybe TypeExtra)
+              _consOcat :: Catalog
+              _consOflags :: TypeCheckFlags
+              _consOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _typIannotatedTree :: TypeName
+              _typInamedType :: (Maybe TypeExtra)
+              _typIoriginalTree :: TypeName
+              _defIannotatedTree :: MaybeScalarExpr
+              _defIoriginalTree :: MaybeScalarExpr
+              _defIupType :: (Maybe TypeExtra)
+              _consIannotatedTree :: RowConstraintList
+              _consIoriginalTree :: RowConstraintList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 54, column 33)
+              _annOtpe =
+                  ({-# LINE 54 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 3678 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 55, column 33)
+              _defOdownEnv =
+                  ({-# LINE 55 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 3684 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 56, column 33)
+              _defOexpectedCast =
+                  ({-# LINE 56 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 3690 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 57, column 33)
+              _defOexpectedType =
+                  ({-# LINE 57 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 3696 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 807, column 33)
+              _defOassignmentCastContext =
+                  ({-# LINE 807 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 3702 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AttributeDef _annIannotatedTree name_ _typIannotatedTree _defIannotatedTree _consIannotatedTree
+                   {-# LINE 3708 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AttributeDef _annIoriginalTree name_ _typIoriginalTree _defIoriginalTree _consIoriginalTree
+                   {-# LINE 3714 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 3720 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 3726 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 3732 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 3738 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 3744 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 3750 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 3756 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 3762 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _defOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 3768 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _defOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 3774 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _defOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 3780 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _consOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 3786 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _consOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 3792 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _consOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 3798 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _typIannotatedTree,_typInamedType,_typIoriginalTree) =
+                  typ_ _typOcat _typOflags _typOimCast
+              ( _defIannotatedTree,_defIoriginalTree,_defIupType) =
+                  def_ _defOassignmentCastContext _defOcat _defOdownEnv _defOexpectedCast _defOexpectedType _defOflags _defOimCast
+              ( _consIannotatedTree,_consIoriginalTree) =
+                  cons_ _consOcat _consOflags _consOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- AttributeDefList --------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : AttributeDefList 
+         originalTree         : AttributeDefList 
+   alternatives:
+      alternative Cons:
+         child hd             : AttributeDef 
+         child tl             : AttributeDefList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type AttributeDefList = [AttributeDef]
+-- cata
+_sem_AttributeDefList :: AttributeDefList ->
+                        T_AttributeDefList
+_sem_AttributeDefList list =
+    (Prelude.foldr _sem_AttributeDefList_Cons _sem_AttributeDefList_Nil (Prelude.map _sem_AttributeDef list))
+-- semantic domain
+type T_AttributeDefList = Catalog ->
+                          TypeCheckFlags ->
+                          (Maybe TypeExtra) ->
+                          ( AttributeDefList,AttributeDefList)
+data Inh_AttributeDefList = Inh_AttributeDefList {_cat_Inh_AttributeDefList :: Catalog,_flags_Inh_AttributeDefList :: TypeCheckFlags,_imCast_Inh_AttributeDefList :: (Maybe TypeExtra)}
+data Syn_AttributeDefList = Syn_AttributeDefList {_annotatedTree_Syn_AttributeDefList :: AttributeDefList,_originalTree_Syn_AttributeDefList :: AttributeDefList}
+_wrap_AttributeDefList :: T_AttributeDefList ->
+                         Inh_AttributeDefList ->
+                         Syn_AttributeDefList
+_wrap_AttributeDefList sem (Inh_AttributeDefList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_AttributeDefList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_AttributeDefList_Cons :: T_AttributeDef ->
+                             T_AttributeDefList ->
+                             T_AttributeDefList
+_sem_AttributeDefList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: AttributeDefList
+              _lhsOoriginalTree :: AttributeDefList
+              _hdOcat :: Catalog
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: AttributeDef
+              _hdIoriginalTree :: AttributeDef
+              _tlIannotatedTree :: AttributeDefList
+              _tlIoriginalTree :: AttributeDefList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 3873 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 3879 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 3885 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 3891 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 3897 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 3903 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 3909 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 3915 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 3921 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 3927 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree) =
+                  hd_ _hdOcat _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_AttributeDefList_Nil :: T_AttributeDefList
+_sem_AttributeDefList_Nil =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: AttributeDefList
+              _lhsOoriginalTree :: AttributeDefList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 3945 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 3951 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 3957 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 3963 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- CaseScalarExprListScalarExprPair ----------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         downEnv              : Environment
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+         thenExpectedType     : Maybe TypeExtra
+         whenExpectedType     : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : CaseScalarExprListScalarExprPair 
+         originalTree         : CaseScalarExprListScalarExprPair 
+         thenType             : Maybe TypeExtra
+         upTypes              : [Maybe TypeExtra]
+         whenTypes            : [Maybe TypeExtra]
+   alternatives:
+      alternative Tuple:
+         child x1             : ScalarExprList 
+         child x2             : ScalarExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type CaseScalarExprListScalarExprPair = ( ScalarExprList,ScalarExpr)
+-- cata
+_sem_CaseScalarExprListScalarExprPair :: CaseScalarExprListScalarExprPair ->
+                                        T_CaseScalarExprListScalarExprPair
+_sem_CaseScalarExprListScalarExprPair ( x1,x2) =
+    (_sem_CaseScalarExprListScalarExprPair_Tuple (_sem_ScalarExprList x1) (_sem_ScalarExpr x2))
+-- semantic domain
+type T_CaseScalarExprListScalarExprPair = Catalog ->
+                                          Environment ->
+                                          TypeCheckFlags ->
+                                          (Maybe TypeExtra) ->
+                                          (Maybe TypeExtra) ->
+                                          (Maybe TypeExtra) ->
+                                          ( CaseScalarExprListScalarExprPair,CaseScalarExprListScalarExprPair,(Maybe TypeExtra),([Maybe TypeExtra]),([Maybe TypeExtra]))
+data Inh_CaseScalarExprListScalarExprPair = Inh_CaseScalarExprListScalarExprPair {_cat_Inh_CaseScalarExprListScalarExprPair :: Catalog,_downEnv_Inh_CaseScalarExprListScalarExprPair :: Environment,_flags_Inh_CaseScalarExprListScalarExprPair :: TypeCheckFlags,_imCast_Inh_CaseScalarExprListScalarExprPair :: (Maybe TypeExtra),_thenExpectedType_Inh_CaseScalarExprListScalarExprPair :: (Maybe TypeExtra),_whenExpectedType_Inh_CaseScalarExprListScalarExprPair :: (Maybe TypeExtra)}
+data Syn_CaseScalarExprListScalarExprPair = Syn_CaseScalarExprListScalarExprPair {_annotatedTree_Syn_CaseScalarExprListScalarExprPair :: CaseScalarExprListScalarExprPair,_originalTree_Syn_CaseScalarExprListScalarExprPair :: CaseScalarExprListScalarExprPair,_thenType_Syn_CaseScalarExprListScalarExprPair :: (Maybe TypeExtra),_upTypes_Syn_CaseScalarExprListScalarExprPair :: ([Maybe TypeExtra]),_whenTypes_Syn_CaseScalarExprListScalarExprPair :: ([Maybe TypeExtra])}
+_wrap_CaseScalarExprListScalarExprPair :: T_CaseScalarExprListScalarExprPair ->
+                                         Inh_CaseScalarExprListScalarExprPair ->
+                                         Syn_CaseScalarExprListScalarExprPair
+_wrap_CaseScalarExprListScalarExprPair sem (Inh_CaseScalarExprListScalarExprPair _lhsIcat _lhsIdownEnv _lhsIflags _lhsIimCast _lhsIthenExpectedType _lhsIwhenExpectedType) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOthenType,_lhsOupTypes,_lhsOwhenTypes) = sem _lhsIcat _lhsIdownEnv _lhsIflags _lhsIimCast _lhsIthenExpectedType _lhsIwhenExpectedType
+     in  (Syn_CaseScalarExprListScalarExprPair _lhsOannotatedTree _lhsOoriginalTree _lhsOthenType _lhsOupTypes _lhsOwhenTypes))
+_sem_CaseScalarExprListScalarExprPair_Tuple :: T_ScalarExprList ->
+                                              T_ScalarExpr ->
+                                              T_CaseScalarExprListScalarExprPair
+_sem_CaseScalarExprListScalarExprPair_Tuple x1_ x2_ =
+    (\ _lhsIcat
+       _lhsIdownEnv
+       _lhsIflags
+       _lhsIimCast
+       _lhsIthenExpectedType
+       _lhsIwhenExpectedType ->
+         (let _x2OodbcFunction :: Bool
+              _lhsOwhenTypes :: ([Maybe TypeExtra])
+              _lhsOthenType :: (Maybe TypeExtra)
+              _x1OexpectedTypes :: ([TypeExtra])
+              _x1OexpectedCast :: Bool
+              _x2OexpectedType :: (Maybe TypeExtra)
+              _x2OexpectedCast :: Bool
+              _x1OassignmentCastContext :: Bool
+              _x2OassignmentCastContext :: Bool
+              _lhsOannotatedTree :: CaseScalarExprListScalarExprPair
+              _lhsOoriginalTree :: CaseScalarExprListScalarExprPair
+              _lhsOupTypes :: ([Maybe TypeExtra])
+              _x1Ocat :: Catalog
+              _x1OdownEnv :: Environment
+              _x1Oflags :: TypeCheckFlags
+              _x1OimCast :: (Maybe TypeExtra)
+              _x2Ocat :: Catalog
+              _x2OdownEnv :: Environment
+              _x2Oflags :: TypeCheckFlags
+              _x2OimCast :: (Maybe TypeExtra)
+              _x1IannotatedTree :: ScalarExprList
+              _x1IoriginalTree :: ScalarExprList
+              _x1IupTypes :: ([Maybe TypeExtra])
+              _x2IannotatedTree :: ScalarExpr
+              _x2IcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _x2IoriginalTree :: ScalarExpr
+              _x2IupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 134, column 13)
+              _x2OodbcFunction =
+                  ({-# LINE 134 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 4053 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 549, column 13)
+              _lhsOwhenTypes =
+                  ({-# LINE 549 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _x1IupTypes
+                   {-# LINE 4059 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 550, column 13)
+              _lhsOthenType =
+                  ({-# LINE 550 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _x2IupType
+                   {-# LINE 4065 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 605, column 11)
+              _x1OexpectedTypes =
+                  ({-# LINE 605 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe [] repeat _lhsIwhenExpectedType
+                   {-# LINE 4071 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 606, column 11)
+              _x1OexpectedCast =
+                  ({-# LINE 606 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 4077 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 607, column 11)
+              _x2OexpectedType =
+                  ({-# LINE 607 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIthenExpectedType
+                   {-# LINE 4083 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 608, column 11)
+              _x2OexpectedCast =
+                  ({-# LINE 608 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   True
+                   {-# LINE 4089 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 808, column 46)
+              _x1OassignmentCastContext =
+                  ({-# LINE 808 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 4095 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 809, column 46)
+              _x2OassignmentCastContext =
+                  ({-# LINE 809 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 4101 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (_x1IannotatedTree,_x2IannotatedTree)
+                   {-# LINE 4107 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (_x1IoriginalTree,_x2IoriginalTree)
+                   {-# LINE 4113 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 4119 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 4125 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (up)
+              _lhsOupTypes =
+                  ({-# LINE 554 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _x1IupTypes
+                   {-# LINE 4131 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1Ocat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 4137 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1OdownEnv =
+                  ({-# LINE 189 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 4143 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1Oflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 4149 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1OimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 4155 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x2Ocat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 4161 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x2OdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 4167 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x2Oflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 4173 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x2OimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 4179 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _x1IannotatedTree,_x1IoriginalTree,_x1IupTypes) =
+                  x1_ _x1OassignmentCastContext _x1Ocat _x1OdownEnv _x1OexpectedCast _x1OexpectedTypes _x1Oflags _x1OimCast
+              ( _x2IannotatedTree,_x2IcolExprs,_x2IoriginalTree,_x2IupType) =
+                  x2_ _x2OassignmentCastContext _x2Ocat _x2OdownEnv _x2OexpectedCast _x2OexpectedType _x2Oflags _x2OimCast _x2OodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOthenType,_lhsOupTypes,_lhsOwhenTypes)))
+-- CaseScalarExprListScalarExprPairList ------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         downEnv              : Environment
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+         thenExpectedType     : Maybe TypeExtra
+         whenExpectedType     : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : CaseScalarExprListScalarExprPairList 
+         originalTree         : CaseScalarExprListScalarExprPairList 
+         thenTypes            : [Maybe TypeExtra]
+         upTypes              : [Maybe TypeExtra]
+         whenTypes            : [[Maybe TypeExtra]]
+   alternatives:
+      alternative Cons:
+         child hd             : CaseScalarExprListScalarExprPair 
+         child tl             : CaseScalarExprListScalarExprPairList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type CaseScalarExprListScalarExprPairList = [CaseScalarExprListScalarExprPair]
+-- cata
+_sem_CaseScalarExprListScalarExprPairList :: CaseScalarExprListScalarExprPairList ->
+                                            T_CaseScalarExprListScalarExprPairList
+_sem_CaseScalarExprListScalarExprPairList list =
+    (Prelude.foldr _sem_CaseScalarExprListScalarExprPairList_Cons _sem_CaseScalarExprListScalarExprPairList_Nil (Prelude.map _sem_CaseScalarExprListScalarExprPair list))
+-- semantic domain
+type T_CaseScalarExprListScalarExprPairList = Catalog ->
+                                              Environment ->
+                                              TypeCheckFlags ->
+                                              (Maybe TypeExtra) ->
+                                              (Maybe TypeExtra) ->
+                                              (Maybe TypeExtra) ->
+                                              ( CaseScalarExprListScalarExprPairList,CaseScalarExprListScalarExprPairList,([Maybe TypeExtra]),([Maybe TypeExtra]),([[Maybe TypeExtra]]))
+data Inh_CaseScalarExprListScalarExprPairList = Inh_CaseScalarExprListScalarExprPairList {_cat_Inh_CaseScalarExprListScalarExprPairList :: Catalog,_downEnv_Inh_CaseScalarExprListScalarExprPairList :: Environment,_flags_Inh_CaseScalarExprListScalarExprPairList :: TypeCheckFlags,_imCast_Inh_CaseScalarExprListScalarExprPairList :: (Maybe TypeExtra),_thenExpectedType_Inh_CaseScalarExprListScalarExprPairList :: (Maybe TypeExtra),_whenExpectedType_Inh_CaseScalarExprListScalarExprPairList :: (Maybe TypeExtra)}
+data Syn_CaseScalarExprListScalarExprPairList = Syn_CaseScalarExprListScalarExprPairList {_annotatedTree_Syn_CaseScalarExprListScalarExprPairList :: CaseScalarExprListScalarExprPairList,_originalTree_Syn_CaseScalarExprListScalarExprPairList :: CaseScalarExprListScalarExprPairList,_thenTypes_Syn_CaseScalarExprListScalarExprPairList :: ([Maybe TypeExtra]),_upTypes_Syn_CaseScalarExprListScalarExprPairList :: ([Maybe TypeExtra]),_whenTypes_Syn_CaseScalarExprListScalarExprPairList :: ([[Maybe TypeExtra]])}
+_wrap_CaseScalarExprListScalarExprPairList :: T_CaseScalarExprListScalarExprPairList ->
+                                             Inh_CaseScalarExprListScalarExprPairList ->
+                                             Syn_CaseScalarExprListScalarExprPairList
+_wrap_CaseScalarExprListScalarExprPairList sem (Inh_CaseScalarExprListScalarExprPairList _lhsIcat _lhsIdownEnv _lhsIflags _lhsIimCast _lhsIthenExpectedType _lhsIwhenExpectedType) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOthenTypes,_lhsOupTypes,_lhsOwhenTypes) = sem _lhsIcat _lhsIdownEnv _lhsIflags _lhsIimCast _lhsIthenExpectedType _lhsIwhenExpectedType
+     in  (Syn_CaseScalarExprListScalarExprPairList _lhsOannotatedTree _lhsOoriginalTree _lhsOthenTypes _lhsOupTypes _lhsOwhenTypes))
+_sem_CaseScalarExprListScalarExprPairList_Cons :: T_CaseScalarExprListScalarExprPair ->
+                                                 T_CaseScalarExprListScalarExprPairList ->
+                                                 T_CaseScalarExprListScalarExprPairList
+_sem_CaseScalarExprListScalarExprPairList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIdownEnv
+       _lhsIflags
+       _lhsIimCast
+       _lhsIthenExpectedType
+       _lhsIwhenExpectedType ->
+         (let _lhsOwhenTypes :: ([[Maybe TypeExtra]])
+              _lhsOthenTypes :: ([Maybe TypeExtra])
+              _lhsOannotatedTree :: CaseScalarExprListScalarExprPairList
+              _lhsOoriginalTree :: CaseScalarExprListScalarExprPairList
+              _lhsOupTypes :: ([Maybe TypeExtra])
+              _hdOcat :: Catalog
+              _hdOdownEnv :: Environment
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _hdOthenExpectedType :: (Maybe TypeExtra)
+              _hdOwhenExpectedType :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOdownEnv :: Environment
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _tlOthenExpectedType :: (Maybe TypeExtra)
+              _tlOwhenExpectedType :: (Maybe TypeExtra)
+              _hdIannotatedTree :: CaseScalarExprListScalarExprPair
+              _hdIoriginalTree :: CaseScalarExprListScalarExprPair
+              _hdIthenType :: (Maybe TypeExtra)
+              _hdIupTypes :: ([Maybe TypeExtra])
+              _hdIwhenTypes :: ([Maybe TypeExtra])
+              _tlIannotatedTree :: CaseScalarExprListScalarExprPairList
+              _tlIoriginalTree :: CaseScalarExprListScalarExprPairList
+              _tlIthenTypes :: ([Maybe TypeExtra])
+              _tlIupTypes :: ([Maybe TypeExtra])
+              _tlIwhenTypes :: ([[Maybe TypeExtra]])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 538, column 10)
+              _lhsOwhenTypes =
+                  ({-# LINE 538 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _hdIwhenTypes : _tlIwhenTypes
+                   {-# LINE 4277 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 539, column 10)
+              _lhsOthenTypes =
+                  ({-# LINE 539 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _hdIthenType : _tlIthenTypes
+                   {-# LINE 4283 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 4289 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 4295 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 4301 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 4307 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (up)
+              _lhsOupTypes =
+                  ({-# LINE 554 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tlIupTypes
+                   {-# LINE 4313 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 4319 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOdownEnv =
+                  ({-# LINE 553 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 4325 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 4331 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 4337 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOthenExpectedType =
+                  ({-# LINE 601 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIthenExpectedType
+                   {-# LINE 4343 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOwhenExpectedType =
+                  ({-# LINE 602 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIwhenExpectedType
+                   {-# LINE 4349 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 4355 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOdownEnv =
+                  ({-# LINE 553 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 4361 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 4367 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 4373 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOthenExpectedType =
+                  ({-# LINE 601 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIthenExpectedType
+                   {-# LINE 4379 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOwhenExpectedType =
+                  ({-# LINE 602 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIwhenExpectedType
+                   {-# LINE 4385 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree,_hdIthenType,_hdIupTypes,_hdIwhenTypes) =
+                  hd_ _hdOcat _hdOdownEnv _hdOflags _hdOimCast _hdOthenExpectedType _hdOwhenExpectedType
+              ( _tlIannotatedTree,_tlIoriginalTree,_tlIthenTypes,_tlIupTypes,_tlIwhenTypes) =
+                  tl_ _tlOcat _tlOdownEnv _tlOflags _tlOimCast _tlOthenExpectedType _tlOwhenExpectedType
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOthenTypes,_lhsOupTypes,_lhsOwhenTypes)))
+_sem_CaseScalarExprListScalarExprPairList_Nil :: T_CaseScalarExprListScalarExprPairList
+_sem_CaseScalarExprListScalarExprPairList_Nil =
+    (\ _lhsIcat
+       _lhsIdownEnv
+       _lhsIflags
+       _lhsIimCast
+       _lhsIthenExpectedType
+       _lhsIwhenExpectedType ->
+         (let _lhsOwhenTypes :: ([[Maybe TypeExtra]])
+              _lhsOthenTypes :: ([Maybe TypeExtra])
+              _lhsOupTypes :: ([Maybe TypeExtra])
+              _lhsOannotatedTree :: CaseScalarExprListScalarExprPairList
+              _lhsOoriginalTree :: CaseScalarExprListScalarExprPairList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 540, column 9)
+              _lhsOwhenTypes =
+                  ({-# LINE 540 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   []
+                   {-# LINE 4409 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 541, column 9)
+              _lhsOthenTypes =
+                  ({-# LINE 541 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   []
+                   {-# LINE 4415 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 542, column 9)
+              _lhsOupTypes =
+                  ({-# LINE 542 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   []
+                   {-# LINE 4421 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 4427 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 4433 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 4439 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 4445 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOthenTypes,_lhsOupTypes,_lhsOwhenTypes)))
+-- Constraint --------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : Constraint 
+         originalTree         : Constraint 
+   alternatives:
+      alternative UniqueConstraint:
+         child ann            : Annotation 
+         child name           : {String}
+         child x              : {[NameComponent]}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative PrimaryKeyConstraint:
+         child ann            : Annotation 
+         child name           : {String}
+         child x              : {[NameComponent]}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CheckConstraint:
+         child ann            : Annotation 
+         child name           : {String}
+         child expr           : ScalarExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative ReferenceConstraint:
+         child ann            : Annotation 
+         child name           : {String}
+         child atts           : {[NameComponent]}
+         child table          : Name 
+         child tableAtts      : {[NameComponent]}
+         child onUpdate       : {Cascade}
+         child onDelete       : {Cascade}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data Constraint = UniqueConstraint (Annotation) (String) (([NameComponent]))
+                | PrimaryKeyConstraint (Annotation) (String) (([NameComponent]))
+                | CheckConstraint (Annotation) (String) (ScalarExpr)
+                | ReferenceConstraint (Annotation) (String) (([NameComponent])) (Name) (([NameComponent])) (Cascade) (Cascade)
+                deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_Constraint :: Constraint ->
+                  T_Constraint
+_sem_Constraint (UniqueConstraint _ann _name _x) =
+    (_sem_Constraint_UniqueConstraint (_sem_Annotation _ann) _name _x)
+_sem_Constraint (PrimaryKeyConstraint _ann _name _x) =
+    (_sem_Constraint_PrimaryKeyConstraint (_sem_Annotation _ann) _name _x)
+_sem_Constraint (CheckConstraint _ann _name _expr) =
+    (_sem_Constraint_CheckConstraint (_sem_Annotation _ann) _name (_sem_ScalarExpr _expr))
+_sem_Constraint (ReferenceConstraint _ann _name _atts _table _tableAtts _onUpdate _onDelete) =
+    (_sem_Constraint_ReferenceConstraint (_sem_Annotation _ann) _name _atts (_sem_Name _table) _tableAtts _onUpdate _onDelete)
+-- semantic domain
+type T_Constraint = Catalog ->
+                    TypeCheckFlags ->
+                    (Maybe TypeExtra) ->
+                    ( Constraint,Constraint)
+data Inh_Constraint = Inh_Constraint {_cat_Inh_Constraint :: Catalog,_flags_Inh_Constraint :: TypeCheckFlags,_imCast_Inh_Constraint :: (Maybe TypeExtra)}
+data Syn_Constraint = Syn_Constraint {_annotatedTree_Syn_Constraint :: Constraint,_originalTree_Syn_Constraint :: Constraint}
+_wrap_Constraint :: T_Constraint ->
+                   Inh_Constraint ->
+                   Syn_Constraint
+_wrap_Constraint sem (Inh_Constraint _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_Constraint _lhsOannotatedTree _lhsOoriginalTree))
+_sem_Constraint_UniqueConstraint :: T_Annotation ->
+                                   String ->
+                                   ([NameComponent]) ->
+                                   T_Constraint
+_sem_Constraint_UniqueConstraint ann_ name_ x_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Constraint
+              _lhsOoriginalTree :: Constraint
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 65, column 35)
+              _annOtpe =
+                  ({-# LINE 65 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 4541 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   UniqueConstraint _annIannotatedTree name_ x_
+                   {-# LINE 4547 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   UniqueConstraint _annIoriginalTree name_ x_
+                   {-# LINE 4553 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 4559 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 4565 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 4571 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 4577 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 4583 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Constraint_PrimaryKeyConstraint :: T_Annotation ->
+                                       String ->
+                                       ([NameComponent]) ->
+                                       T_Constraint
+_sem_Constraint_PrimaryKeyConstraint ann_ name_ x_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Constraint
+              _lhsOoriginalTree :: Constraint
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 62, column 39)
+              _annOtpe =
+                  ({-# LINE 62 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 4608 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   PrimaryKeyConstraint _annIannotatedTree name_ x_
+                   {-# LINE 4614 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   PrimaryKeyConstraint _annIoriginalTree name_ x_
+                   {-# LINE 4620 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 4626 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 4632 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 4638 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 4644 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 4650 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Constraint_CheckConstraint :: T_Annotation ->
+                                  String ->
+                                  T_ScalarExpr ->
+                                  T_Constraint
+_sem_Constraint_CheckConstraint ann_ name_ expr_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _exprOdownEnv :: Environment
+              _exprOexpectedCast :: Bool
+              _exprOexpectedType :: (Maybe TypeExtra)
+              _exprOodbcFunction :: Bool
+              _exprOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Constraint
+              _lhsOoriginalTree :: Constraint
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _exprOcat :: Catalog
+              _exprOflags :: TypeCheckFlags
+              _exprOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exprIannotatedTree :: ScalarExpr
+              _exprIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exprIoriginalTree :: ScalarExpr
+              _exprIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 58, column 34)
+              _annOtpe =
+                  ({-# LINE 58 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 4687 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 59, column 34)
+              _exprOdownEnv =
+                  ({-# LINE 59 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 4693 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 60, column 34)
+              _exprOexpectedCast =
+                  ({-# LINE 60 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 4699 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 61, column 34)
+              _exprOexpectedType =
+                  ({-# LINE 61 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 4705 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 137, column 23)
+              _exprOodbcFunction =
+                  ({-# LINE 137 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 4711 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 810, column 34)
+              _exprOassignmentCastContext =
+                  ({-# LINE 810 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 4717 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CheckConstraint _annIannotatedTree name_ _exprIannotatedTree
+                   {-# LINE 4723 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CheckConstraint _annIoriginalTree name_ _exprIoriginalTree
+                   {-# LINE 4729 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 4735 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 4741 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 4747 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 4753 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 4759 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 4765 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 4771 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 4777 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exprIannotatedTree,_exprIcolExprs,_exprIoriginalTree,_exprIupType) =
+                  expr_ _exprOassignmentCastContext _exprOcat _exprOdownEnv _exprOexpectedCast _exprOexpectedType _exprOflags _exprOimCast _exprOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Constraint_ReferenceConstraint :: T_Annotation ->
+                                      String ->
+                                      ([NameComponent]) ->
+                                      T_Name ->
+                                      ([NameComponent]) ->
+                                      Cascade ->
+                                      Cascade ->
+                                      T_Constraint
+_sem_Constraint_ReferenceConstraint ann_ name_ atts_ table_ tableAtts_ onUpdate_ onDelete_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _tableOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Constraint
+              _lhsOoriginalTree :: Constraint
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _tableOcat :: Catalog
+              _tableOflags :: TypeCheckFlags
+              _tableOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _tableIannotatedTree :: Name
+              _tableIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 63, column 38)
+              _annOtpe =
+                  ({-# LINE 63 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 4814 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 64, column 38)
+              _tableOtpe =
+                  ({-# LINE 64 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 4820 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ReferenceConstraint _annIannotatedTree name_ atts_ _tableIannotatedTree tableAtts_ onUpdate_ onDelete_
+                   {-# LINE 4826 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ReferenceConstraint _annIoriginalTree name_ atts_ _tableIoriginalTree tableAtts_ onUpdate_ onDelete_
+                   {-# LINE 4832 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 4838 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 4844 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 4850 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 4856 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 4862 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 4868 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 4874 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 4880 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _tableIannotatedTree,_tableIoriginalTree) =
+                  table_ _tableOcat _tableOflags _tableOimCast _tableOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- ConstraintList ----------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : ConstraintList 
+         originalTree         : ConstraintList 
+   alternatives:
+      alternative Cons:
+         child hd             : Constraint 
+         child tl             : ConstraintList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type ConstraintList = [Constraint]
+-- cata
+_sem_ConstraintList :: ConstraintList ->
+                      T_ConstraintList
+_sem_ConstraintList list =
+    (Prelude.foldr _sem_ConstraintList_Cons _sem_ConstraintList_Nil (Prelude.map _sem_Constraint list))
+-- semantic domain
+type T_ConstraintList = Catalog ->
+                        TypeCheckFlags ->
+                        (Maybe TypeExtra) ->
+                        ( ConstraintList,ConstraintList)
+data Inh_ConstraintList = Inh_ConstraintList {_cat_Inh_ConstraintList :: Catalog,_flags_Inh_ConstraintList :: TypeCheckFlags,_imCast_Inh_ConstraintList :: (Maybe TypeExtra)}
+data Syn_ConstraintList = Syn_ConstraintList {_annotatedTree_Syn_ConstraintList :: ConstraintList,_originalTree_Syn_ConstraintList :: ConstraintList}
+_wrap_ConstraintList :: T_ConstraintList ->
+                       Inh_ConstraintList ->
+                       Syn_ConstraintList
+_wrap_ConstraintList sem (Inh_ConstraintList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_ConstraintList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_ConstraintList_Cons :: T_Constraint ->
+                           T_ConstraintList ->
+                           T_ConstraintList
+_sem_ConstraintList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: ConstraintList
+              _lhsOoriginalTree :: ConstraintList
+              _hdOcat :: Catalog
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: Constraint
+              _hdIoriginalTree :: Constraint
+              _tlIannotatedTree :: ConstraintList
+              _tlIoriginalTree :: ConstraintList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 4951 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 4957 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 4963 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 4969 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 4975 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 4981 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 4987 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 4993 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 4999 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 5005 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree) =
+                  hd_ _hdOcat _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_ConstraintList_Nil :: T_ConstraintList
+_sem_ConstraintList_Nil =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: ConstraintList
+              _lhsOoriginalTree :: ConstraintList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 5023 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 5029 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 5035 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 5041 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- FnBody ------------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : FnBody 
+         originalTree         : FnBody 
+   alternatives:
+      alternative SqlFnBody:
+         child ann            : Annotation 
+         child sts            : StatementList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative PlpgsqlFnBody:
+         child ann            : Annotation 
+         child blk            : Statement 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data FnBody = SqlFnBody (Annotation) (StatementList)
+            | PlpgsqlFnBody (Annotation) (Statement)
+            deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_FnBody :: FnBody ->
+              T_FnBody
+_sem_FnBody (SqlFnBody _ann _sts) =
+    (_sem_FnBody_SqlFnBody (_sem_Annotation _ann) (_sem_StatementList _sts))
+_sem_FnBody (PlpgsqlFnBody _ann _blk) =
+    (_sem_FnBody_PlpgsqlFnBody (_sem_Annotation _ann) (_sem_Statement _blk))
+-- semantic domain
+type T_FnBody = Catalog ->
+                TypeCheckFlags ->
+                (Maybe TypeExtra) ->
+                ( FnBody,FnBody)
+data Inh_FnBody = Inh_FnBody {_cat_Inh_FnBody :: Catalog,_flags_Inh_FnBody :: TypeCheckFlags,_imCast_Inh_FnBody :: (Maybe TypeExtra)}
+data Syn_FnBody = Syn_FnBody {_annotatedTree_Syn_FnBody :: FnBody,_originalTree_Syn_FnBody :: FnBody}
+_wrap_FnBody :: T_FnBody ->
+               Inh_FnBody ->
+               Syn_FnBody
+_wrap_FnBody sem (Inh_FnBody _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_FnBody _lhsOannotatedTree _lhsOoriginalTree))
+_sem_FnBody_SqlFnBody :: T_Annotation ->
+                        T_StatementList ->
+                        T_FnBody
+_sem_FnBody_SqlFnBody ann_ sts_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: FnBody
+              _lhsOoriginalTree :: FnBody
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _stsOcat :: Catalog
+              _stsOflags :: TypeCheckFlags
+              _stsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _stsIannotatedTree :: StatementList
+              _stsIoriginalTree :: StatementList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 67, column 24)
+              _annOtpe =
+                  ({-# LINE 67 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 5115 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SqlFnBody _annIannotatedTree _stsIannotatedTree
+                   {-# LINE 5121 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SqlFnBody _annIoriginalTree _stsIoriginalTree
+                   {-# LINE 5127 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 5133 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 5139 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 5145 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 5151 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 5157 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 5163 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 5169 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 5175 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _stsIannotatedTree,_stsIoriginalTree) =
+                  sts_ _stsOcat _stsOflags _stsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_FnBody_PlpgsqlFnBody :: T_Annotation ->
+                            T_Statement ->
+                            T_FnBody
+_sem_FnBody_PlpgsqlFnBody ann_ blk_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: FnBody
+              _lhsOoriginalTree :: FnBody
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _blkOcat :: Catalog
+              _blkOflags :: TypeCheckFlags
+              _blkOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _blkIannotatedTree :: Statement
+              _blkIoriginalTree :: Statement
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 66, column 28)
+              _annOtpe =
+                  ({-# LINE 66 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 5206 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   PlpgsqlFnBody _annIannotatedTree _blkIannotatedTree
+                   {-# LINE 5212 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   PlpgsqlFnBody _annIoriginalTree _blkIoriginalTree
+                   {-# LINE 5218 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 5224 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 5230 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 5236 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 5242 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 5248 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _blkOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 5254 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _blkOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 5260 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _blkOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 5266 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _blkIannotatedTree,_blkIoriginalTree) =
+                  blk_ _blkOcat _blkOflags _blkOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- InList ------------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         downEnv              : Environment
+         expectedCast         : Bool
+         expectedType         : Maybe TypeExtra
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : InList 
+         listType             : Either [TypeError] TypeExtra
+         originalTree         : InList 
+   alternatives:
+      alternative InList:
+         child ann            : Annotation 
+         child exprs          : ScalarExprList 
+         visit 0:
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative InQueryExpr:
+         child ann            : Annotation 
+         child sel            : QueryExpr 
+         visit 0:
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+-}
+data InList = InList (Annotation) (ScalarExprList)
+            | InQueryExpr (Annotation) (QueryExpr)
+            deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_InList :: InList ->
+              T_InList
+_sem_InList (InList _ann _exprs) =
+    (_sem_InList_InList (_sem_Annotation _ann) (_sem_ScalarExprList _exprs))
+_sem_InList (InQueryExpr _ann _sel) =
+    (_sem_InList_InQueryExpr (_sem_Annotation _ann) (_sem_QueryExpr _sel))
+-- semantic domain
+type T_InList = Catalog ->
+                Environment ->
+                Bool ->
+                (Maybe TypeExtra) ->
+                TypeCheckFlags ->
+                (Maybe TypeExtra) ->
+                ( InList,(Either [TypeError] TypeExtra),InList)
+data Inh_InList = Inh_InList {_cat_Inh_InList :: Catalog,_downEnv_Inh_InList :: Environment,_expectedCast_Inh_InList :: Bool,_expectedType_Inh_InList :: (Maybe TypeExtra),_flags_Inh_InList :: TypeCheckFlags,_imCast_Inh_InList :: (Maybe TypeExtra)}
+data Syn_InList = Syn_InList {_annotatedTree_Syn_InList :: InList,_listType_Syn_InList :: (Either [TypeError] TypeExtra),_originalTree_Syn_InList :: InList}
+_wrap_InList :: T_InList ->
+               Inh_InList ->
+               Syn_InList
+_wrap_InList sem (Inh_InList _lhsIcat _lhsIdownEnv _lhsIexpectedCast _lhsIexpectedType _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOlistType,_lhsOoriginalTree) = sem _lhsIcat _lhsIdownEnv _lhsIexpectedCast _lhsIexpectedType _lhsIflags _lhsIimCast
+     in  (Syn_InList _lhsOannotatedTree _lhsOlistType _lhsOoriginalTree))
+_sem_InList_InList :: T_Annotation ->
+                     T_ScalarExprList ->
+                     T_InList
+_sem_InList_InList ann_ exprs_ =
+    (\ _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOlistType :: (Either [TypeError] TypeExtra)
+              _exprsOexpectedTypes :: ([TypeExtra])
+              _exprsOexpectedCast :: Bool
+              _annOimCast :: (Maybe TypeExtra)
+              _exprsOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: InList
+              _lhsOoriginalTree :: InList
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _exprsOcat :: Catalog
+              _exprsOdownEnv :: Environment
+              _exprsOflags :: TypeCheckFlags
+              _exprsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exprsIannotatedTree :: ScalarExprList
+              _exprsIoriginalTree :: ScalarExprList
+              _exprsIupTypes :: ([Maybe TypeExtra])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 219, column 9)
+              _tpe =
+                  ({-# LINE 219 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   Left []
+                   {-# LINE 5362 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 681, column 9)
+              _lhsOlistType =
+                  ({-# LINE 681 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   mapM (maybe (Left []) Right) _exprsIupTypes
+                   >>= resolveResultSetTypeExtra _lhsIcat
+                   {-# LINE 5369 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 683, column 9)
+              _exprsOexpectedTypes =
+                  ({-# LINE 683 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe [] repeat _lhsIexpectedType
+                   {-# LINE 5375 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 685, column 9)
+              _exprsOexpectedCast =
+                  ({-# LINE 685 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 5381 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 781, column 12)
+              _annOimCast =
+                  ({-# LINE 781 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Nothing
+                   {-# LINE 5387 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 811, column 21)
+              _exprsOassignmentCastContext =
+                  ({-# LINE 811 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 5393 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   InList _annIannotatedTree _exprsIannotatedTree
+                   {-# LINE 5399 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   InList _annIoriginalTree _exprsIoriginalTree
+                   {-# LINE 5405 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 5411 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 5417 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 5423 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 5429 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (from local)
+              _annOtpe =
+                  ({-# LINE 126 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _tpe
+                   {-# LINE 5435 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 5441 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprsOdownEnv =
+                  ({-# LINE 189 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 5447 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 5453 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 5459 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exprsIannotatedTree,_exprsIoriginalTree,_exprsIupTypes) =
+                  exprs_ _exprsOassignmentCastContext _exprsOcat _exprsOdownEnv _exprsOexpectedCast _exprsOexpectedTypes _exprsOflags _exprsOimCast
+          in  ( _lhsOannotatedTree,_lhsOlistType,_lhsOoriginalTree)))
+_sem_InList_InQueryExpr :: T_Annotation ->
+                          T_QueryExpr ->
+                          T_InList
+_sem_InList_InQueryExpr ann_ sel_ =
+    (\ _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast ->
+         (let _selOouterDownEnv :: (Maybe Environment)
+              _lhsOlistType :: (Either [TypeError] TypeExtra)
+              _selOexpectedType :: (Maybe [TypeExtra])
+              _annOimCast :: (Maybe TypeExtra)
+              _selOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: InList
+              _lhsOoriginalTree :: InList
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _selOcat :: Catalog
+              _selOflags :: TypeCheckFlags
+              _selOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _selIannotatedTree :: QueryExpr
+              _selIoriginalTree :: QueryExpr
+              _selIupType :: (Maybe [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 97, column 17)
+              _selOouterDownEnv =
+                  ({-# LINE 97 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   Nothing
+                   {-# LINE 5498 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 219, column 9)
+              _tpe =
+                  ({-# LINE 219 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   Left []
+                   {-# LINE 5504 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 688, column 9)
+              _lhsOlistType =
+                  ({-# LINE 688 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   do
+                   st <- maybe (Left []) Right (map snd <$> _selIupType)
+                   case length st of
+                             0 -> Left [InternalError
+                                        "got subquery with no columns? in inselect"]
+                             1 -> Right $ head st
+                             _ -> Right $ mkTypeExtra $ AnonymousCompositeType
+                                     $ map teType st
+                   {-# LINE 5517 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 698, column 9)
+              _selOexpectedType =
+                  ({-# LINE 698 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   liftM (map snd) _selIupType
+                   {-# LINE 5523 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 782, column 17)
+              _annOimCast =
+                  ({-# LINE 782 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Nothing
+                   {-# LINE 5529 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 812, column 26)
+              _selOassignmentCastContext =
+                  ({-# LINE 812 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 5535 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   InQueryExpr _annIannotatedTree _selIannotatedTree
+                   {-# LINE 5541 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   InQueryExpr _annIoriginalTree _selIoriginalTree
+                   {-# LINE 5547 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 5553 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 5559 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 5565 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 5571 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (from local)
+              _annOtpe =
+                  ({-# LINE 126 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _tpe
+                   {-# LINE 5577 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 5583 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 5589 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 5595 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _selIannotatedTree,_selIoriginalTree,_selIupType) =
+                  sel_ _selOassignmentCastContext _selOcat _selOexpectedType _selOflags _selOimCast _selOouterDownEnv
+          in  ( _lhsOannotatedTree,_lhsOlistType,_lhsOoriginalTree)))
+-- JoinExpr ----------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         downEnv              : Environment
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : JoinExpr 
+         originalTree         : JoinExpr 
+   alternatives:
+      alternative JoinOn:
+         child ann            : Annotation 
+         child expr           : ScalarExpr 
+         visit 0:
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative JoinUsing:
+         child ann            : Annotation 
+         child x              : {[NameComponent]}
+         visit 0:
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+-}
+data JoinExpr = JoinOn (Annotation) (ScalarExpr)
+              | JoinUsing (Annotation) (([NameComponent]))
+              deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_JoinExpr :: JoinExpr ->
+                T_JoinExpr
+_sem_JoinExpr (JoinOn _ann _expr) =
+    (_sem_JoinExpr_JoinOn (_sem_Annotation _ann) (_sem_ScalarExpr _expr))
+_sem_JoinExpr (JoinUsing _ann _x) =
+    (_sem_JoinExpr_JoinUsing (_sem_Annotation _ann) _x)
+-- semantic domain
+type T_JoinExpr = Catalog ->
+                  Environment ->
+                  TypeCheckFlags ->
+                  (Maybe TypeExtra) ->
+                  ( JoinExpr,JoinExpr)
+data Inh_JoinExpr = Inh_JoinExpr {_cat_Inh_JoinExpr :: Catalog,_downEnv_Inh_JoinExpr :: Environment,_flags_Inh_JoinExpr :: TypeCheckFlags,_imCast_Inh_JoinExpr :: (Maybe TypeExtra)}
+data Syn_JoinExpr = Syn_JoinExpr {_annotatedTree_Syn_JoinExpr :: JoinExpr,_originalTree_Syn_JoinExpr :: JoinExpr}
+_wrap_JoinExpr :: T_JoinExpr ->
+                 Inh_JoinExpr ->
+                 Syn_JoinExpr
+_wrap_JoinExpr sem (Inh_JoinExpr _lhsIcat _lhsIdownEnv _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIdownEnv _lhsIflags _lhsIimCast
+     in  (Syn_JoinExpr _lhsOannotatedTree _lhsOoriginalTree))
+_sem_JoinExpr_JoinOn :: T_Annotation ->
+                       T_ScalarExpr ->
+                       T_JoinExpr
+_sem_JoinExpr_JoinOn ann_ expr_ =
+    (\ _lhsIcat
+       _lhsIdownEnv
+       _lhsIflags
+       _lhsIimCast ->
+         (let _exprOodbcFunction :: Bool
+              _exprOexpectedType :: (Maybe TypeExtra)
+              _exprOexpectedCast :: Bool
+              _exprOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: JoinExpr
+              _lhsOoriginalTree :: JoinExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _exprOcat :: Catalog
+              _exprOdownEnv :: Environment
+              _exprOflags :: TypeCheckFlags
+              _exprOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exprIannotatedTree :: ScalarExpr
+              _exprIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exprIoriginalTree :: ScalarExpr
+              _exprIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 223, column 9)
+              _tpe =
+                  ({-# LINE 223 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   Left []
+                   {-# LINE 5685 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 140, column 14)
+              _exprOodbcFunction =
+                  ({-# LINE 140 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 5691 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 745, column 7)
+              _exprOexpectedType =
+                  ({-# LINE 745 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   do
+                   bt <- ansiTypeNameToDialect (tcfDialect _lhsIflags) "boolean"
+                   Just $ TypeExtra (ScalarType bt) Nothing Nothing
+                        $ maybe False teNullable _exprIupType
+                   {-# LINE 5700 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 749, column 7)
+              _exprOexpectedCast =
+                  ({-# LINE 749 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 5706 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 813, column 23)
+              _exprOassignmentCastContext =
+                  ({-# LINE 813 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 5712 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   JoinOn _annIannotatedTree _exprIannotatedTree
+                   {-# LINE 5718 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   JoinOn _annIoriginalTree _exprIoriginalTree
+                   {-# LINE 5724 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 5730 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 5736 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 5742 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 5748 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 5754 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (from local)
+              _annOtpe =
+                  ({-# LINE 126 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _tpe
+                   {-# LINE 5760 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 5766 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 5772 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 5778 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 5784 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exprIannotatedTree,_exprIcolExprs,_exprIoriginalTree,_exprIupType) =
+                  expr_ _exprOassignmentCastContext _exprOcat _exprOdownEnv _exprOexpectedCast _exprOexpectedType _exprOflags _exprOimCast _exprOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_JoinExpr_JoinUsing :: T_Annotation ->
+                          ([NameComponent]) ->
+                          T_JoinExpr
+_sem_JoinExpr_JoinUsing ann_ x_ =
+    (\ _lhsIcat
+       _lhsIdownEnv
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: JoinExpr
+              _lhsOoriginalTree :: JoinExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 223, column 9)
+              _tpe =
+                  ({-# LINE 223 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   Left []
+                   {-# LINE 5811 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   JoinUsing _annIannotatedTree x_
+                   {-# LINE 5817 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   JoinUsing _annIoriginalTree x_
+                   {-# LINE 5823 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 5829 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 5835 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 5841 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 5847 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 5853 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (from local)
+              _annOtpe =
+                  ({-# LINE 126 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _tpe
+                   {-# LINE 5859 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- MaybeBoolExpr -----------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         downEnv              : Environment
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : MaybeBoolExpr 
+         originalTree         : MaybeBoolExpr 
+   alternatives:
+      alternative Just:
+         child just           : ScalarExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nothing:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type MaybeBoolExpr = Maybe (ScalarExpr)
+-- cata
+_sem_MaybeBoolExpr :: MaybeBoolExpr ->
+                     T_MaybeBoolExpr
+_sem_MaybeBoolExpr (Prelude.Just x) =
+    (_sem_MaybeBoolExpr_Just (_sem_ScalarExpr x))
+_sem_MaybeBoolExpr Prelude.Nothing =
+    _sem_MaybeBoolExpr_Nothing
+-- semantic domain
+type T_MaybeBoolExpr = Catalog ->
+                       Environment ->
+                       TypeCheckFlags ->
+                       (Maybe TypeExtra) ->
+                       ( MaybeBoolExpr,MaybeBoolExpr)
+data Inh_MaybeBoolExpr = Inh_MaybeBoolExpr {_cat_Inh_MaybeBoolExpr :: Catalog,_downEnv_Inh_MaybeBoolExpr :: Environment,_flags_Inh_MaybeBoolExpr :: TypeCheckFlags,_imCast_Inh_MaybeBoolExpr :: (Maybe TypeExtra)}
+data Syn_MaybeBoolExpr = Syn_MaybeBoolExpr {_annotatedTree_Syn_MaybeBoolExpr :: MaybeBoolExpr,_originalTree_Syn_MaybeBoolExpr :: MaybeBoolExpr}
+_wrap_MaybeBoolExpr :: T_MaybeBoolExpr ->
+                      Inh_MaybeBoolExpr ->
+                      Syn_MaybeBoolExpr
+_wrap_MaybeBoolExpr sem (Inh_MaybeBoolExpr _lhsIcat _lhsIdownEnv _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIdownEnv _lhsIflags _lhsIimCast
+     in  (Syn_MaybeBoolExpr _lhsOannotatedTree _lhsOoriginalTree))
+_sem_MaybeBoolExpr_Just :: T_ScalarExpr ->
+                          T_MaybeBoolExpr
+_sem_MaybeBoolExpr_Just just_ =
+    (\ _lhsIcat
+       _lhsIdownEnv
+       _lhsIflags
+       _lhsIimCast ->
+         (let _justOodbcFunction :: Bool
+              _justOexpectedType :: (Maybe TypeExtra)
+              _justOexpectedCast :: Bool
+              _justOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: MaybeBoolExpr
+              _lhsOoriginalTree :: MaybeBoolExpr
+              _justOcat :: Catalog
+              _justOdownEnv :: Environment
+              _justOflags :: TypeCheckFlags
+              _justOimCast :: (Maybe TypeExtra)
+              _justIannotatedTree :: ScalarExpr
+              _justIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _justIoriginalTree :: ScalarExpr
+              _justIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 143, column 12)
+              _justOodbcFunction =
+                  ({-# LINE 143 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 5933 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 761, column 7)
+              _justOexpectedType =
+                  ({-# LINE 761 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Nothing
+                   {-# LINE 5939 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 762, column 7)
+              _justOexpectedCast =
+                  ({-# LINE 762 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 5945 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 814, column 26)
+              _justOassignmentCastContext =
+                  ({-# LINE 814 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 5951 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Just _justIannotatedTree
+                   {-# LINE 5957 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Just _justIoriginalTree
+                   {-# LINE 5963 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 5969 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 5975 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 5981 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 5987 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 5993 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 5999 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _justIannotatedTree,_justIcolExprs,_justIoriginalTree,_justIupType) =
+                  just_ _justOassignmentCastContext _justOcat _justOdownEnv _justOexpectedCast _justOexpectedType _justOflags _justOimCast _justOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_MaybeBoolExpr_Nothing :: T_MaybeBoolExpr
+_sem_MaybeBoolExpr_Nothing =
+    (\ _lhsIcat
+       _lhsIdownEnv
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: MaybeBoolExpr
+              _lhsOoriginalTree :: MaybeBoolExpr
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Nothing
+                   {-# LINE 6016 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Nothing
+                   {-# LINE 6022 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 6028 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 6034 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- MaybeNameComponentList --------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : MaybeNameComponentList 
+         originalTree         : MaybeNameComponentList 
+   alternatives:
+      alternative Just:
+         child just           : NameComponentList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nothing:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type MaybeNameComponentList = Maybe (NameComponentList)
+-- cata
+_sem_MaybeNameComponentList :: MaybeNameComponentList ->
+                              T_MaybeNameComponentList
+_sem_MaybeNameComponentList (Prelude.Just x) =
+    (_sem_MaybeNameComponentList_Just (_sem_NameComponentList x))
+_sem_MaybeNameComponentList Prelude.Nothing =
+    _sem_MaybeNameComponentList_Nothing
+-- semantic domain
+type T_MaybeNameComponentList = Catalog ->
+                                TypeCheckFlags ->
+                                (Maybe TypeExtra) ->
+                                ( MaybeNameComponentList,MaybeNameComponentList)
+data Inh_MaybeNameComponentList = Inh_MaybeNameComponentList {_cat_Inh_MaybeNameComponentList :: Catalog,_flags_Inh_MaybeNameComponentList :: TypeCheckFlags,_imCast_Inh_MaybeNameComponentList :: (Maybe TypeExtra)}
+data Syn_MaybeNameComponentList = Syn_MaybeNameComponentList {_annotatedTree_Syn_MaybeNameComponentList :: MaybeNameComponentList,_originalTree_Syn_MaybeNameComponentList :: MaybeNameComponentList}
+_wrap_MaybeNameComponentList :: T_MaybeNameComponentList ->
+                               Inh_MaybeNameComponentList ->
+                               Syn_MaybeNameComponentList
+_wrap_MaybeNameComponentList sem (Inh_MaybeNameComponentList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_MaybeNameComponentList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_MaybeNameComponentList_Just :: T_NameComponentList ->
+                                   T_MaybeNameComponentList
+_sem_MaybeNameComponentList_Just just_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: MaybeNameComponentList
+              _lhsOoriginalTree :: MaybeNameComponentList
+              _justOcat :: Catalog
+              _justOflags :: TypeCheckFlags
+              _justOimCast :: (Maybe TypeExtra)
+              _justIannotatedTree :: NameComponentList
+              _justIoriginalTree :: NameComponentList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Just _justIannotatedTree
+                   {-# LINE 6096 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Just _justIoriginalTree
+                   {-# LINE 6102 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 6108 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 6114 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 6120 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 6126 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 6132 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _justIannotatedTree,_justIoriginalTree) =
+                  just_ _justOcat _justOflags _justOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_MaybeNameComponentList_Nothing :: T_MaybeNameComponentList
+_sem_MaybeNameComponentList_Nothing =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: MaybeNameComponentList
+              _lhsOoriginalTree :: MaybeNameComponentList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Nothing
+                   {-# LINE 6148 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Nothing
+                   {-# LINE 6154 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 6160 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 6166 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- MaybeScalarExpr ---------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         assignmentCastContext : Bool
+         cat                  : Catalog
+         downEnv              : Environment
+         expectedCast         : Bool
+         expectedType         : Maybe TypeExtra
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : MaybeScalarExpr 
+         originalTree         : MaybeScalarExpr 
+         upType               : Maybe TypeExtra
+   alternatives:
+      alternative Just:
+         child just           : ScalarExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nothing:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type MaybeScalarExpr = Maybe (ScalarExpr)
+-- cata
+_sem_MaybeScalarExpr :: MaybeScalarExpr ->
+                       T_MaybeScalarExpr
+_sem_MaybeScalarExpr (Prelude.Just x) =
+    (_sem_MaybeScalarExpr_Just (_sem_ScalarExpr x))
+_sem_MaybeScalarExpr Prelude.Nothing =
+    _sem_MaybeScalarExpr_Nothing
+-- semantic domain
+type T_MaybeScalarExpr = Bool ->
+                         Catalog ->
+                         Environment ->
+                         Bool ->
+                         (Maybe TypeExtra) ->
+                         TypeCheckFlags ->
+                         (Maybe TypeExtra) ->
+                         ( MaybeScalarExpr,MaybeScalarExpr,(Maybe TypeExtra))
+data Inh_MaybeScalarExpr = Inh_MaybeScalarExpr {_assignmentCastContext_Inh_MaybeScalarExpr :: Bool,_cat_Inh_MaybeScalarExpr :: Catalog,_downEnv_Inh_MaybeScalarExpr :: Environment,_expectedCast_Inh_MaybeScalarExpr :: Bool,_expectedType_Inh_MaybeScalarExpr :: (Maybe TypeExtra),_flags_Inh_MaybeScalarExpr :: TypeCheckFlags,_imCast_Inh_MaybeScalarExpr :: (Maybe TypeExtra)}
+data Syn_MaybeScalarExpr = Syn_MaybeScalarExpr {_annotatedTree_Syn_MaybeScalarExpr :: MaybeScalarExpr,_originalTree_Syn_MaybeScalarExpr :: MaybeScalarExpr,_upType_Syn_MaybeScalarExpr :: (Maybe TypeExtra)}
+_wrap_MaybeScalarExpr :: T_MaybeScalarExpr ->
+                        Inh_MaybeScalarExpr ->
+                        Syn_MaybeScalarExpr
+_wrap_MaybeScalarExpr sem (Inh_MaybeScalarExpr _lhsIassignmentCastContext _lhsIcat _lhsIdownEnv _lhsIexpectedCast _lhsIexpectedType _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupType) = sem _lhsIassignmentCastContext _lhsIcat _lhsIdownEnv _lhsIexpectedCast _lhsIexpectedType _lhsIflags _lhsIimCast
+     in  (Syn_MaybeScalarExpr _lhsOannotatedTree _lhsOoriginalTree _lhsOupType))
+_sem_MaybeScalarExpr_Just :: T_ScalarExpr ->
+                            T_MaybeScalarExpr
+_sem_MaybeScalarExpr_Just just_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast ->
+         (let _justOodbcFunction :: Bool
+              _lhsOannotatedTree :: MaybeScalarExpr
+              _lhsOoriginalTree :: MaybeScalarExpr
+              _lhsOupType :: (Maybe TypeExtra)
+              _justOassignmentCastContext :: Bool
+              _justOcat :: Catalog
+              _justOdownEnv :: Environment
+              _justOexpectedCast :: Bool
+              _justOexpectedType :: (Maybe TypeExtra)
+              _justOflags :: TypeCheckFlags
+              _justOimCast :: (Maybe TypeExtra)
+              _justIannotatedTree :: ScalarExpr
+              _justIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _justIoriginalTree :: ScalarExpr
+              _justIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 146, column 12)
+              _justOodbcFunction =
+                  ({-# LINE 146 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 6249 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Just _justIannotatedTree
+                   {-# LINE 6255 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Just _justIoriginalTree
+                   {-# LINE 6261 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 6267 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 6273 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (up)
+              _lhsOupType =
+                  ({-# LINE 109 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _justIupType
+                   {-# LINE 6279 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 6285 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 6291 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 6297 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOexpectedCast =
+                  ({-# LINE 111 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIexpectedCast
+                   {-# LINE 6303 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOexpectedType =
+                  ({-# LINE 110 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIexpectedType
+                   {-# LINE 6309 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 6315 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 6321 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _justIannotatedTree,_justIcolExprs,_justIoriginalTree,_justIupType) =
+                  just_ _justOassignmentCastContext _justOcat _justOdownEnv _justOexpectedCast _justOexpectedType _justOflags _justOimCast _justOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupType)))
+_sem_MaybeScalarExpr_Nothing :: T_MaybeScalarExpr
+_sem_MaybeScalarExpr_Nothing =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOupType :: (Maybe TypeExtra)
+              _lhsOannotatedTree :: MaybeScalarExpr
+              _lhsOoriginalTree :: MaybeScalarExpr
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 120, column 15)
+              _lhsOupType =
+                  ({-# LINE 120 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Nothing
+                   {-# LINE 6342 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Nothing
+                   {-# LINE 6348 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Nothing
+                   {-# LINE 6354 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 6360 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 6366 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupType)))
+-- MaybeSelectList ---------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : MaybeSelectList 
+         originalTree         : MaybeSelectList 
+   alternatives:
+      alternative Just:
+         child just           : SelectList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nothing:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type MaybeSelectList = Maybe (SelectList)
+-- cata
+_sem_MaybeSelectList :: MaybeSelectList ->
+                       T_MaybeSelectList
+_sem_MaybeSelectList (Prelude.Just x) =
+    (_sem_MaybeSelectList_Just (_sem_SelectList x))
+_sem_MaybeSelectList Prelude.Nothing =
+    _sem_MaybeSelectList_Nothing
+-- semantic domain
+type T_MaybeSelectList = Catalog ->
+                         TypeCheckFlags ->
+                         (Maybe TypeExtra) ->
+                         ( MaybeSelectList,MaybeSelectList)
+data Inh_MaybeSelectList = Inh_MaybeSelectList {_cat_Inh_MaybeSelectList :: Catalog,_flags_Inh_MaybeSelectList :: TypeCheckFlags,_imCast_Inh_MaybeSelectList :: (Maybe TypeExtra)}
+data Syn_MaybeSelectList = Syn_MaybeSelectList {_annotatedTree_Syn_MaybeSelectList :: MaybeSelectList,_originalTree_Syn_MaybeSelectList :: MaybeSelectList}
+_wrap_MaybeSelectList :: T_MaybeSelectList ->
+                        Inh_MaybeSelectList ->
+                        Syn_MaybeSelectList
+_wrap_MaybeSelectList sem (Inh_MaybeSelectList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_MaybeSelectList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_MaybeSelectList_Just :: T_SelectList ->
+                            T_MaybeSelectList
+_sem_MaybeSelectList_Just just_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _justOdownEnv :: Environment
+              _justOexpectedCast :: Bool
+              _justOexpectedType :: (Maybe [TypeExtra])
+              _justOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: MaybeSelectList
+              _lhsOoriginalTree :: MaybeSelectList
+              _justOcat :: Catalog
+              _justOflags :: TypeCheckFlags
+              _justOimCast :: (Maybe TypeExtra)
+              _justIannotatedTree :: SelectList
+              _justIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _justIoriginalTree :: SelectList
+              _justIupEnv :: Environment
+              _justIupType :: (Maybe [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 68, column 28)
+              _justOdownEnv =
+                  ({-# LINE 68 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 6435 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 69, column 28)
+              _justOexpectedCast =
+                  ({-# LINE 69 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 6441 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 70, column 28)
+              _justOexpectedType =
+                  ({-# LINE 70 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 6447 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 815, column 28)
+              _justOassignmentCastContext =
+                  ({-# LINE 815 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 6453 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Just _justIannotatedTree
+                   {-# LINE 6459 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Just _justIoriginalTree
+                   {-# LINE 6465 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 6471 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 6477 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 6483 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 6489 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 6495 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _justIannotatedTree,_justIcolExprs,_justIoriginalTree,_justIupEnv,_justIupType) =
+                  just_ _justOassignmentCastContext _justOcat _justOdownEnv _justOexpectedCast _justOexpectedType _justOflags _justOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_MaybeSelectList_Nothing :: T_MaybeSelectList
+_sem_MaybeSelectList_Nothing =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: MaybeSelectList
+              _lhsOoriginalTree :: MaybeSelectList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Nothing
+                   {-# LINE 6511 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Nothing
+                   {-# LINE 6517 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 6523 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 6529 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- MaybeTablePartitionDef --------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : MaybeTablePartitionDef 
+         originalTree         : MaybeTablePartitionDef 
+   alternatives:
+      alternative Just:
+         child just           : TablePartitionDef 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nothing:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type MaybeTablePartitionDef = Maybe (TablePartitionDef)
+-- cata
+_sem_MaybeTablePartitionDef :: MaybeTablePartitionDef ->
+                              T_MaybeTablePartitionDef
+_sem_MaybeTablePartitionDef (Prelude.Just x) =
+    (_sem_MaybeTablePartitionDef_Just (_sem_TablePartitionDef x))
+_sem_MaybeTablePartitionDef Prelude.Nothing =
+    _sem_MaybeTablePartitionDef_Nothing
+-- semantic domain
+type T_MaybeTablePartitionDef = Catalog ->
+                                TypeCheckFlags ->
+                                (Maybe TypeExtra) ->
+                                ( MaybeTablePartitionDef,MaybeTablePartitionDef)
+data Inh_MaybeTablePartitionDef = Inh_MaybeTablePartitionDef {_cat_Inh_MaybeTablePartitionDef :: Catalog,_flags_Inh_MaybeTablePartitionDef :: TypeCheckFlags,_imCast_Inh_MaybeTablePartitionDef :: (Maybe TypeExtra)}
+data Syn_MaybeTablePartitionDef = Syn_MaybeTablePartitionDef {_annotatedTree_Syn_MaybeTablePartitionDef :: MaybeTablePartitionDef,_originalTree_Syn_MaybeTablePartitionDef :: MaybeTablePartitionDef}
+_wrap_MaybeTablePartitionDef :: T_MaybeTablePartitionDef ->
+                               Inh_MaybeTablePartitionDef ->
+                               Syn_MaybeTablePartitionDef
+_wrap_MaybeTablePartitionDef sem (Inh_MaybeTablePartitionDef _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_MaybeTablePartitionDef _lhsOannotatedTree _lhsOoriginalTree))
+_sem_MaybeTablePartitionDef_Just :: T_TablePartitionDef ->
+                                   T_MaybeTablePartitionDef
+_sem_MaybeTablePartitionDef_Just just_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: MaybeTablePartitionDef
+              _lhsOoriginalTree :: MaybeTablePartitionDef
+              _justOcat :: Catalog
+              _justOflags :: TypeCheckFlags
+              _justOimCast :: (Maybe TypeExtra)
+              _justIannotatedTree :: TablePartitionDef
+              _justIoriginalTree :: TablePartitionDef
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Just _justIannotatedTree
+                   {-# LINE 6591 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Just _justIoriginalTree
+                   {-# LINE 6597 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 6603 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 6609 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 6615 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 6621 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 6627 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _justIannotatedTree,_justIoriginalTree) =
+                  just_ _justOcat _justOflags _justOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_MaybeTablePartitionDef_Nothing :: T_MaybeTablePartitionDef
+_sem_MaybeTablePartitionDef_Nothing =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: MaybeTablePartitionDef
+              _lhsOoriginalTree :: MaybeTablePartitionDef
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Nothing
+                   {-# LINE 6643 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Nothing
+                   {-# LINE 6649 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 6655 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 6661 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- Name --------------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+         tpe                  : Either [TypeError] TypeExtra
+      synthesized attributes:
+         annotatedTree        : Name 
+         originalTree         : Name 
+   alternatives:
+      alternative Name:
+         child ann            : Annotation 
+         child is             : {[NameComponent]}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AntiName:
+         child string         : {String}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data Name = Name (Annotation) (([NameComponent]))
+          | AntiName (String)
+          deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_Name :: Name ->
+            T_Name
+_sem_Name (Name _ann _is) =
+    (_sem_Name_Name (_sem_Annotation _ann) _is)
+_sem_Name (AntiName _string) =
+    (_sem_Name_AntiName _string)
+-- semantic domain
+type T_Name = Catalog ->
+              TypeCheckFlags ->
+              (Maybe TypeExtra) ->
+              (Either [TypeError] TypeExtra) ->
+              ( Name,Name)
+data Inh_Name = Inh_Name {_cat_Inh_Name :: Catalog,_flags_Inh_Name :: TypeCheckFlags,_imCast_Inh_Name :: (Maybe TypeExtra),_tpe_Inh_Name :: (Either [TypeError] TypeExtra)}
+data Syn_Name = Syn_Name {_annotatedTree_Syn_Name :: Name,_originalTree_Syn_Name :: Name}
+_wrap_Name :: T_Name ->
+             Inh_Name ->
+             Syn_Name
+_wrap_Name sem (Inh_Name _lhsIcat _lhsIflags _lhsIimCast _lhsItpe) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast _lhsItpe
+     in  (Syn_Name _lhsOannotatedTree _lhsOoriginalTree))
+_sem_Name_Name :: T_Annotation ->
+                 ([NameComponent]) ->
+                 T_Name
+_sem_Name_Name ann_ is_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast
+       _lhsItpe ->
+         (let _lhsOannotatedTree :: Name
+              _lhsOoriginalTree :: Name
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Name _annIannotatedTree is_
+                   {-# LINE 6732 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Name _annIoriginalTree is_
+                   {-# LINE 6738 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 6744 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 6750 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 6756 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 6762 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 6768 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOtpe =
+                  ({-# LINE 126 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsItpe
+                   {-# LINE 6774 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Name_AntiName :: String ->
+                     T_Name
+_sem_Name_AntiName string_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast
+       _lhsItpe ->
+         (let _lhsOannotatedTree :: Name
+              _lhsOoriginalTree :: Name
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AntiName string_
+                   {-# LINE 6792 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AntiName string_
+                   {-# LINE 6798 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 6804 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 6810 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- NameComponentList -------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : NameComponentList 
+         originalTree         : NameComponentList 
+   alternatives:
+      alternative Cons:
+         child hd             : {NameComponent}
+         child tl             : NameComponentList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type NameComponentList = [(NameComponent)]
+-- cata
+_sem_NameComponentList :: NameComponentList ->
+                         T_NameComponentList
+_sem_NameComponentList list =
+    (Prelude.foldr _sem_NameComponentList_Cons _sem_NameComponentList_Nil list)
+-- semantic domain
+type T_NameComponentList = Catalog ->
+                           TypeCheckFlags ->
+                           (Maybe TypeExtra) ->
+                           ( NameComponentList,NameComponentList)
+data Inh_NameComponentList = Inh_NameComponentList {_cat_Inh_NameComponentList :: Catalog,_flags_Inh_NameComponentList :: TypeCheckFlags,_imCast_Inh_NameComponentList :: (Maybe TypeExtra)}
+data Syn_NameComponentList = Syn_NameComponentList {_annotatedTree_Syn_NameComponentList :: NameComponentList,_originalTree_Syn_NameComponentList :: NameComponentList}
+_wrap_NameComponentList :: T_NameComponentList ->
+                          Inh_NameComponentList ->
+                          Syn_NameComponentList
+_wrap_NameComponentList sem (Inh_NameComponentList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_NameComponentList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_NameComponentList_Cons :: NameComponent ->
+                              T_NameComponentList ->
+                              T_NameComponentList
+_sem_NameComponentList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: NameComponentList
+              _lhsOoriginalTree :: NameComponentList
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _tlIannotatedTree :: NameComponentList
+              _tlIoriginalTree :: NameComponentList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) hd_ _tlIannotatedTree
+                   {-# LINE 6872 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) hd_ _tlIoriginalTree
+                   {-# LINE 6878 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 6884 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 6890 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 6896 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 6902 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 6908 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _tlIannotatedTree,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_NameComponentList_Nil :: T_NameComponentList
+_sem_NameComponentList_Nil =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: NameComponentList
+              _lhsOoriginalTree :: NameComponentList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 6924 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 6930 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 6936 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 6942 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- NameTypeNameListPair ----------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : NameTypeNameListPair 
+         originalTree         : NameTypeNameListPair 
+   alternatives:
+      alternative Tuple:
+         child x1             : Name 
+         child x2             : TypeNameList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type NameTypeNameListPair = ( Name,TypeNameList)
+-- cata
+_sem_NameTypeNameListPair :: NameTypeNameListPair ->
+                            T_NameTypeNameListPair
+_sem_NameTypeNameListPair ( x1,x2) =
+    (_sem_NameTypeNameListPair_Tuple (_sem_Name x1) (_sem_TypeNameList x2))
+-- semantic domain
+type T_NameTypeNameListPair = Catalog ->
+                              TypeCheckFlags ->
+                              (Maybe TypeExtra) ->
+                              ( NameTypeNameListPair,NameTypeNameListPair)
+data Inh_NameTypeNameListPair = Inh_NameTypeNameListPair {_cat_Inh_NameTypeNameListPair :: Catalog,_flags_Inh_NameTypeNameListPair :: TypeCheckFlags,_imCast_Inh_NameTypeNameListPair :: (Maybe TypeExtra)}
+data Syn_NameTypeNameListPair = Syn_NameTypeNameListPair {_annotatedTree_Syn_NameTypeNameListPair :: NameTypeNameListPair,_originalTree_Syn_NameTypeNameListPair :: NameTypeNameListPair}
+_wrap_NameTypeNameListPair :: T_NameTypeNameListPair ->
+                             Inh_NameTypeNameListPair ->
+                             Syn_NameTypeNameListPair
+_wrap_NameTypeNameListPair sem (Inh_NameTypeNameListPair _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_NameTypeNameListPair _lhsOannotatedTree _lhsOoriginalTree))
+_sem_NameTypeNameListPair_Tuple :: T_Name ->
+                                  T_TypeNameList ->
+                                  T_NameTypeNameListPair
+_sem_NameTypeNameListPair_Tuple x1_ x2_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _x1Otpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: NameTypeNameListPair
+              _lhsOoriginalTree :: NameTypeNameListPair
+              _x1Ocat :: Catalog
+              _x1Oflags :: TypeCheckFlags
+              _x1OimCast :: (Maybe TypeExtra)
+              _x2Ocat :: Catalog
+              _x2Oflags :: TypeCheckFlags
+              _x2OimCast :: (Maybe TypeExtra)
+              _x1IannotatedTree :: Name
+              _x1IoriginalTree :: Name
+              _x2IannotatedTree :: TypeNameList
+              _x2IoriginalTree :: TypeNameList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 71, column 34)
+              _x1Otpe =
+                  ({-# LINE 71 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 7006 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (_x1IannotatedTree,_x2IannotatedTree)
+                   {-# LINE 7012 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (_x1IoriginalTree,_x2IoriginalTree)
+                   {-# LINE 7018 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 7024 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 7030 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1Ocat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 7036 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1Oflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 7042 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1OimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 7048 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x2Ocat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 7054 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x2Oflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 7060 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x2OimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 7066 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _x1IannotatedTree,_x1IoriginalTree) =
+                  x1_ _x1Ocat _x1Oflags _x1OimCast _x1Otpe
+              ( _x2IannotatedTree,_x2IoriginalTree) =
+                  x2_ _x2Ocat _x2Oflags _x2OimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- NameTypeNameListPairList ------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : NameTypeNameListPairList 
+         originalTree         : NameTypeNameListPairList 
+   alternatives:
+      alternative Cons:
+         child hd             : NameTypeNameListPair 
+         child tl             : NameTypeNameListPairList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type NameTypeNameListPairList = [NameTypeNameListPair]
+-- cata
+_sem_NameTypeNameListPairList :: NameTypeNameListPairList ->
+                                T_NameTypeNameListPairList
+_sem_NameTypeNameListPairList list =
+    (Prelude.foldr _sem_NameTypeNameListPairList_Cons _sem_NameTypeNameListPairList_Nil (Prelude.map _sem_NameTypeNameListPair list))
+-- semantic domain
+type T_NameTypeNameListPairList = Catalog ->
+                                  TypeCheckFlags ->
+                                  (Maybe TypeExtra) ->
+                                  ( NameTypeNameListPairList,NameTypeNameListPairList)
+data Inh_NameTypeNameListPairList = Inh_NameTypeNameListPairList {_cat_Inh_NameTypeNameListPairList :: Catalog,_flags_Inh_NameTypeNameListPairList :: TypeCheckFlags,_imCast_Inh_NameTypeNameListPairList :: (Maybe TypeExtra)}
+data Syn_NameTypeNameListPairList = Syn_NameTypeNameListPairList {_annotatedTree_Syn_NameTypeNameListPairList :: NameTypeNameListPairList,_originalTree_Syn_NameTypeNameListPairList :: NameTypeNameListPairList}
+_wrap_NameTypeNameListPairList :: T_NameTypeNameListPairList ->
+                                 Inh_NameTypeNameListPairList ->
+                                 Syn_NameTypeNameListPairList
+_wrap_NameTypeNameListPairList sem (Inh_NameTypeNameListPairList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_NameTypeNameListPairList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_NameTypeNameListPairList_Cons :: T_NameTypeNameListPair ->
+                                     T_NameTypeNameListPairList ->
+                                     T_NameTypeNameListPairList
+_sem_NameTypeNameListPairList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: NameTypeNameListPairList
+              _lhsOoriginalTree :: NameTypeNameListPairList
+              _hdOcat :: Catalog
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: NameTypeNameListPair
+              _hdIoriginalTree :: NameTypeNameListPair
+              _tlIannotatedTree :: NameTypeNameListPairList
+              _tlIoriginalTree :: NameTypeNameListPairList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 7137 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 7143 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 7149 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 7155 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 7161 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 7167 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 7173 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 7179 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 7185 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 7191 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree) =
+                  hd_ _hdOcat _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_NameTypeNameListPairList_Nil :: T_NameTypeNameListPairList
+_sem_NameTypeNameListPairList_Nil =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: NameTypeNameListPairList
+              _lhsOoriginalTree :: NameTypeNameListPairList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 7209 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 7215 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 7221 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 7227 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- OnExpr ------------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         downEnv              : Environment
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : OnExpr 
+         originalTree         : OnExpr 
+   alternatives:
+      alternative Just:
+         child just           : JoinExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nothing:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type OnExpr = Maybe (JoinExpr)
+-- cata
+_sem_OnExpr :: OnExpr ->
+              T_OnExpr
+_sem_OnExpr (Prelude.Just x) =
+    (_sem_OnExpr_Just (_sem_JoinExpr x))
+_sem_OnExpr Prelude.Nothing =
+    _sem_OnExpr_Nothing
+-- semantic domain
+type T_OnExpr = Catalog ->
+                Environment ->
+                TypeCheckFlags ->
+                (Maybe TypeExtra) ->
+                ( OnExpr,OnExpr)
+data Inh_OnExpr = Inh_OnExpr {_cat_Inh_OnExpr :: Catalog,_downEnv_Inh_OnExpr :: Environment,_flags_Inh_OnExpr :: TypeCheckFlags,_imCast_Inh_OnExpr :: (Maybe TypeExtra)}
+data Syn_OnExpr = Syn_OnExpr {_annotatedTree_Syn_OnExpr :: OnExpr,_originalTree_Syn_OnExpr :: OnExpr}
+_wrap_OnExpr :: T_OnExpr ->
+               Inh_OnExpr ->
+               Syn_OnExpr
+_wrap_OnExpr sem (Inh_OnExpr _lhsIcat _lhsIdownEnv _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIdownEnv _lhsIflags _lhsIimCast
+     in  (Syn_OnExpr _lhsOannotatedTree _lhsOoriginalTree))
+_sem_OnExpr_Just :: T_JoinExpr ->
+                   T_OnExpr
+_sem_OnExpr_Just just_ =
+    (\ _lhsIcat
+       _lhsIdownEnv
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: OnExpr
+              _lhsOoriginalTree :: OnExpr
+              _justOcat :: Catalog
+              _justOdownEnv :: Environment
+              _justOflags :: TypeCheckFlags
+              _justOimCast :: (Maybe TypeExtra)
+              _justIannotatedTree :: JoinExpr
+              _justIoriginalTree :: JoinExpr
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Just _justIannotatedTree
+                   {-# LINE 7293 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Just _justIoriginalTree
+                   {-# LINE 7299 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 7305 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 7311 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 7317 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOdownEnv =
+                  ({-# LINE 215 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 7323 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 7329 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _justOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 7335 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _justIannotatedTree,_justIoriginalTree) =
+                  just_ _justOcat _justOdownEnv _justOflags _justOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_OnExpr_Nothing :: T_OnExpr
+_sem_OnExpr_Nothing =
+    (\ _lhsIcat
+       _lhsIdownEnv
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: OnExpr
+              _lhsOoriginalTree :: OnExpr
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Nothing
+                   {-# LINE 7352 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Nothing
+                   {-# LINE 7358 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 7364 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 7370 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- ParamDef ----------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : ParamDef 
+         originalTree         : ParamDef 
+   alternatives:
+      alternative ParamDef:
+         child ann            : Annotation 
+         child name           : {NameComponent}
+         child typ            : TypeName 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative ParamDefTp:
+         child ann            : Annotation 
+         child typ            : TypeName 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data ParamDef = ParamDef (Annotation) (NameComponent) (TypeName)
+              | ParamDefTp (Annotation) (TypeName)
+              deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_ParamDef :: ParamDef ->
+                T_ParamDef
+_sem_ParamDef (ParamDef _ann _name _typ) =
+    (_sem_ParamDef_ParamDef (_sem_Annotation _ann) _name (_sem_TypeName _typ))
+_sem_ParamDef (ParamDefTp _ann _typ) =
+    (_sem_ParamDef_ParamDefTp (_sem_Annotation _ann) (_sem_TypeName _typ))
+-- semantic domain
+type T_ParamDef = Catalog ->
+                  TypeCheckFlags ->
+                  (Maybe TypeExtra) ->
+                  ( ParamDef,ParamDef)
+data Inh_ParamDef = Inh_ParamDef {_cat_Inh_ParamDef :: Catalog,_flags_Inh_ParamDef :: TypeCheckFlags,_imCast_Inh_ParamDef :: (Maybe TypeExtra)}
+data Syn_ParamDef = Syn_ParamDef {_annotatedTree_Syn_ParamDef :: ParamDef,_originalTree_Syn_ParamDef :: ParamDef}
+_wrap_ParamDef :: T_ParamDef ->
+                 Inh_ParamDef ->
+                 Syn_ParamDef
+_wrap_ParamDef sem (Inh_ParamDef _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_ParamDef _lhsOannotatedTree _lhsOoriginalTree))
+_sem_ParamDef_ParamDef :: T_Annotation ->
+                         NameComponent ->
+                         T_TypeName ->
+                         T_ParamDef
+_sem_ParamDef_ParamDef ann_ name_ typ_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: ParamDef
+              _lhsOoriginalTree :: ParamDef
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _typOcat :: Catalog
+              _typOflags :: TypeCheckFlags
+              _typOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _typIannotatedTree :: TypeName
+              _typInamedType :: (Maybe TypeExtra)
+              _typIoriginalTree :: TypeName
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 72, column 25)
+              _annOtpe =
+                  ({-# LINE 72 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 7447 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ParamDef _annIannotatedTree name_ _typIannotatedTree
+                   {-# LINE 7453 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ParamDef _annIoriginalTree name_ _typIoriginalTree
+                   {-# LINE 7459 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 7465 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 7471 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 7477 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 7483 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 7489 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 7495 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 7501 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 7507 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _typIannotatedTree,_typInamedType,_typIoriginalTree) =
+                  typ_ _typOcat _typOflags _typOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_ParamDef_ParamDefTp :: T_Annotation ->
+                           T_TypeName ->
+                           T_ParamDef
+_sem_ParamDef_ParamDefTp ann_ typ_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: ParamDef
+              _lhsOoriginalTree :: ParamDef
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _typOcat :: Catalog
+              _typOflags :: TypeCheckFlags
+              _typOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _typIannotatedTree :: TypeName
+              _typInamedType :: (Maybe TypeExtra)
+              _typIoriginalTree :: TypeName
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 73, column 27)
+              _annOtpe =
+                  ({-# LINE 73 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 7539 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ParamDefTp _annIannotatedTree _typIannotatedTree
+                   {-# LINE 7545 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ParamDefTp _annIoriginalTree _typIoriginalTree
+                   {-# LINE 7551 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 7557 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 7563 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 7569 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 7575 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 7581 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 7587 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 7593 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 7599 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _typIannotatedTree,_typInamedType,_typIoriginalTree) =
+                  typ_ _typOcat _typOflags _typOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- ParamDefList ------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : ParamDefList 
+         originalTree         : ParamDefList 
+   alternatives:
+      alternative Cons:
+         child hd             : ParamDef 
+         child tl             : ParamDefList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type ParamDefList = [ParamDef]
+-- cata
+_sem_ParamDefList :: ParamDefList ->
+                    T_ParamDefList
+_sem_ParamDefList list =
+    (Prelude.foldr _sem_ParamDefList_Cons _sem_ParamDefList_Nil (Prelude.map _sem_ParamDef list))
+-- semantic domain
+type T_ParamDefList = Catalog ->
+                      TypeCheckFlags ->
+                      (Maybe TypeExtra) ->
+                      ( ParamDefList,ParamDefList)
+data Inh_ParamDefList = Inh_ParamDefList {_cat_Inh_ParamDefList :: Catalog,_flags_Inh_ParamDefList :: TypeCheckFlags,_imCast_Inh_ParamDefList :: (Maybe TypeExtra)}
+data Syn_ParamDefList = Syn_ParamDefList {_annotatedTree_Syn_ParamDefList :: ParamDefList,_originalTree_Syn_ParamDefList :: ParamDefList}
+_wrap_ParamDefList :: T_ParamDefList ->
+                     Inh_ParamDefList ->
+                     Syn_ParamDefList
+_wrap_ParamDefList sem (Inh_ParamDefList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_ParamDefList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_ParamDefList_Cons :: T_ParamDef ->
+                         T_ParamDefList ->
+                         T_ParamDefList
+_sem_ParamDefList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: ParamDefList
+              _lhsOoriginalTree :: ParamDefList
+              _hdOcat :: Catalog
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: ParamDef
+              _hdIoriginalTree :: ParamDef
+              _tlIannotatedTree :: ParamDefList
+              _tlIoriginalTree :: ParamDefList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 7670 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 7676 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 7682 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 7688 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 7694 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 7700 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 7706 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 7712 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 7718 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 7724 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree) =
+                  hd_ _hdOcat _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_ParamDefList_Nil :: T_ParamDefList
+_sem_ParamDefList_Nil =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: ParamDefList
+              _lhsOoriginalTree :: ParamDefList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 7742 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 7748 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 7754 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 7760 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- QueryExpr ---------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         assignmentCastContext : Bool
+         cat                  : Catalog
+         expectedType         : Maybe [TypeExtra]
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+         outerDownEnv         : Maybe Environment
+      synthesized attributes:
+         annotatedTree        : QueryExpr 
+         originalTree         : QueryExpr 
+         upType               : Maybe [(Text,TypeExtra)]
+   alternatives:
+      alternative Select:
+         child ann            : Annotation 
+         child selDistinct    : {Distinct}
+         child selSelectList  : SelectList 
+         child selTref        : TableRefList 
+         child selWhere       : MaybeBoolExpr 
+         child selGroupBy     : ScalarExprList 
+         child selHaving      : MaybeBoolExpr 
+         child selOrderBy     : ScalarExprDirectionPairList 
+         child selLimit       : MaybeScalarExpr 
+         child selOffset      : MaybeScalarExpr 
+         child selOption      : {[QueryHint]}
+         visit 0:
+            local tpee        : {Either [TypeError] [(Text,TypeExtra)]}
+            local tpe         : {Either [TypeError] TypeExtra}
+            local selGroupBy  : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative CombineQueryExpr:
+         child ann            : Annotation 
+         child cqType         : {CombineType}
+         child cqQe0          : QueryExpr 
+         child cqQe1          : QueryExpr 
+         visit 0:
+            local tpe         : {Either [TypeError] TypeExtra}
+            local tpee        : {Either [TypeError] [(Text,TypeExtra)]}
+            local annotatedTree : _
+            local originalTree : _
+      alternative Values:
+         child ann            : Annotation 
+         child qeValues       : ScalarExprListList 
+         visit 0:
+            local tpe         : {Either [TypeError] TypeExtra}
+            local tpee        : {Either [TypeError] [(Text,TypeExtra)]}
+            local annotatedTree : _
+            local originalTree : _
+      alternative WithQueryExpr:
+         child ann            : Annotation 
+         child withs          : WithQueryList 
+         child withQe         : QueryExpr 
+         visit 0:
+            local tpe         : {Either [TypeError] TypeExtra}
+            local tpee        : {Either [TypeError] [(Text,TypeExtra)]}
+            local annotatedTree : _
+            local originalTree : _
+-}
+
+data QueryExpr
+    = Select { ann:: (Annotation)
+             ,selDistinct :: ( Distinct)
+             ,selSelectList :: ( SelectList)
+             ,selTref :: ( TableRefList)
+             ,selWhere :: ( MaybeBoolExpr)
+             ,selGroupBy :: ( ScalarExprList)
+             ,selHaving :: ( MaybeBoolExpr)
+             ,selOrderBy :: ( ScalarExprDirectionPairList)
+             ,selLimit :: ( MaybeScalarExpr)
+             ,selOffset :: ( MaybeScalarExpr)
+             ,selOption :: ( [QueryHint])
+        }
+    |  CombineQueryExpr { ann:: (Annotation)
+                       ,cqType :: ( CombineType)
+                       ,cqQe0 :: ( QueryExpr)
+                       ,cqQe1 :: ( QueryExpr)
+        }
+    |  Values { ann:: (Annotation)
+             ,qeValues:: (ScalarExprListList)
+        }
+    |  WithQueryExpr { ann :: ( Annotation)
+                    ,withs :: ( WithQueryList)
+                    ,withQe :: ( QueryExpr)
+
+-- todo: represent parens explicitly in queryexpr
+--    | QueryExprParens ex:: QueryExpr
+
+
+    } deriving (Eq,Show,Data,Typeable)
+
+-- cata
+_sem_QueryExpr :: QueryExpr ->
+                 T_QueryExpr
+_sem_QueryExpr (Select _ann _selDistinct _selSelectList _selTref _selWhere _selGroupBy _selHaving _selOrderBy _selLimit _selOffset _selOption) =
+    (_sem_QueryExpr_Select (_sem_Annotation _ann) _selDistinct (_sem_SelectList _selSelectList) (_sem_TableRefList _selTref) (_sem_MaybeBoolExpr _selWhere) (_sem_ScalarExprList _selGroupBy) (_sem_MaybeBoolExpr _selHaving) (_sem_ScalarExprDirectionPairList _selOrderBy) (_sem_MaybeScalarExpr _selLimit) (_sem_MaybeScalarExpr _selOffset) _selOption)
+_sem_QueryExpr (CombineQueryExpr _ann _cqType _cqQe0 _cqQe1) =
+    (_sem_QueryExpr_CombineQueryExpr (_sem_Annotation _ann) _cqType (_sem_QueryExpr _cqQe0) (_sem_QueryExpr _cqQe1))
+_sem_QueryExpr (Values _ann _qeValues) =
+    (_sem_QueryExpr_Values (_sem_Annotation _ann) (_sem_ScalarExprListList _qeValues))
+_sem_QueryExpr (WithQueryExpr _ann _withs _withQe) =
+    (_sem_QueryExpr_WithQueryExpr (_sem_Annotation _ann) (_sem_WithQueryList _withs) (_sem_QueryExpr _withQe))
+-- semantic domain
+type T_QueryExpr = Bool ->
+                   Catalog ->
+                   (Maybe [TypeExtra]) ->
+                   TypeCheckFlags ->
+                   (Maybe TypeExtra) ->
+                   (Maybe Environment) ->
+                   ( QueryExpr,QueryExpr,(Maybe [(Text,TypeExtra)]))
+data Inh_QueryExpr = Inh_QueryExpr {_assignmentCastContext_Inh_QueryExpr :: Bool,_cat_Inh_QueryExpr :: Catalog,_expectedType_Inh_QueryExpr :: (Maybe [TypeExtra]),_flags_Inh_QueryExpr :: TypeCheckFlags,_imCast_Inh_QueryExpr :: (Maybe TypeExtra),_outerDownEnv_Inh_QueryExpr :: (Maybe Environment)}
+data Syn_QueryExpr = Syn_QueryExpr {_annotatedTree_Syn_QueryExpr :: QueryExpr,_originalTree_Syn_QueryExpr :: QueryExpr,_upType_Syn_QueryExpr :: (Maybe [(Text,TypeExtra)])}
+_wrap_QueryExpr :: T_QueryExpr ->
+                  Inh_QueryExpr ->
+                  Syn_QueryExpr
+_wrap_QueryExpr sem (Inh_QueryExpr _lhsIassignmentCastContext _lhsIcat _lhsIexpectedType _lhsIflags _lhsIimCast _lhsIouterDownEnv) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupType) = sem _lhsIassignmentCastContext _lhsIcat _lhsIexpectedType _lhsIflags _lhsIimCast _lhsIouterDownEnv
+     in  (Syn_QueryExpr _lhsOannotatedTree _lhsOoriginalTree _lhsOupType))
+_sem_QueryExpr_Select :: T_Annotation ->
+                        Distinct ->
+                        T_SelectList ->
+                        T_TableRefList ->
+                        T_MaybeBoolExpr ->
+                        T_ScalarExprList ->
+                        T_MaybeBoolExpr ->
+                        T_ScalarExprDirectionPairList ->
+                        T_MaybeScalarExpr ->
+                        T_MaybeScalarExpr ->
+                        ([QueryHint]) ->
+                        T_QueryExpr
+_sem_QueryExpr_Select ann_ selDistinct_ selSelectList_ selTref_ selWhere_ selGroupBy_ selHaving_ selOrderBy_ selLimit_ selOffset_ selOption_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIouterDownEnv ->
+         (let _selGroupByOexpectedCast :: Bool
+              _selLimitOdownEnv :: Environment
+              _selLimitOexpectedCast :: Bool
+              _selOffsetOdownEnv :: Environment
+              _selOffsetOexpectedCast :: Bool
+              _selSelectListOexpectedCast :: Bool
+              _selSelectListOdownEnv :: Environment
+              _selGroupByOdownEnv :: Environment
+              _selHavingOdownEnv :: Environment
+              _selOrderByOdownEnv :: Environment
+              _tpee :: (Either [TypeError] [(Text,TypeExtra)])
+              _selWhereOdownEnv :: Environment
+              _tpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe [(Text,TypeExtra)])
+              _lhsOannotatedTree :: QueryExpr
+              _selGroupByOexpectedTypes :: ([TypeExtra])
+              _selLimitOexpectedType :: (Maybe TypeExtra)
+              _selOffsetOexpectedType :: (Maybe TypeExtra)
+              _lhsOoriginalTree :: QueryExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _selSelectListOassignmentCastContext :: Bool
+              _selSelectListOcat :: Catalog
+              _selSelectListOexpectedType :: (Maybe [TypeExtra])
+              _selSelectListOflags :: TypeCheckFlags
+              _selSelectListOimCast :: (Maybe TypeExtra)
+              _selTrefOcat :: Catalog
+              _selTrefOflags :: TypeCheckFlags
+              _selTrefOimCast :: (Maybe TypeExtra)
+              _selWhereOcat :: Catalog
+              _selWhereOflags :: TypeCheckFlags
+              _selWhereOimCast :: (Maybe TypeExtra)
+              _selGroupByOassignmentCastContext :: Bool
+              _selGroupByOcat :: Catalog
+              _selGroupByOflags :: TypeCheckFlags
+              _selGroupByOimCast :: (Maybe TypeExtra)
+              _selHavingOcat :: Catalog
+              _selHavingOflags :: TypeCheckFlags
+              _selHavingOimCast :: (Maybe TypeExtra)
+              _selOrderByOcat :: Catalog
+              _selOrderByOflags :: TypeCheckFlags
+              _selOrderByOimCast :: (Maybe TypeExtra)
+              _selLimitOassignmentCastContext :: Bool
+              _selLimitOcat :: Catalog
+              _selLimitOflags :: TypeCheckFlags
+              _selLimitOimCast :: (Maybe TypeExtra)
+              _selOffsetOassignmentCastContext :: Bool
+              _selOffsetOcat :: Catalog
+              _selOffsetOflags :: TypeCheckFlags
+              _selOffsetOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _selSelectListIannotatedTree :: SelectList
+              _selSelectListIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _selSelectListIoriginalTree :: SelectList
+              _selSelectListIupEnv :: Environment
+              _selSelectListIupType :: (Maybe [(Text,TypeExtra)])
+              _selTrefIannotatedTree :: TableRefList
+              _selTrefIoriginalTree :: TableRefList
+              _selTrefIupEnv :: Environment
+              _selWhereIannotatedTree :: MaybeBoolExpr
+              _selWhereIoriginalTree :: MaybeBoolExpr
+              _selGroupByIannotatedTree :: ScalarExprList
+              _selGroupByIoriginalTree :: ScalarExprList
+              _selGroupByIupTypes :: ([Maybe TypeExtra])
+              _selHavingIannotatedTree :: MaybeBoolExpr
+              _selHavingIoriginalTree :: MaybeBoolExpr
+              _selOrderByIannotatedTree :: ScalarExprDirectionPairList
+              _selOrderByIoriginalTree :: ScalarExprDirectionPairList
+              _selLimitIannotatedTree :: MaybeScalarExpr
+              _selLimitIoriginalTree :: MaybeScalarExpr
+              _selLimitIupType :: (Maybe TypeExtra)
+              _selOffsetIannotatedTree :: MaybeScalarExpr
+              _selOffsetIoriginalTree :: MaybeScalarExpr
+              _selOffsetIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 74, column 24)
+              _selGroupByOexpectedCast =
+                  ({-# LINE 74 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 7956 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 75, column 24)
+              _selLimitOdownEnv =
+                  ({-# LINE 75 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 7962 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 76, column 24)
+              _selLimitOexpectedCast =
+                  ({-# LINE 76 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 7968 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 77, column 24)
+              _selOffsetOdownEnv =
+                  ({-# LINE 77 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 7974 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 78, column 24)
+              _selOffsetOexpectedCast =
+                  ({-# LINE 78 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 7980 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 79, column 24)
+              _selSelectListOexpectedCast =
+                  ({-# LINE 79 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 7986 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 106, column 9)
+              _selSelectListOdownEnv =
+                  ({-# LINE 106 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _selTrefIupEnv
+                   {-# LINE 7992 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 107, column 9)
+              _selGroupByOdownEnv =
+                  ({-# LINE 107 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _selTrefIupEnv
+                   {-# LINE 7998 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 108, column 9)
+              _selHavingOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _selTrefIupEnv
+                   {-# LINE 8004 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 128, column 9)
+              _selOrderByOdownEnv =
+                  ({-# LINE 128 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   E.orderByEnvironment _selSelectListIupEnv _selTrefIupEnv
+                   {-# LINE 8010 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 129, column 9)
+              _tpee =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   maybe (Left []) Right _selSelectListIupType
+                   {-# LINE 8016 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 132, column 9)
+              _selWhereOdownEnv =
+                  ({-# LINE 132 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   maybe _selTrefIupEnv
+                    (\e -> E.createCorrelatedSubqueryEnvironment e _selTrefIupEnv)
+                    _lhsIouterDownEnv
+                   {-# LINE 8024 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 142, column 9)
+              _tpe =
+                  ({-# LINE 142 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   liftM (mkTypeExtra . CompositeType) _tpee
+                   {-# LINE 8030 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 145, column 9)
+              _lhsOupType =
+                  ({-# LINE 145 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   either (const Nothing) Just _tpee
+                   {-# LINE 8036 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 239, column 9)
+              _selGroupBy =
+                  ({-# LINE 239 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   case _selGroupByIannotatedTree of
+                       [App e nm@(Name _ [Nmc "cube"]) es] ->
+                         [App e{anType = (Just (mkTypeExtra $ ScalarType "int4"))
+                               ,anErrs = []
+                               } nm es]
+                       x -> x
+                   {-# LINE 8047 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 248, column 9)
+              _lhsOannotatedTree =
+                  ({-# LINE 248 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   Select _annIannotatedTree
+                          selDistinct_
+                          _selSelectListIannotatedTree
+                          _selTrefIannotatedTree
+                          _selWhereIannotatedTree
+                          _selGroupBy
+                          _selHavingIannotatedTree
+                          _selOrderByIannotatedTree
+                          _selLimitIannotatedTree
+                          _selOffsetIannotatedTree
+                          selOption_
+                   {-# LINE 8063 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 766, column 7)
+              _selGroupByOexpectedTypes =
+                  ({-# LINE 766 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   []
+                   {-# LINE 8069 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 767, column 7)
+              _selLimitOexpectedType =
+                  ({-# LINE 767 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Nothing
+                   {-# LINE 8075 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 768, column 7)
+              _selOffsetOexpectedType =
+                  ({-# LINE 768 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Nothing
+                   {-# LINE 8081 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Select _annIannotatedTree selDistinct_ _selSelectListIannotatedTree _selTrefIannotatedTree _selWhereIannotatedTree _selGroupByIannotatedTree _selHavingIannotatedTree _selOrderByIannotatedTree _selLimitIannotatedTree _selOffsetIannotatedTree selOption_
+                   {-# LINE 8087 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Select _annIoriginalTree selDistinct_ _selSelectListIoriginalTree _selTrefIoriginalTree _selWhereIoriginalTree _selGroupByIoriginalTree _selHavingIoriginalTree _selOrderByIoriginalTree _selLimitIoriginalTree _selOffsetIoriginalTree selOption_
+                   {-# LINE 8093 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 8099 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8105 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8111 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8117 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (from local)
+              _annOtpe =
+                  ({-# LINE 126 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _tpe
+                   {-# LINE 8123 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selSelectListOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 8129 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selSelectListOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8135 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selSelectListOexpectedType =
+                  ({-# LINE 159 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _lhsIexpectedType
+                   {-# LINE 8141 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selSelectListOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8147 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selSelectListOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8153 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selTrefOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8159 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selTrefOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8165 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selTrefOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8171 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selWhereOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8177 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selWhereOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8183 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selWhereOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8189 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selGroupByOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 8195 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selGroupByOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8201 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selGroupByOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8207 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selGroupByOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8213 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selHavingOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8219 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selHavingOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8225 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selHavingOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8231 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOrderByOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8237 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOrderByOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8243 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOrderByOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8249 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selLimitOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 8255 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selLimitOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8261 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selLimitOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8267 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selLimitOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8273 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOffsetOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 8279 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOffsetOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8285 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOffsetOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8291 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOffsetOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8297 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _selSelectListIannotatedTree,_selSelectListIcolExprs,_selSelectListIoriginalTree,_selSelectListIupEnv,_selSelectListIupType) =
+                  selSelectList_ _selSelectListOassignmentCastContext _selSelectListOcat _selSelectListOdownEnv _selSelectListOexpectedCast _selSelectListOexpectedType _selSelectListOflags _selSelectListOimCast
+              ( _selTrefIannotatedTree,_selTrefIoriginalTree,_selTrefIupEnv) =
+                  selTref_ _selTrefOcat _selTrefOflags _selTrefOimCast
+              ( _selWhereIannotatedTree,_selWhereIoriginalTree) =
+                  selWhere_ _selWhereOcat _selWhereOdownEnv _selWhereOflags _selWhereOimCast
+              ( _selGroupByIannotatedTree,_selGroupByIoriginalTree,_selGroupByIupTypes) =
+                  selGroupBy_ _selGroupByOassignmentCastContext _selGroupByOcat _selGroupByOdownEnv _selGroupByOexpectedCast _selGroupByOexpectedTypes _selGroupByOflags _selGroupByOimCast
+              ( _selHavingIannotatedTree,_selHavingIoriginalTree) =
+                  selHaving_ _selHavingOcat _selHavingOdownEnv _selHavingOflags _selHavingOimCast
+              ( _selOrderByIannotatedTree,_selOrderByIoriginalTree) =
+                  selOrderBy_ _selOrderByOcat _selOrderByOdownEnv _selOrderByOflags _selOrderByOimCast
+              ( _selLimitIannotatedTree,_selLimitIoriginalTree,_selLimitIupType) =
+                  selLimit_ _selLimitOassignmentCastContext _selLimitOcat _selLimitOdownEnv _selLimitOexpectedCast _selLimitOexpectedType _selLimitOflags _selLimitOimCast
+              ( _selOffsetIannotatedTree,_selOffsetIoriginalTree,_selOffsetIupType) =
+                  selOffset_ _selOffsetOassignmentCastContext _selOffsetOcat _selOffsetOdownEnv _selOffsetOexpectedCast _selOffsetOexpectedType _selOffsetOflags _selOffsetOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupType)))
+_sem_QueryExpr_CombineQueryExpr :: T_Annotation ->
+                                  CombineType ->
+                                  T_QueryExpr ->
+                                  T_QueryExpr ->
+                                  T_QueryExpr
+_sem_QueryExpr_CombineQueryExpr ann_ cqType_ cqQe0_ cqQe1_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIouterDownEnv ->
+         (let _tpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe [(Text,TypeExtra)])
+              _tpee :: (Either [TypeError] [(Text,TypeExtra)])
+              _lhsOannotatedTree :: QueryExpr
+              _lhsOoriginalTree :: QueryExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _cqQe0OassignmentCastContext :: Bool
+              _cqQe0Ocat :: Catalog
+              _cqQe0OexpectedType :: (Maybe [TypeExtra])
+              _cqQe0Oflags :: TypeCheckFlags
+              _cqQe0OimCast :: (Maybe TypeExtra)
+              _cqQe0OouterDownEnv :: (Maybe Environment)
+              _cqQe1OassignmentCastContext :: Bool
+              _cqQe1Ocat :: Catalog
+              _cqQe1OexpectedType :: (Maybe [TypeExtra])
+              _cqQe1Oflags :: TypeCheckFlags
+              _cqQe1OimCast :: (Maybe TypeExtra)
+              _cqQe1OouterDownEnv :: (Maybe Environment)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _cqQe0IannotatedTree :: QueryExpr
+              _cqQe0IoriginalTree :: QueryExpr
+              _cqQe0IupType :: (Maybe [(Text,TypeExtra)])
+              _cqQe1IannotatedTree :: QueryExpr
+              _cqQe1IoriginalTree :: QueryExpr
+              _cqQe1IupType :: (Maybe [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 142, column 9)
+              _tpe =
+                  ({-# LINE 142 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   liftM (mkTypeExtra . CompositeType) _tpee
+                   {-# LINE 8363 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 145, column 9)
+              _lhsOupType =
+                  ({-# LINE 145 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   either (const Nothing) Just _tpee
+                   {-# LINE 8369 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 156, column 9)
+              _tpee =
+                  ({-# LINE 156 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   do
+                   a <- maybe (Left []) Right _cqQe0IupType
+                   b <- maybe (Left []) Right _cqQe1IupType
+                   unless (length a == length b) $ Left [IncompatibleUnionTypes (CompositeType a) (CompositeType b)]
+                   let uts = zipWithM (\(_,te1) (_,te2) -> resolveResultSetTypeExtra _lhsIcat [te1,te2])
+                                 a b
+                   case uts of
+                     Left{} -> Left [IncompatibleUnionTypes (CompositeType a) (CompositeType b)]
+                     Right uts' -> return $ zipWith (\(n,_) te -> (n,te)) a uts'
+                   {-# LINE 8383 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CombineQueryExpr _annIannotatedTree cqType_ _cqQe0IannotatedTree _cqQe1IannotatedTree
+                   {-# LINE 8389 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CombineQueryExpr _annIoriginalTree cqType_ _cqQe0IoriginalTree _cqQe1IoriginalTree
+                   {-# LINE 8395 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 8401 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 8407 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8413 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8419 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8425 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (from local)
+              _annOtpe =
+                  ({-# LINE 126 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _tpe
+                   {-# LINE 8431 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _cqQe0OassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 8437 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _cqQe0Ocat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8443 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _cqQe0OexpectedType =
+                  ({-# LINE 18 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIexpectedType
+                   {-# LINE 8449 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _cqQe0Oflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8455 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _cqQe0OimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8461 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _cqQe0OouterDownEnv =
+                  ({-# LINE 89 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIouterDownEnv
+                   {-# LINE 8467 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _cqQe1OassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 8473 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _cqQe1Ocat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8479 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _cqQe1OexpectedType =
+                  ({-# LINE 18 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIexpectedType
+                   {-# LINE 8485 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _cqQe1Oflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8491 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _cqQe1OimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8497 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _cqQe1OouterDownEnv =
+                  ({-# LINE 89 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIouterDownEnv
+                   {-# LINE 8503 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _cqQe0IannotatedTree,_cqQe0IoriginalTree,_cqQe0IupType) =
+                  cqQe0_ _cqQe0OassignmentCastContext _cqQe0Ocat _cqQe0OexpectedType _cqQe0Oflags _cqQe0OimCast _cqQe0OouterDownEnv
+              ( _cqQe1IannotatedTree,_cqQe1IoriginalTree,_cqQe1IupType) =
+                  cqQe1_ _cqQe1OassignmentCastContext _cqQe1Ocat _cqQe1OexpectedType _cqQe1Oflags _cqQe1OimCast _cqQe1OouterDownEnv
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupType)))
+_sem_QueryExpr_Values :: T_Annotation ->
+                        T_ScalarExprListList ->
+                        T_QueryExpr
+_sem_QueryExpr_Values ann_ qeValues_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIouterDownEnv ->
+         (let _qeValuesOdownEnv :: Environment
+              _tpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe [(Text,TypeExtra)])
+              _tpee :: (Either [TypeError] [(Text,TypeExtra)])
+              _qeValuesOexpectedCast :: Bool
+              _lhsOannotatedTree :: QueryExpr
+              _lhsOoriginalTree :: QueryExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _qeValuesOassignmentCastContext :: Bool
+              _qeValuesOcat :: Catalog
+              _qeValuesOexpectedType :: (Maybe [TypeExtra])
+              _qeValuesOflags :: TypeCheckFlags
+              _qeValuesOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _qeValuesIannotatedTree :: ScalarExprListList
+              _qeValuesIoriginalTree :: ScalarExprListList
+              _qeValuesIupType :: (Either [TypeError] [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 80, column 24)
+              _qeValuesOdownEnv =
+                  ({-# LINE 80 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 8547 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 142, column 9)
+              _tpe =
+                  ({-# LINE 142 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   liftM (mkTypeExtra . CompositeType) _tpee
+                   {-# LINE 8553 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 145, column 9)
+              _lhsOupType =
+                  ({-# LINE 145 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   either (const Nothing) Just _tpee
+                   {-# LINE 8559 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 153, column 9)
+              _tpee =
+                  ({-# LINE 153 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _qeValuesIupType
+                   {-# LINE 8565 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 154, column 9)
+              _qeValuesOexpectedCast =
+                  ({-# LINE 154 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   True
+                   {-# LINE 8571 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Values _annIannotatedTree _qeValuesIannotatedTree
+                   {-# LINE 8577 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Values _annIoriginalTree _qeValuesIoriginalTree
+                   {-# LINE 8583 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 8589 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 8595 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8601 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8607 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8613 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (from local)
+              _annOtpe =
+                  ({-# LINE 126 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _tpe
+                   {-# LINE 8619 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _qeValuesOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 8625 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _qeValuesOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8631 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _qeValuesOexpectedType =
+                  ({-# LINE 186 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIexpectedType
+                   {-# LINE 8637 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _qeValuesOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8643 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _qeValuesOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8649 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _qeValuesIannotatedTree,_qeValuesIoriginalTree,_qeValuesIupType) =
+                  qeValues_ _qeValuesOassignmentCastContext _qeValuesOcat _qeValuesOdownEnv _qeValuesOexpectedCast _qeValuesOexpectedType _qeValuesOflags _qeValuesOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupType)))
+_sem_QueryExpr_WithQueryExpr :: T_Annotation ->
+                               T_WithQueryList ->
+                               T_QueryExpr ->
+                               T_QueryExpr
+_sem_QueryExpr_WithQueryExpr ann_ withs_ withQe_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIouterDownEnv ->
+         (let _withQeOcat :: Catalog
+              _withsOcatExtIncomp :: (Either [TypeError] Catalog)
+              _lhsOannotatedTree :: QueryExpr
+              _tpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe [(Text,TypeExtra)])
+              _tpee :: (Either [TypeError] [(Text,TypeExtra)])
+              _lhsOoriginalTree :: QueryExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _withsOcat :: Catalog
+              _withsOflags :: TypeCheckFlags
+              _withsOimCast :: (Maybe TypeExtra)
+              _withQeOassignmentCastContext :: Bool
+              _withQeOexpectedType :: (Maybe [TypeExtra])
+              _withQeOflags :: TypeCheckFlags
+              _withQeOimCast :: (Maybe TypeExtra)
+              _withQeOouterDownEnv :: (Maybe Environment)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _withsIannotatedTree :: WithQueryList
+              _withsIcatExtComp :: (Either [TypeError] Catalog)
+              _withsIoriginalTree :: WithQueryList
+              _withQeIannotatedTree :: QueryExpr
+              _withQeIoriginalTree :: QueryExpr
+              _withQeIupType :: (Maybe [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 70, column 8)
+              _withQeOcat =
+                  ({-# LINE 70 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   case _withsIcatExtComp of
+                     Right catExtComp -> catExtComp
+                     Left _ -> _lhsIcat
+                   {-# LINE 8700 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 74, column 8)
+              _withsOcatExtIncomp =
+                  ({-# LINE 74 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   return _lhsIcat
+                   {-# LINE 8706 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 76, column 8)
+              _lhsOannotatedTree =
+                  ({-# LINE 76 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   case _withsIcatExtComp of
+                     Right _ -> WithQueryExpr (_annIannotatedTree) (_withsIannotatedTree) (_withQeIannotatedTree)
+                     Left tyErrs -> WithQueryExpr (emptyAnnotation { anType = Nothing, anErrs = tyErrs })
+                       (_withsIannotatedTree) (_withQeIannotatedTree)
+                   {-# LINE 8715 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 142, column 9)
+              _tpe =
+                  ({-# LINE 142 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   liftM (mkTypeExtra . CompositeType) _tpee
+                   {-# LINE 8721 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 145, column 9)
+              _lhsOupType =
+                  ({-# LINE 145 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   either (const Nothing) Just _tpee
+                   {-# LINE 8727 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 151, column 9)
+              _tpee =
+                  ({-# LINE 151 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   maybe (Left []) Right _withQeIupType
+                   {-# LINE 8733 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   WithQueryExpr _annIannotatedTree _withsIannotatedTree _withQeIannotatedTree
+                   {-# LINE 8739 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   WithQueryExpr _annIoriginalTree _withsIoriginalTree _withQeIoriginalTree
+                   {-# LINE 8745 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 8751 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8757 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8763 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8769 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (from local)
+              _annOtpe =
+                  ({-# LINE 126 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _tpe
+                   {-# LINE 8775 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _withsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8781 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _withsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8787 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _withsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8793 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _withQeOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 8799 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _withQeOexpectedType =
+                  ({-# LINE 18 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIexpectedType
+                   {-# LINE 8805 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _withQeOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8811 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _withQeOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 8817 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _withQeOouterDownEnv =
+                  ({-# LINE 89 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIouterDownEnv
+                   {-# LINE 8823 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _withsIannotatedTree,_withsIcatExtComp,_withsIoriginalTree) =
+                  withs_ _withsOcat _withsOcatExtIncomp _withsOflags _withsOimCast
+              ( _withQeIannotatedTree,_withQeIoriginalTree,_withQeIupType) =
+                  withQe_ _withQeOassignmentCastContext _withQeOcat _withQeOexpectedType _withQeOflags _withQeOimCast _withQeOouterDownEnv
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupType)))
+-- Root --------------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+      synthesized attributes:
+         annotatedTree        : Root 
+         originalTree         : Root 
+   alternatives:
+      alternative Root:
+         child statements     : StatementList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data Root = Root (StatementList)
+          deriving ( Show)
+-- cata
+_sem_Root :: Root ->
+            T_Root
+_sem_Root (Root _statements) =
+    (_sem_Root_Root (_sem_StatementList _statements))
+-- semantic domain
+type T_Root = Catalog ->
+              TypeCheckFlags ->
+              ( Root,Root)
+data Inh_Root = Inh_Root {_cat_Inh_Root :: Catalog,_flags_Inh_Root :: TypeCheckFlags}
+data Syn_Root = Syn_Root {_annotatedTree_Syn_Root :: Root,_originalTree_Syn_Root :: Root}
+_wrap_Root :: T_Root ->
+             Inh_Root ->
+             Syn_Root
+_wrap_Root sem (Inh_Root _lhsIcat _lhsIflags) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags
+     in  (Syn_Root _lhsOannotatedTree _lhsOoriginalTree))
+_sem_Root_Root :: T_StatementList ->
+                 T_Root
+_sem_Root_Root statements_ =
+    (\ _lhsIcat
+       _lhsIflags ->
+         (let _statementsOimCast :: (Maybe TypeExtra)
+              _lhsOannotatedTree :: Root
+              _lhsOoriginalTree :: Root
+              _statementsOcat :: Catalog
+              _statementsOflags :: TypeCheckFlags
+              _statementsIannotatedTree :: StatementList
+              _statementsIoriginalTree :: StatementList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag"(line 133, column 8)
+              _statementsOimCast =
+                  ({-# LINE 133 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Nothing
+                   {-# LINE 8883 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Root _statementsIannotatedTree
+                   {-# LINE 8889 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Root _statementsIoriginalTree
+                   {-# LINE 8895 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 8901 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 8907 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _statementsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 8913 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _statementsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 8919 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _statementsIannotatedTree,_statementsIoriginalTree) =
+                  statements_ _statementsOcat _statementsOflags _statementsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- RowConstraint -----------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : RowConstraint 
+         originalTree         : RowConstraint 
+   alternatives:
+      alternative NullConstraint:
+         child ann            : Annotation 
+         child name           : {String}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative NotNullConstraint:
+         child ann            : Annotation 
+         child name           : {String}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative IdentityConstraint:
+         child ann            : Annotation 
+         child name           : {String}
+         child seedAndInc     : {(Maybe (Integer,Integer))}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative RowCheckConstraint:
+         child ann            : Annotation 
+         child name           : {String}
+         child expr           : ScalarExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative RowUniqueConstraint:
+         child ann            : Annotation 
+         child name           : {String}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative RowPrimaryKeyConstraint:
+         child ann            : Annotation 
+         child name           : {String}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative RowReferenceConstraint:
+         child ann            : Annotation 
+         child name           : {String}
+         child table          : Name 
+         child att            : {Maybe NameComponent}
+         child onUpdate       : {Cascade}
+         child onDelete       : {Cascade}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data RowConstraint = NullConstraint (Annotation) (String)
+                   | NotNullConstraint (Annotation) (String)
+                   | IdentityConstraint (Annotation) (String) (((Maybe (Integer,Integer))))
+                   | RowCheckConstraint (Annotation) (String) (ScalarExpr)
+                   | RowUniqueConstraint (Annotation) (String)
+                   | RowPrimaryKeyConstraint (Annotation) (String)
+                   | RowReferenceConstraint (Annotation) (String) (Name) ((Maybe NameComponent)) (Cascade) (Cascade)
+                   deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_RowConstraint :: RowConstraint ->
+                     T_RowConstraint
+_sem_RowConstraint (NullConstraint _ann _name) =
+    (_sem_RowConstraint_NullConstraint (_sem_Annotation _ann) _name)
+_sem_RowConstraint (NotNullConstraint _ann _name) =
+    (_sem_RowConstraint_NotNullConstraint (_sem_Annotation _ann) _name)
+_sem_RowConstraint (IdentityConstraint _ann _name _seedAndInc) =
+    (_sem_RowConstraint_IdentityConstraint (_sem_Annotation _ann) _name _seedAndInc)
+_sem_RowConstraint (RowCheckConstraint _ann _name _expr) =
+    (_sem_RowConstraint_RowCheckConstraint (_sem_Annotation _ann) _name (_sem_ScalarExpr _expr))
+_sem_RowConstraint (RowUniqueConstraint _ann _name) =
+    (_sem_RowConstraint_RowUniqueConstraint (_sem_Annotation _ann) _name)
+_sem_RowConstraint (RowPrimaryKeyConstraint _ann _name) =
+    (_sem_RowConstraint_RowPrimaryKeyConstraint (_sem_Annotation _ann) _name)
+_sem_RowConstraint (RowReferenceConstraint _ann _name _table _att _onUpdate _onDelete) =
+    (_sem_RowConstraint_RowReferenceConstraint (_sem_Annotation _ann) _name (_sem_Name _table) _att _onUpdate _onDelete)
+-- semantic domain
+type T_RowConstraint = Catalog ->
+                       TypeCheckFlags ->
+                       (Maybe TypeExtra) ->
+                       ( RowConstraint,RowConstraint)
+data Inh_RowConstraint = Inh_RowConstraint {_cat_Inh_RowConstraint :: Catalog,_flags_Inh_RowConstraint :: TypeCheckFlags,_imCast_Inh_RowConstraint :: (Maybe TypeExtra)}
+data Syn_RowConstraint = Syn_RowConstraint {_annotatedTree_Syn_RowConstraint :: RowConstraint,_originalTree_Syn_RowConstraint :: RowConstraint}
+_wrap_RowConstraint :: T_RowConstraint ->
+                      Inh_RowConstraint ->
+                      Syn_RowConstraint
+_wrap_RowConstraint sem (Inh_RowConstraint _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_RowConstraint _lhsOannotatedTree _lhsOoriginalTree))
+_sem_RowConstraint_NullConstraint :: T_Annotation ->
+                                    String ->
+                                    T_RowConstraint
+_sem_RowConstraint_NullConstraint ann_ name_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: RowConstraint
+              _lhsOoriginalTree :: RowConstraint
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 83, column 36)
+              _annOtpe =
+                  ({-# LINE 83 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 9041 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   NullConstraint _annIannotatedTree name_
+                   {-# LINE 9047 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   NullConstraint _annIoriginalTree name_
+                   {-# LINE 9053 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 9059 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 9065 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 9071 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 9077 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 9083 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_RowConstraint_NotNullConstraint :: T_Annotation ->
+                                       String ->
+                                       T_RowConstraint
+_sem_RowConstraint_NotNullConstraint ann_ name_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: RowConstraint
+              _lhsOoriginalTree :: RowConstraint
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 82, column 39)
+              _annOtpe =
+                  ({-# LINE 82 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 9107 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   NotNullConstraint _annIannotatedTree name_
+                   {-# LINE 9113 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   NotNullConstraint _annIoriginalTree name_
+                   {-# LINE 9119 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 9125 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 9131 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 9137 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 9143 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 9149 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_RowConstraint_IdentityConstraint :: T_Annotation ->
+                                        String ->
+                                        ((Maybe (Integer,Integer))) ->
+                                        T_RowConstraint
+_sem_RowConstraint_IdentityConstraint ann_ name_ seedAndInc_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: RowConstraint
+              _lhsOoriginalTree :: RowConstraint
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 81, column 40)
+              _annOtpe =
+                  ({-# LINE 81 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 9174 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   IdentityConstraint _annIannotatedTree name_ seedAndInc_
+                   {-# LINE 9180 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   IdentityConstraint _annIoriginalTree name_ seedAndInc_
+                   {-# LINE 9186 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 9192 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 9198 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 9204 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 9210 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 9216 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_RowConstraint_RowCheckConstraint :: T_Annotation ->
+                                        String ->
+                                        T_ScalarExpr ->
+                                        T_RowConstraint
+_sem_RowConstraint_RowCheckConstraint ann_ name_ expr_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _exprOdownEnv :: Environment
+              _exprOexpectedCast :: Bool
+              _exprOexpectedType :: (Maybe TypeExtra)
+              _exprOodbcFunction :: Bool
+              _exprOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: RowConstraint
+              _lhsOoriginalTree :: RowConstraint
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _exprOcat :: Catalog
+              _exprOflags :: TypeCheckFlags
+              _exprOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exprIannotatedTree :: ScalarExpr
+              _exprIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exprIoriginalTree :: ScalarExpr
+              _exprIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 84, column 40)
+              _annOtpe =
+                  ({-# LINE 84 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 9253 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 85, column 40)
+              _exprOdownEnv =
+                  ({-# LINE 85 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 9259 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 86, column 40)
+              _exprOexpectedCast =
+                  ({-# LINE 86 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 9265 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 87, column 40)
+              _exprOexpectedType =
+                  ({-# LINE 87 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 9271 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 149, column 26)
+              _exprOodbcFunction =
+                  ({-# LINE 149 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 9277 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 816, column 40)
+              _exprOassignmentCastContext =
+                  ({-# LINE 816 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 9283 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   RowCheckConstraint _annIannotatedTree name_ _exprIannotatedTree
+                   {-# LINE 9289 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   RowCheckConstraint _annIoriginalTree name_ _exprIoriginalTree
+                   {-# LINE 9295 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 9301 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 9307 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 9313 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 9319 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 9325 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 9331 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 9337 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 9343 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exprIannotatedTree,_exprIcolExprs,_exprIoriginalTree,_exprIupType) =
+                  expr_ _exprOassignmentCastContext _exprOcat _exprOdownEnv _exprOexpectedCast _exprOexpectedType _exprOflags _exprOimCast _exprOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_RowConstraint_RowUniqueConstraint :: T_Annotation ->
+                                         String ->
+                                         T_RowConstraint
+_sem_RowConstraint_RowUniqueConstraint ann_ name_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: RowConstraint
+              _lhsOoriginalTree :: RowConstraint
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 91, column 41)
+              _annOtpe =
+                  ({-# LINE 91 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 9369 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   RowUniqueConstraint _annIannotatedTree name_
+                   {-# LINE 9375 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   RowUniqueConstraint _annIoriginalTree name_
+                   {-# LINE 9381 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 9387 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 9393 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 9399 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 9405 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 9411 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_RowConstraint_RowPrimaryKeyConstraint :: T_Annotation ->
+                                             String ->
+                                             T_RowConstraint
+_sem_RowConstraint_RowPrimaryKeyConstraint ann_ name_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: RowConstraint
+              _lhsOoriginalTree :: RowConstraint
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 88, column 45)
+              _annOtpe =
+                  ({-# LINE 88 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 9435 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   RowPrimaryKeyConstraint _annIannotatedTree name_
+                   {-# LINE 9441 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   RowPrimaryKeyConstraint _annIoriginalTree name_
+                   {-# LINE 9447 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 9453 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 9459 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 9465 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 9471 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 9477 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_RowConstraint_RowReferenceConstraint :: T_Annotation ->
+                                            String ->
+                                            T_Name ->
+                                            (Maybe NameComponent) ->
+                                            Cascade ->
+                                            Cascade ->
+                                            T_RowConstraint
+_sem_RowConstraint_RowReferenceConstraint ann_ name_ table_ att_ onUpdate_ onDelete_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _tableOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: RowConstraint
+              _lhsOoriginalTree :: RowConstraint
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _tableOcat :: Catalog
+              _tableOflags :: TypeCheckFlags
+              _tableOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _tableIannotatedTree :: Name
+              _tableIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 89, column 44)
+              _annOtpe =
+                  ({-# LINE 89 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 9511 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 90, column 44)
+              _tableOtpe =
+                  ({-# LINE 90 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 9517 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   RowReferenceConstraint _annIannotatedTree name_ _tableIannotatedTree att_ onUpdate_ onDelete_
+                   {-# LINE 9523 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   RowReferenceConstraint _annIoriginalTree name_ _tableIoriginalTree att_ onUpdate_ onDelete_
+                   {-# LINE 9529 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 9535 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 9541 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 9547 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 9553 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 9559 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 9565 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 9571 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 9577 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _tableIannotatedTree,_tableIoriginalTree) =
+                  table_ _tableOcat _tableOflags _tableOimCast _tableOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- RowConstraintList -------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : RowConstraintList 
+         originalTree         : RowConstraintList 
+   alternatives:
+      alternative Cons:
+         child hd             : RowConstraint 
+         child tl             : RowConstraintList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type RowConstraintList = [RowConstraint]
+-- cata
+_sem_RowConstraintList :: RowConstraintList ->
+                         T_RowConstraintList
+_sem_RowConstraintList list =
+    (Prelude.foldr _sem_RowConstraintList_Cons _sem_RowConstraintList_Nil (Prelude.map _sem_RowConstraint list))
+-- semantic domain
+type T_RowConstraintList = Catalog ->
+                           TypeCheckFlags ->
+                           (Maybe TypeExtra) ->
+                           ( RowConstraintList,RowConstraintList)
+data Inh_RowConstraintList = Inh_RowConstraintList {_cat_Inh_RowConstraintList :: Catalog,_flags_Inh_RowConstraintList :: TypeCheckFlags,_imCast_Inh_RowConstraintList :: (Maybe TypeExtra)}
+data Syn_RowConstraintList = Syn_RowConstraintList {_annotatedTree_Syn_RowConstraintList :: RowConstraintList,_originalTree_Syn_RowConstraintList :: RowConstraintList}
+_wrap_RowConstraintList :: T_RowConstraintList ->
+                          Inh_RowConstraintList ->
+                          Syn_RowConstraintList
+_wrap_RowConstraintList sem (Inh_RowConstraintList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_RowConstraintList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_RowConstraintList_Cons :: T_RowConstraint ->
+                              T_RowConstraintList ->
+                              T_RowConstraintList
+_sem_RowConstraintList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: RowConstraintList
+              _lhsOoriginalTree :: RowConstraintList
+              _hdOcat :: Catalog
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: RowConstraint
+              _hdIoriginalTree :: RowConstraint
+              _tlIannotatedTree :: RowConstraintList
+              _tlIoriginalTree :: RowConstraintList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 9648 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 9654 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 9660 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 9666 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 9672 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 9678 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 9684 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 9690 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 9696 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 9702 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree) =
+                  hd_ _hdOcat _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_RowConstraintList_Nil :: T_RowConstraintList
+_sem_RowConstraintList_Nil =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: RowConstraintList
+              _lhsOoriginalTree :: RowConstraintList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 9720 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 9726 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 9732 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 9738 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- ScalarExpr --------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         assignmentCastContext : Bool
+         cat                  : Catalog
+         downEnv              : Environment
+         expectedCast         : Bool
+         expectedType         : Maybe TypeExtra
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+         odbcFunction         : Bool
+      synthesized attributes:
+         annotatedTree        : ScalarExpr 
+         colExprs             : [(NameComponent,Maybe TypeExtra,ScalarExpr)]
+         originalTree         : ScalarExpr 
+         upType               : Maybe TypeExtra
+   alternatives:
+      alternative NumberLit:
+         child ann            : Annotation 
+         child d              : {String}
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local digChars    : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative StringLit:
+         child ann            : Annotation 
+         child value          : {String}
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative NullLit:
+         child ann            : Annotation 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative BooleanLit:
+         child ann            : Annotation 
+         child b              : {Bool}
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative TypedStringLit:
+         child ann            : Annotation 
+         child tn             : TypeName 
+         child value          : {String}
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative Interval:
+         child ann            : Annotation 
+         child value          : {String}
+         child field          : {IntervalField}
+         child prec           : {Maybe Int}
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative Identifier:
+         child ann            : Annotation 
+         child i              : Name 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local elkp        : _
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative Star:
+         child ann            : Annotation 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : {Either [TypeError] TypeExtra}
+            local starCS      : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative QStar:
+         child ann            : Annotation 
+         child q              : {NameComponent}
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : {Either [TypeError] TypeExtra}
+            local starCS      : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative PositionalArg:
+         child ann            : Annotation 
+         child p              : {Integer}
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative Placeholder:
+         child ann            : Annotation 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative PrefixOp:
+         child ann            : Annotation 
+         child opName         : Name 
+         child arg            : ScalarExpr 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : {Either [TypeError] TypeExtra}
+            local ttpe        : {Either [TypeError] ([TypeExtra],TypeExtra)}
+            local annotatedTree : _
+            local originalTree : _
+      alternative PostfixOp:
+         child ann            : Annotation 
+         child opName         : Name 
+         child arg            : ScalarExpr 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : {Either [TypeError] TypeExtra}
+            local ttpe        : {Either [TypeError] ([TypeExtra],TypeExtra)}
+            local annotatedTree : _
+            local originalTree : _
+      alternative BinaryOp:
+         child ann            : Annotation 
+         child opName         : Name 
+         child arg0           : ScalarExpr 
+         child arg1           : ScalarExpr 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : {Either [TypeError] TypeExtra}
+            local ttpe        : {Either [TypeError] ([TypeExtra],TypeExtra)}
+            local annotatedTree : _
+            local originalTree : _
+      alternative SpecialOp:
+         child ann            : Annotation 
+         child opName         : Name 
+         child args           : ScalarExprList 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : {Either [TypeError] TypeExtra}
+            local ttpe        : {Either [TypeError] ([TypeExtra],TypeExtra)}
+            local annotatedTree : _
+            local originalTree : _
+      alternative Extract:
+         child ann            : Annotation 
+         child field          : {ExtractField}
+         child e              : ScalarExpr 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative App:
+         child ann            : Annotation 
+         child funName        : Name 
+         child args           : ScalarExprList 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : {Either [TypeError] TypeExtra}
+            local funName     : _
+            local ttpe        : {Either [TypeError] ([TypeExtra],TypeExtra)}
+            local annotatedTree : _
+            local originalTree : _
+      alternative AggregateApp:
+         child ann            : Annotation 
+         child aggDistinct    : {Distinct}
+         child fn             : ScalarExpr 
+         child orderBy        : ScalarExprDirectionPairList 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative WindowApp:
+         child ann            : Annotation 
+         child fn             : ScalarExpr 
+         child partitionBy    : ScalarExprList 
+         child orderBy        : ScalarExprDirectionPairList 
+         child frm            : {Maybe FrameClause}
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative Cast:
+         child ann            : Annotation 
+         child expr           : ScalarExpr 
+         child tn             : TypeName 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative ImplicitCast:
+         child ann            : Annotation 
+         child expr           : ScalarExpr 
+         child te             : {TypeExtra}
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative Case:
+         child ann            : Annotation 
+         child cases          : CaseScalarExprListScalarExprPairList 
+         child els            : MaybeScalarExpr 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local whenTypes   : _
+            local thenTypes   : _
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative CaseSimple:
+         child ann            : Annotation 
+         child value          : ScalarExpr 
+         child cases          : CaseScalarExprListScalarExprPairList 
+         child els            : MaybeScalarExpr 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local whenTypes   : _
+            local thenTypes   : _
+            local whent       : _
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative Parens:
+         child ann            : Annotation 
+         child ex             : ScalarExpr 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative InPredicate:
+         child ann            : Annotation 
+         child expr           : ScalarExpr 
+         child i              : {Bool}
+         child list           : InList 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local rt          : {Either [TypeError] TypeExtra}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative Exists:
+         child ann            : Annotation 
+         child sel            : QueryExpr 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative ScalarSubQuery:
+         child ann            : Annotation 
+         child sel            : QueryExpr 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative LiftApp:
+         child ann            : Annotation 
+         child oper           : Name 
+         child flav           : {LiftFlavour}
+         child args           : ScalarExprList 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative OdbcLiteral:
+         child ann            : Annotation 
+         child olt            : {OdbcLiteralType}
+         child val            : {String}
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative OdbcFunc:
+         child ann            : Annotation 
+         child ex             : ScalarExpr 
+         visit 0:
+            local upType      : _
+            local dialectTypeName : {Text -> Either [TypeError] Text}
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative AntiScalarExpr:
+         child string         : {String}
+         visit 0:
+            local tpe         : _
+            local annotatedTree : _
+            local originalTree : _
+-}
+data ScalarExpr = NumberLit (Annotation) (String)
+                | StringLit (Annotation) (String)
+                | NullLit (Annotation)
+                | BooleanLit (Annotation) (Bool)
+                | TypedStringLit (Annotation) (TypeName) (String)
+                | Interval (Annotation) (String) (IntervalField) ((Maybe Int))
+                | Identifier (Annotation) (Name)
+                | Star (Annotation)
+                | QStar (Annotation) (NameComponent)
+                | PositionalArg (Annotation) (Integer)
+                | Placeholder (Annotation)
+                | PrefixOp (Annotation) (Name) (ScalarExpr)
+                | PostfixOp (Annotation) (Name) (ScalarExpr)
+                | BinaryOp (Annotation) (Name) (ScalarExpr) (ScalarExpr)
+                | SpecialOp (Annotation) (Name) (ScalarExprList)
+                | Extract (Annotation) (ExtractField) (ScalarExpr)
+                | App (Annotation) (Name) (ScalarExprList)
+                | AggregateApp (Annotation) (Distinct) (ScalarExpr) (ScalarExprDirectionPairList)
+                | WindowApp (Annotation) (ScalarExpr) (ScalarExprList) (ScalarExprDirectionPairList) ((Maybe FrameClause))
+                | Cast (Annotation) (ScalarExpr) (TypeName)
+                | ImplicitCast (Annotation) (ScalarExpr) (TypeExtra)
+                | Case (Annotation) (CaseScalarExprListScalarExprPairList) (MaybeScalarExpr)
+                | CaseSimple (Annotation) (ScalarExpr) (CaseScalarExprListScalarExprPairList) (MaybeScalarExpr)
+                | Parens (Annotation) (ScalarExpr)
+                | InPredicate (Annotation) (ScalarExpr) (Bool) (InList)
+                | Exists (Annotation) (QueryExpr)
+                | ScalarSubQuery (Annotation) (QueryExpr)
+                | LiftApp (Annotation) (Name) (LiftFlavour) (ScalarExprList)
+                | OdbcLiteral (Annotation) (OdbcLiteralType) (String)
+                | OdbcFunc (Annotation) (ScalarExpr)
+                | AntiScalarExpr (String)
+                deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_ScalarExpr :: ScalarExpr ->
+                  T_ScalarExpr
+_sem_ScalarExpr (NumberLit _ann _d) =
+    (_sem_ScalarExpr_NumberLit (_sem_Annotation _ann) _d)
+_sem_ScalarExpr (StringLit _ann _value) =
+    (_sem_ScalarExpr_StringLit (_sem_Annotation _ann) _value)
+_sem_ScalarExpr (NullLit _ann) =
+    (_sem_ScalarExpr_NullLit (_sem_Annotation _ann))
+_sem_ScalarExpr (BooleanLit _ann _b) =
+    (_sem_ScalarExpr_BooleanLit (_sem_Annotation _ann) _b)
+_sem_ScalarExpr (TypedStringLit _ann _tn _value) =
+    (_sem_ScalarExpr_TypedStringLit (_sem_Annotation _ann) (_sem_TypeName _tn) _value)
+_sem_ScalarExpr (Interval _ann _value _field _prec) =
+    (_sem_ScalarExpr_Interval (_sem_Annotation _ann) _value _field _prec)
+_sem_ScalarExpr (Identifier _ann _i) =
+    (_sem_ScalarExpr_Identifier (_sem_Annotation _ann) (_sem_Name _i))
+_sem_ScalarExpr (Star _ann) =
+    (_sem_ScalarExpr_Star (_sem_Annotation _ann))
+_sem_ScalarExpr (QStar _ann _q) =
+    (_sem_ScalarExpr_QStar (_sem_Annotation _ann) _q)
+_sem_ScalarExpr (PositionalArg _ann _p) =
+    (_sem_ScalarExpr_PositionalArg (_sem_Annotation _ann) _p)
+_sem_ScalarExpr (Placeholder _ann) =
+    (_sem_ScalarExpr_Placeholder (_sem_Annotation _ann))
+_sem_ScalarExpr (PrefixOp _ann _opName _arg) =
+    (_sem_ScalarExpr_PrefixOp (_sem_Annotation _ann) (_sem_Name _opName) (_sem_ScalarExpr _arg))
+_sem_ScalarExpr (PostfixOp _ann _opName _arg) =
+    (_sem_ScalarExpr_PostfixOp (_sem_Annotation _ann) (_sem_Name _opName) (_sem_ScalarExpr _arg))
+_sem_ScalarExpr (BinaryOp _ann _opName _arg0 _arg1) =
+    (_sem_ScalarExpr_BinaryOp (_sem_Annotation _ann) (_sem_Name _opName) (_sem_ScalarExpr _arg0) (_sem_ScalarExpr _arg1))
+_sem_ScalarExpr (SpecialOp _ann _opName _args) =
+    (_sem_ScalarExpr_SpecialOp (_sem_Annotation _ann) (_sem_Name _opName) (_sem_ScalarExprList _args))
+_sem_ScalarExpr (Extract _ann _field _e) =
+    (_sem_ScalarExpr_Extract (_sem_Annotation _ann) _field (_sem_ScalarExpr _e))
+_sem_ScalarExpr (App _ann _funName _args) =
+    (_sem_ScalarExpr_App (_sem_Annotation _ann) (_sem_Name _funName) (_sem_ScalarExprList _args))
+_sem_ScalarExpr (AggregateApp _ann _aggDistinct _fn _orderBy) =
+    (_sem_ScalarExpr_AggregateApp (_sem_Annotation _ann) _aggDistinct (_sem_ScalarExpr _fn) (_sem_ScalarExprDirectionPairList _orderBy))
+_sem_ScalarExpr (WindowApp _ann _fn _partitionBy _orderBy _frm) =
+    (_sem_ScalarExpr_WindowApp (_sem_Annotation _ann) (_sem_ScalarExpr _fn) (_sem_ScalarExprList _partitionBy) (_sem_ScalarExprDirectionPairList _orderBy) _frm)
+_sem_ScalarExpr (Cast _ann _expr _tn) =
+    (_sem_ScalarExpr_Cast (_sem_Annotation _ann) (_sem_ScalarExpr _expr) (_sem_TypeName _tn))
+_sem_ScalarExpr (ImplicitCast _ann _expr _te) =
+    (_sem_ScalarExpr_ImplicitCast (_sem_Annotation _ann) (_sem_ScalarExpr _expr) _te)
+_sem_ScalarExpr (Case _ann _cases _els) =
+    (_sem_ScalarExpr_Case (_sem_Annotation _ann) (_sem_CaseScalarExprListScalarExprPairList _cases) (_sem_MaybeScalarExpr _els))
+_sem_ScalarExpr (CaseSimple _ann _value _cases _els) =
+    (_sem_ScalarExpr_CaseSimple (_sem_Annotation _ann) (_sem_ScalarExpr _value) (_sem_CaseScalarExprListScalarExprPairList _cases) (_sem_MaybeScalarExpr _els))
+_sem_ScalarExpr (Parens _ann _ex) =
+    (_sem_ScalarExpr_Parens (_sem_Annotation _ann) (_sem_ScalarExpr _ex))
+_sem_ScalarExpr (InPredicate _ann _expr _i _list) =
+    (_sem_ScalarExpr_InPredicate (_sem_Annotation _ann) (_sem_ScalarExpr _expr) _i (_sem_InList _list))
+_sem_ScalarExpr (Exists _ann _sel) =
+    (_sem_ScalarExpr_Exists (_sem_Annotation _ann) (_sem_QueryExpr _sel))
+_sem_ScalarExpr (ScalarSubQuery _ann _sel) =
+    (_sem_ScalarExpr_ScalarSubQuery (_sem_Annotation _ann) (_sem_QueryExpr _sel))
+_sem_ScalarExpr (LiftApp _ann _oper _flav _args) =
+    (_sem_ScalarExpr_LiftApp (_sem_Annotation _ann) (_sem_Name _oper) _flav (_sem_ScalarExprList _args))
+_sem_ScalarExpr (OdbcLiteral _ann _olt _val) =
+    (_sem_ScalarExpr_OdbcLiteral (_sem_Annotation _ann) _olt _val)
+_sem_ScalarExpr (OdbcFunc _ann _ex) =
+    (_sem_ScalarExpr_OdbcFunc (_sem_Annotation _ann) (_sem_ScalarExpr _ex))
+_sem_ScalarExpr (AntiScalarExpr _string) =
+    (_sem_ScalarExpr_AntiScalarExpr _string)
+-- semantic domain
+type T_ScalarExpr = Bool ->
+                    Catalog ->
+                    Environment ->
+                    Bool ->
+                    (Maybe TypeExtra) ->
+                    TypeCheckFlags ->
+                    (Maybe TypeExtra) ->
+                    Bool ->
+                    ( ScalarExpr,([(NameComponent,Maybe TypeExtra,ScalarExpr)]),ScalarExpr,(Maybe TypeExtra))
+data Inh_ScalarExpr = Inh_ScalarExpr {_assignmentCastContext_Inh_ScalarExpr :: Bool,_cat_Inh_ScalarExpr :: Catalog,_downEnv_Inh_ScalarExpr :: Environment,_expectedCast_Inh_ScalarExpr :: Bool,_expectedType_Inh_ScalarExpr :: (Maybe TypeExtra),_flags_Inh_ScalarExpr :: TypeCheckFlags,_imCast_Inh_ScalarExpr :: (Maybe TypeExtra),_odbcFunction_Inh_ScalarExpr :: Bool}
+data Syn_ScalarExpr = Syn_ScalarExpr {_annotatedTree_Syn_ScalarExpr :: ScalarExpr,_colExprs_Syn_ScalarExpr :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)]),_originalTree_Syn_ScalarExpr :: ScalarExpr,_upType_Syn_ScalarExpr :: (Maybe TypeExtra)}
+_wrap_ScalarExpr :: T_ScalarExpr ->
+                   Inh_ScalarExpr ->
+                   Syn_ScalarExpr
+_wrap_ScalarExpr sem (Inh_ScalarExpr _lhsIassignmentCastContext _lhsIcat _lhsIdownEnv _lhsIexpectedCast _lhsIexpectedType _lhsIflags _lhsIimCast _lhsIodbcFunction) =
+    (let ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType) = sem _lhsIassignmentCastContext _lhsIcat _lhsIdownEnv _lhsIexpectedCast _lhsIexpectedType _lhsIflags _lhsIimCast _lhsIodbcFunction
+     in  (Syn_ScalarExpr _lhsOannotatedTree _lhsOcolExprs _lhsOoriginalTree _lhsOupType))
+_sem_ScalarExpr_NumberLit :: T_Annotation ->
+                            String ->
+                            T_ScalarExpr
+_sem_ScalarExpr_NumberLit ann_ d_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 10231 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 10237 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 10243 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 10249 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 10260 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 10266 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 249, column 9)
+              _tpe =
+                  ({-# LINE 249 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   if all (`elem` _digChars    ) d_
+                   then (mkTypeExtraNN . ScalarType) <$> classifyInteger (tcfDialect _lhsIflags) d_
+                   else (mkTypeExtraNN . ScalarType) <$> (_dialectTypeName     "numeric")
+                   {-# LINE 10274 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 253, column 9)
+              _digChars =
+                  ({-# LINE 253 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   concatMap show [(0::Int)..9]
+                   {-# LINE 10280 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   NumberLit _annIannotatedTree d_
+                   {-# LINE 10286 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   NumberLit _annIoriginalTree d_
+                   {-# LINE 10292 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 10298 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 10304 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 10310 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 10316 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_StringLit :: T_Annotation ->
+                            String ->
+                            T_ScalarExpr
+_sem_ScalarExpr_StringLit ann_ value_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 10363 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 10369 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 10375 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 10381 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 10392 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 10398 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 257, column 9)
+              _tpe =
+                  ({-# LINE 257 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Right $ (mkTypeExtraNN UnknownType) {tePrecision = Just $ length value_}
+                   {-# LINE 10404 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   StringLit _annIannotatedTree value_
+                   {-# LINE 10410 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   StringLit _annIoriginalTree value_
+                   {-# LINE 10416 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 10422 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 10428 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 10434 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 10440 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_NullLit :: T_Annotation ->
+                          T_ScalarExpr
+_sem_ScalarExpr_NullLit ann_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 10486 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 10492 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 10498 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 10504 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 10515 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 10521 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 260, column 10)
+              _tpe =
+                  ({-# LINE 260 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Right $ mkTypeExtra UnknownType
+                   {-# LINE 10527 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   NullLit _annIannotatedTree
+                   {-# LINE 10533 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   NullLit _annIoriginalTree
+                   {-# LINE 10539 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 10545 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 10551 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 10557 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 10563 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_BooleanLit :: T_Annotation ->
+                             Bool ->
+                             T_ScalarExpr
+_sem_ScalarExpr_BooleanLit ann_ b_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 10610 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 10616 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 10622 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 10628 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 10639 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 10645 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 240, column 9)
+              _tpe =
+                  ({-# LINE 240 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   fmap (mkTypeExtraNN . ScalarType) $ _dialectTypeName     "boolean"
+                   {-# LINE 10651 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   BooleanLit _annIannotatedTree b_
+                   {-# LINE 10657 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   BooleanLit _annIoriginalTree b_
+                   {-# LINE 10663 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 10669 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 10675 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 10681 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 10687 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_TypedStringLit :: T_Annotation ->
+                                 T_TypeName ->
+                                 String ->
+                                 T_ScalarExpr
+_sem_ScalarExpr_TypedStringLit ann_ tn_ value_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _tnOcat :: Catalog
+              _tnOflags :: TypeCheckFlags
+              _tnOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _tnIannotatedTree :: TypeName
+              _tnInamedType :: (Maybe TypeExtra)
+              _tnIoriginalTree :: TypeName
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 10741 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 10747 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 10753 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 10759 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 10770 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 10776 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 270, column 10)
+              _tpe =
+                  ({-# LINE 270 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right _tnInamedType
+                   {-# LINE 10782 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   TypedStringLit _annIannotatedTree _tnIannotatedTree value_
+                   {-# LINE 10788 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   TypedStringLit _annIoriginalTree _tnIoriginalTree value_
+                   {-# LINE 10794 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 10800 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 10806 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 10812 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 10818 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tnOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 10824 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tnOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 10830 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tnOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 10836 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _tnIannotatedTree,_tnInamedType,_tnIoriginalTree) =
+                  tn_ _tnOcat _tnOflags _tnOimCast
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_Interval :: T_Annotation ->
+                           String ->
+                           IntervalField ->
+                           (Maybe Int) ->
+                           T_ScalarExpr
+_sem_ScalarExpr_Interval ann_ value_ field_ prec_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 10887 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 10893 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 10899 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 10905 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 10916 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 10922 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 282, column 9)
+              _tpe =
+                  ({-# LINE 282 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Right $ mkTypeExtraNN $ ScalarType "interval"
+                   {-# LINE 10928 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Interval _annIannotatedTree value_ field_ prec_
+                   {-# LINE 10934 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Interval _annIoriginalTree value_ field_ prec_
+                   {-# LINE 10940 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 10946 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 10952 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 10958 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 10964 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_Identifier :: T_Annotation ->
+                             T_Name ->
+                             T_ScalarExpr
+_sem_ScalarExpr_Identifier ann_ i_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _lhsOannotatedTree :: ScalarExpr
+              _iOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _iOcat :: Catalog
+              _iOflags :: TypeCheckFlags
+              _iOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _iIannotatedTree :: Name
+              _iIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 11017 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 11023 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 11029 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 11035 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 11046 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 11052 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 325, column 10)
+              _elkp =
+                  ({-# LINE 325 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   E.envLookupIdentifier (nameComponents _iIoriginalTree) _lhsIdownEnv
+                   {-# LINE 11058 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 326, column 10)
+              _tpe =
+                  ({-# LINE 326 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   fmap snd _elkp
+                   {-# LINE 11064 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 328, column 10)
+              _lhsOannotatedTree =
+                  ({-# LINE 328 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _annotatedTree
+                   {-# LINE 11070 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 329, column 10)
+              _annotatedTree =
+                  ({-# LINE 329 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   let t = Identifier _annIannotatedTree _iIannotatedTree
+                   in fromMaybe t $ do
+                       case tcfAddQualifiers _lhsIflags of
+                         False -> Nothing
+                         True -> do
+                                ((q,i),_) <- either (const Nothing) Just _elkp
+                                if q /= ""
+                                  then
+                                       return $ Identifier _annIannotatedTree
+                                                  (Name emptyAnnotation [Nmc $ T.unpack q, Nmc $ T.unpack i])
+                                  else return t
+                   {-# LINE 11086 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 349, column 10)
+              _iOtpe =
+                  ({-# LINE 349 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Left []
+                   {-# LINE 11092 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Identifier _annIoriginalTree _iIoriginalTree
+                   {-# LINE 11098 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 11104 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 11110 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 11116 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _iOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 11122 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _iOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 11128 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _iOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 11134 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _iIannotatedTree,_iIoriginalTree) =
+                  i_ _iOcat _iOflags _iOimCast _iOtpe
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_Star :: T_Annotation ->
+                       T_ScalarExpr
+_sem_ScalarExpr_Star ann_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _tpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 11183 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 11189 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 11195 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 11201 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 11212 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 11218 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 713, column 9)
+              _tpe =
+                  ({-# LINE 713 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _originalTree of
+                     Star _ ->
+                       E.envExpandStar Nothing _lhsIdownEnv
+                       >>= _starCS
+                     QStar _ q -> do
+                       E.envExpandStar (Just q) _lhsIdownEnv
+                       >>= _starCS
+                     _ -> Left [InternalError "wrong ctor in sem rule for star, qstar in scalarexprs.ag"]
+                   {-# LINE 11231 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 722, column 9)
+              _starCS =
+                  ({-# LINE 722 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Right . mkTypeExtraNN . CompositeType . map (\((_q,n),t) -> (n,t))
+                   {-# LINE 11237 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Star _annIannotatedTree
+                   {-# LINE 11243 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Star _annIoriginalTree
+                   {-# LINE 11249 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 11255 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 11261 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 11267 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 11273 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_QStar :: T_Annotation ->
+                        NameComponent ->
+                        T_ScalarExpr
+_sem_ScalarExpr_QStar ann_ q_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _tpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 11321 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 11327 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 11333 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 11339 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 11350 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 11356 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 713, column 9)
+              _tpe =
+                  ({-# LINE 713 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _originalTree of
+                     Star _ ->
+                       E.envExpandStar Nothing _lhsIdownEnv
+                       >>= _starCS
+                     QStar _ q -> do
+                       E.envExpandStar (Just q) _lhsIdownEnv
+                       >>= _starCS
+                     _ -> Left [InternalError "wrong ctor in sem rule for star, qstar in scalarexprs.ag"]
+                   {-# LINE 11369 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 722, column 9)
+              _starCS =
+                  ({-# LINE 722 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Right . mkTypeExtraNN . CompositeType . map (\((_q,n),t) -> (n,t))
+                   {-# LINE 11375 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   QStar _annIannotatedTree q_
+                   {-# LINE 11381 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   QStar _annIoriginalTree q_
+                   {-# LINE 11387 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 11393 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 11399 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 11405 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 11411 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_PositionalArg :: T_Annotation ->
+                                Integer ->
+                                T_ScalarExpr
+_sem_ScalarExpr_PositionalArg ann_ p_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 11458 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 11464 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 11470 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 11476 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 11487 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 11493 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 734, column 9)
+              _tpe =
+                  ({-# LINE 734 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Left []
+                   {-# LINE 11499 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   PositionalArg _annIannotatedTree p_
+                   {-# LINE 11505 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   PositionalArg _annIoriginalTree p_
+                   {-# LINE 11511 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 11517 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 11523 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 11529 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 11535 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_Placeholder :: T_Annotation ->
+                              T_ScalarExpr
+_sem_ScalarExpr_Placeholder ann_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 11581 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 11587 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 11593 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 11599 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 11610 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 11616 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 300, column 10)
+              _tpe =
+                  ({-# LINE 300 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Right $ mkTypeExtraNN UnknownType
+                   {-# LINE 11622 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Placeholder _annIannotatedTree
+                   {-# LINE 11628 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Placeholder _annIoriginalTree
+                   {-# LINE 11634 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 11640 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 11646 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 11652 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 11658 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_PrefixOp :: T_Annotation ->
+                           T_Name ->
+                           T_ScalarExpr ->
+                           T_ScalarExpr
+_sem_ScalarExpr_PrefixOp ann_ opName_ arg_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _argOodbcFunction :: Bool
+              _opNameOtpe :: (Either [TypeError] TypeExtra)
+              _tpe :: (Either [TypeError] TypeExtra)
+              _ttpe :: (Either [TypeError] ([TypeExtra],TypeExtra))
+              _argOexpectedType :: (Maybe TypeExtra)
+              _argOexpectedCast :: Bool
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _opNameOcat :: Catalog
+              _opNameOflags :: TypeCheckFlags
+              _opNameOimCast :: (Maybe TypeExtra)
+              _argOassignmentCastContext :: Bool
+              _argOcat :: Catalog
+              _argOdownEnv :: Environment
+              _argOflags :: TypeCheckFlags
+              _argOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _opNameIannotatedTree :: Name
+              _opNameIoriginalTree :: Name
+              _argIannotatedTree :: ScalarExpr
+              _argIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _argIoriginalTree :: ScalarExpr
+              _argIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 11726 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 11732 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 11738 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 11744 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 11755 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 11761 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 175, column 26)
+              _argOodbcFunction =
+                  ({-# LINE 175 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 11767 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 210, column 9)
+              _opNameOtpe =
+                  ({-# LINE 210 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Left []
+                   {-# LINE 11773 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 364, column 10)
+              _tpe =
+                  ({-# LINE 364 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   fmap snd _ttpe
+                   {-# LINE 11779 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 433, column 10)
+              _ttpe =
+                  ({-# LINE 433 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   tcAppLike (tcfDialect _lhsIflags) _lhsIcat (nameComponents _opNameIoriginalTree) (getMaybeIntsFromLiterals [_argIoriginalTree]) [_argIupType]
+                   {-# LINE 11785 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 434, column 10)
+              _argOexpectedType =
+                  ({-# LINE 434 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _ttpe     of
+                     Right ([t],_) -> Just t
+                     _ -> Nothing
+                   {-# LINE 11793 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 456, column 9)
+              _argOexpectedCast =
+                  ({-# LINE 456 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 11799 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   PrefixOp _annIannotatedTree _opNameIannotatedTree _argIannotatedTree
+                   {-# LINE 11805 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   PrefixOp _annIoriginalTree _opNameIoriginalTree _argIoriginalTree
+                   {-# LINE 11811 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 11817 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 11823 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 11829 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 11835 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _opNameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 11841 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _opNameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 11847 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _opNameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 11853 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 11859 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 11865 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 11871 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 11877 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 11883 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _opNameIannotatedTree,_opNameIoriginalTree) =
+                  opName_ _opNameOcat _opNameOflags _opNameOimCast _opNameOtpe
+              ( _argIannotatedTree,_argIcolExprs,_argIoriginalTree,_argIupType) =
+                  arg_ _argOassignmentCastContext _argOcat _argOdownEnv _argOexpectedCast _argOexpectedType _argOflags _argOimCast _argOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_PostfixOp :: T_Annotation ->
+                            T_Name ->
+                            T_ScalarExpr ->
+                            T_ScalarExpr
+_sem_ScalarExpr_PostfixOp ann_ opName_ arg_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _argOodbcFunction :: Bool
+              _opNameOtpe :: (Either [TypeError] TypeExtra)
+              _tpe :: (Either [TypeError] TypeExtra)
+              _ttpe :: (Either [TypeError] ([TypeExtra],TypeExtra))
+              _argOexpectedType :: (Maybe TypeExtra)
+              _argOexpectedCast :: Bool
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _opNameOcat :: Catalog
+              _opNameOflags :: TypeCheckFlags
+              _opNameOimCast :: (Maybe TypeExtra)
+              _argOassignmentCastContext :: Bool
+              _argOcat :: Catalog
+              _argOdownEnv :: Environment
+              _argOflags :: TypeCheckFlags
+              _argOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _opNameIannotatedTree :: Name
+              _opNameIoriginalTree :: Name
+              _argIannotatedTree :: ScalarExpr
+              _argIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _argIoriginalTree :: ScalarExpr
+              _argIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 11955 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 11961 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 11967 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 11973 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 11984 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 11990 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 175, column 26)
+              _argOodbcFunction =
+                  ({-# LINE 175 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 11996 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 210, column 9)
+              _opNameOtpe =
+                  ({-# LINE 210 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Left []
+                   {-# LINE 12002 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 364, column 10)
+              _tpe =
+                  ({-# LINE 364 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   fmap snd _ttpe
+                   {-# LINE 12008 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 433, column 10)
+              _ttpe =
+                  ({-# LINE 433 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   tcAppLike (tcfDialect _lhsIflags) _lhsIcat (nameComponents _opNameIoriginalTree) (getMaybeIntsFromLiterals [_argIoriginalTree]) [_argIupType]
+                   {-# LINE 12014 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 434, column 10)
+              _argOexpectedType =
+                  ({-# LINE 434 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _ttpe     of
+                     Right ([t],_) -> Just t
+                     _ -> Nothing
+                   {-# LINE 12022 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 456, column 9)
+              _argOexpectedCast =
+                  ({-# LINE 456 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 12028 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   PostfixOp _annIannotatedTree _opNameIannotatedTree _argIannotatedTree
+                   {-# LINE 12034 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   PostfixOp _annIoriginalTree _opNameIoriginalTree _argIoriginalTree
+                   {-# LINE 12040 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 12046 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 12052 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 12058 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 12064 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _opNameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 12070 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _opNameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 12076 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _opNameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 12082 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 12088 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 12094 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 12100 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 12106 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 12112 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _opNameIannotatedTree,_opNameIoriginalTree) =
+                  opName_ _opNameOcat _opNameOflags _opNameOimCast _opNameOtpe
+              ( _argIannotatedTree,_argIcolExprs,_argIoriginalTree,_argIupType) =
+                  arg_ _argOassignmentCastContext _argOcat _argOdownEnv _argOexpectedCast _argOexpectedType _argOflags _argOimCast _argOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_BinaryOp :: T_Annotation ->
+                           T_Name ->
+                           T_ScalarExpr ->
+                           T_ScalarExpr ->
+                           T_ScalarExpr
+_sem_ScalarExpr_BinaryOp ann_ opName_ arg0_ arg1_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _arg0OodbcFunction :: Bool
+              _arg1OodbcFunction :: Bool
+              _opNameOtpe :: (Either [TypeError] TypeExtra)
+              _tpe :: (Either [TypeError] TypeExtra)
+              _ttpe :: (Either [TypeError] ([TypeExtra],TypeExtra))
+              _arg0OexpectedType :: (Maybe TypeExtra)
+              _arg1OexpectedType :: (Maybe TypeExtra)
+              _arg0OexpectedCast :: Bool
+              _arg1OexpectedCast :: Bool
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _opNameOcat :: Catalog
+              _opNameOflags :: TypeCheckFlags
+              _opNameOimCast :: (Maybe TypeExtra)
+              _arg0OassignmentCastContext :: Bool
+              _arg0Ocat :: Catalog
+              _arg0OdownEnv :: Environment
+              _arg0Oflags :: TypeCheckFlags
+              _arg0OimCast :: (Maybe TypeExtra)
+              _arg1OassignmentCastContext :: Bool
+              _arg1Ocat :: Catalog
+              _arg1OdownEnv :: Environment
+              _arg1Oflags :: TypeCheckFlags
+              _arg1OimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _opNameIannotatedTree :: Name
+              _opNameIoriginalTree :: Name
+              _arg0IannotatedTree :: ScalarExpr
+              _arg0IcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _arg0IoriginalTree :: ScalarExpr
+              _arg0IupType :: (Maybe TypeExtra)
+              _arg1IannotatedTree :: ScalarExpr
+              _arg1IcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _arg1IoriginalTree :: ScalarExpr
+              _arg1IupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 12197 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 12203 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 12209 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 12215 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 12226 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 12232 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 176, column 16)
+              _arg0OodbcFunction =
+                  ({-# LINE 176 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 12238 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 177, column 16)
+              _arg1OodbcFunction =
+                  ({-# LINE 177 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 12244 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 210, column 9)
+              _opNameOtpe =
+                  ({-# LINE 210 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Left []
+                   {-# LINE 12250 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 364, column 10)
+              _tpe =
+                  ({-# LINE 364 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   fmap snd _ttpe
+                   {-# LINE 12256 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 425, column 10)
+              _ttpe =
+                  ({-# LINE 425 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   tcAppLike (tcfDialect _lhsIflags)
+                             _lhsIcat (nameComponents _opNameIoriginalTree) (getMaybeIntsFromLiterals [_arg0IoriginalTree,_arg1IoriginalTree])
+                             [_arg0IupType,_arg1IupType]
+                   {-# LINE 12264 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 428, column 10)
+              (_arg0OexpectedType,_arg1OexpectedType) =
+                  ({-# LINE 428 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _ttpe     of
+                     Right ([t0,t1],_) -> (Just t0,Just t1)
+                     _ -> (Nothing,Nothing)
+                   {-# LINE 12272 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 458, column 9)
+              _arg0OexpectedCast =
+                  ({-# LINE 458 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 12278 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 459, column 9)
+              _arg1OexpectedCast =
+                  ({-# LINE 459 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 12284 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   BinaryOp _annIannotatedTree _opNameIannotatedTree _arg0IannotatedTree _arg1IannotatedTree
+                   {-# LINE 12290 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   BinaryOp _annIoriginalTree _opNameIoriginalTree _arg0IoriginalTree _arg1IoriginalTree
+                   {-# LINE 12296 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 12302 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 12308 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 12314 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 12320 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _opNameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 12326 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _opNameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 12332 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _opNameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 12338 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _arg0OassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 12344 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _arg0Ocat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 12350 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _arg0OdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 12356 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _arg0Oflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 12362 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _arg0OimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 12368 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _arg1OassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 12374 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _arg1Ocat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 12380 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _arg1OdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 12386 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _arg1Oflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 12392 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _arg1OimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 12398 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _opNameIannotatedTree,_opNameIoriginalTree) =
+                  opName_ _opNameOcat _opNameOflags _opNameOimCast _opNameOtpe
+              ( _arg0IannotatedTree,_arg0IcolExprs,_arg0IoriginalTree,_arg0IupType) =
+                  arg0_ _arg0OassignmentCastContext _arg0Ocat _arg0OdownEnv _arg0OexpectedCast _arg0OexpectedType _arg0Oflags _arg0OimCast _arg0OodbcFunction
+              ( _arg1IannotatedTree,_arg1IcolExprs,_arg1IoriginalTree,_arg1IupType) =
+                  arg1_ _arg1OassignmentCastContext _arg1Ocat _arg1OdownEnv _arg1OexpectedCast _arg1OexpectedType _arg1Oflags _arg1OimCast _arg1OodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_SpecialOp :: T_Annotation ->
+                            T_Name ->
+                            T_ScalarExprList ->
+                            T_ScalarExpr
+_sem_ScalarExpr_SpecialOp ann_ opName_ args_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _opNameOtpe :: (Either [TypeError] TypeExtra)
+              _tpe :: (Either [TypeError] TypeExtra)
+              _ttpe :: (Either [TypeError] ([TypeExtra],TypeExtra))
+              _argsOexpectedTypes :: ([TypeExtra])
+              _argsOexpectedCast :: Bool
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _opNameOcat :: Catalog
+              _opNameOflags :: TypeCheckFlags
+              _opNameOimCast :: (Maybe TypeExtra)
+              _argsOassignmentCastContext :: Bool
+              _argsOcat :: Catalog
+              _argsOdownEnv :: Environment
+              _argsOflags :: TypeCheckFlags
+              _argsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _opNameIannotatedTree :: Name
+              _opNameIoriginalTree :: Name
+              _argsIannotatedTree :: ScalarExprList
+              _argsIoriginalTree :: ScalarExprList
+              _argsIupTypes :: ([Maybe TypeExtra])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 12470 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 12476 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 12482 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 12488 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 12499 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 12505 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 210, column 9)
+              _opNameOtpe =
+                  ({-# LINE 210 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Left []
+                   {-# LINE 12511 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 364, column 10)
+              _tpe =
+                  ({-# LINE 364 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   fmap snd _ttpe
+                   {-# LINE 12517 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 439, column 10)
+              _ttpe =
+                  ({-# LINE 439 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   tcAppLike (tcfDialect _lhsIflags) _lhsIcat (nameComponents _opNameIoriginalTree) (getMaybeIntsFromLiterals _argsIoriginalTree) _argsIupTypes
+                   {-# LINE 12523 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 440, column 10)
+              _argsOexpectedTypes =
+                  ({-# LINE 440 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const []) id $ fmap fst _ttpe
+                   {-# LINE 12529 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 454, column 9)
+              _argsOexpectedCast =
+                  ({-# LINE 454 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 12535 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SpecialOp _annIannotatedTree _opNameIannotatedTree _argsIannotatedTree
+                   {-# LINE 12541 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SpecialOp _annIoriginalTree _opNameIoriginalTree _argsIoriginalTree
+                   {-# LINE 12547 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 12553 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 12559 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 12565 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 12571 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _opNameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 12577 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _opNameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 12583 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _opNameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 12589 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 12595 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 12601 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOdownEnv =
+                  ({-# LINE 189 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 12607 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 12613 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 12619 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _opNameIannotatedTree,_opNameIoriginalTree) =
+                  opName_ _opNameOcat _opNameOflags _opNameOimCast _opNameOtpe
+              ( _argsIannotatedTree,_argsIoriginalTree,_argsIupTypes) =
+                  args_ _argsOassignmentCastContext _argsOcat _argsOdownEnv _argsOexpectedCast _argsOexpectedTypes _argsOflags _argsOimCast
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_Extract :: T_Annotation ->
+                          ExtractField ->
+                          T_ScalarExpr ->
+                          T_ScalarExpr
+_sem_ScalarExpr_Extract ann_ field_ e_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _eOodbcFunction :: Bool
+              _eOexpectedType :: (Maybe TypeExtra)
+              _eOexpectedCast :: Bool
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _eOassignmentCastContext :: Bool
+              _eOcat :: Catalog
+              _eOdownEnv :: Environment
+              _eOflags :: TypeCheckFlags
+              _eOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _eIannotatedTree :: ScalarExpr
+              _eIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _eIoriginalTree :: ScalarExpr
+              _eIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 12683 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 12689 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 12695 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 12701 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 12712 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 12718 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 171, column 15)
+              _eOodbcFunction =
+                  ({-# LINE 171 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 12724 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 284, column 9)
+              _tpe =
+                  ({-# LINE 284 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   do
+                   x <- maybe (Left []) Right _eIupType
+                   if (teType x) `elem` (map ScalarType $ diDatetimeTypes $ tcfDialect _lhsIflags)
+                     then do
+                          i <- ScalarType <$> _dialectTypeName     "int"
+                          return $ TypeExtra i Nothing Nothing $ teNullable x
+                     else Left [NoMatchingOperator "extract" [teType x]]
+                   {-# LINE 12736 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 292, column 9)
+              _eOexpectedType =
+                  ({-# LINE 292 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   do
+                   x <- _eIupType
+                   either (const Nothing)
+                          (Just . TypeExtra (teType x) Nothing Nothing . teNullable)
+                          _tpe
+                   {-# LINE 12746 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 298, column 9)
+              _eOexpectedCast =
+                  ({-# LINE 298 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 12752 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Extract _annIannotatedTree field_ _eIannotatedTree
+                   {-# LINE 12758 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Extract _annIoriginalTree field_ _eIoriginalTree
+                   {-# LINE 12764 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 12770 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 12776 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 12782 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 12788 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _eOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 12794 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _eOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 12800 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _eOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 12806 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _eOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 12812 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _eOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 12818 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _eIannotatedTree,_eIcolExprs,_eIoriginalTree,_eIupType) =
+                  e_ _eOassignmentCastContext _eOcat _eOdownEnv _eOexpectedCast _eOexpectedType _eOflags _eOimCast _eOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_App :: T_Annotation ->
+                      T_Name ->
+                      T_ScalarExprList ->
+                      T_ScalarExpr
+_sem_ScalarExpr_App ann_ funName_ args_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _funNameOtpe :: (Either [TypeError] TypeExtra)
+              _tpe :: (Either [TypeError] TypeExtra)
+              _argsOexpectedTypes :: ([TypeExtra])
+              _ttpe :: (Either [TypeError] ([TypeExtra],TypeExtra))
+              _argsOexpectedCast :: Bool
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _funNameOcat :: Catalog
+              _funNameOflags :: TypeCheckFlags
+              _funNameOimCast :: (Maybe TypeExtra)
+              _argsOassignmentCastContext :: Bool
+              _argsOcat :: Catalog
+              _argsOdownEnv :: Environment
+              _argsOflags :: TypeCheckFlags
+              _argsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _funNameIannotatedTree :: Name
+              _funNameIoriginalTree :: Name
+              _argsIannotatedTree :: ScalarExprList
+              _argsIoriginalTree :: ScalarExprList
+              _argsIupTypes :: ([Maybe TypeExtra])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 12886 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 12892 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 12898 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 12904 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 12915 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 12921 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 208, column 9)
+              _funNameOtpe =
+                  ({-# LINE 208 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Left []
+                   {-# LINE 12927 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 364, column 10)
+              _tpe =
+                  ({-# LINE 364 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   fmap snd _ttpe
+                   {-# LINE 12933 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 366, column 10)
+              _argsOexpectedTypes =
+                  ({-# LINE 366 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const []) id $ fmap fst _ttpe
+                   {-# LINE 12939 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 380, column 10)
+              _funName =
+                  ({-# LINE 380 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   let y = if _lhsIodbcFunction
+                           then let f [] = []
+                                    f [Nmc x] = [Nmc $ "!odbc-" ++ x]
+                                    f [QNmc x] = [QNmc $ "!odbc-" ++ x]
+                                    f [x] = [x]
+                                    f (x:xs) = x:f xs
+                                in (\(Name a nms) -> Name a (f nms)) _funNameIoriginalTree
+                           else _funNameIoriginalTree
+                   in                    y
+                   {-# LINE 12953 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 403, column 10)
+              _ttpe =
+                  ({-# LINE 403 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _originalTree of
+                     (App _ (Name _ [Nmc "count"]) [Star _]) ->
+                         tcAppLike (tcfDialect _lhsIflags)
+                                   _lhsIcat (nameComponents _funName    )
+                                   (getMaybeIntsFromLiterals _argsIoriginalTree)
+                                   [Just $ mkTypeExtraNN UnknownType]
+                     (App _ (Name _ [Nmc n]) [_,Identifier _ (Name _ [Nmc tyi])])
+                         | _lhsIodbcFunction && map toLower n == "convert" -> do
+                         (ts,_r) <- do
+                                   t <- _dialectTypeName     "int"
+                                   tcAppLike (tcfDialect _lhsIflags)
+                                     _lhsIcat (nameComponents _funName    ) (getMaybeIntsFromLiterals _argsIoriginalTree)
+                                     [Just $ mkTypeExtraNN UnknownType, Just $ mkTypeExtraNN $ ScalarType t]
+                         r' <- maybe (Left [UnrecognisedIdentifier $ T.pack tyi]) (Right . mkTypeExtra)
+                                  $ lookup (map toLower tyi) odbcConvertTypes
+                         Right (ts, r')
+                     _ -> tcAppLike (tcfDialect _lhsIflags)
+                                    _lhsIcat (nameComponents _funName    ) (getMaybeIntsFromLiterals _argsIoriginalTree) _argsIupTypes
+                   {-# LINE 12976 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 454, column 9)
+              _argsOexpectedCast =
+                  ({-# LINE 454 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 12982 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   App _annIannotatedTree _funNameIannotatedTree _argsIannotatedTree
+                   {-# LINE 12988 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   App _annIoriginalTree _funNameIoriginalTree _argsIoriginalTree
+                   {-# LINE 12994 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 13000 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 13006 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 13012 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 13018 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _funNameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 13024 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _funNameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 13030 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _funNameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 13036 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 13042 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 13048 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOdownEnv =
+                  ({-# LINE 189 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 13054 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 13060 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 13066 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _funNameIannotatedTree,_funNameIoriginalTree) =
+                  funName_ _funNameOcat _funNameOflags _funNameOimCast _funNameOtpe
+              ( _argsIannotatedTree,_argsIoriginalTree,_argsIupTypes) =
+                  args_ _argsOassignmentCastContext _argsOcat _argsOdownEnv _argsOexpectedCast _argsOexpectedTypes _argsOflags _argsOimCast
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_AggregateApp :: T_Annotation ->
+                               Distinct ->
+                               T_ScalarExpr ->
+                               T_ScalarExprDirectionPairList ->
+                               T_ScalarExpr
+_sem_ScalarExpr_AggregateApp ann_ aggDistinct_ fn_ orderBy_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _fnOodbcFunction :: Bool
+              _fnOexpectedCast :: Bool
+              _fnOexpectedType :: (Maybe TypeExtra)
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _fnOassignmentCastContext :: Bool
+              _fnOcat :: Catalog
+              _fnOdownEnv :: Environment
+              _fnOflags :: TypeCheckFlags
+              _fnOimCast :: (Maybe TypeExtra)
+              _orderByOcat :: Catalog
+              _orderByOdownEnv :: Environment
+              _orderByOflags :: TypeCheckFlags
+              _orderByOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _fnIannotatedTree :: ScalarExpr
+              _fnIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _fnIoriginalTree :: ScalarExpr
+              _fnIupType :: (Maybe TypeExtra)
+              _orderByIannotatedTree :: ScalarExprDirectionPairList
+              _orderByIoriginalTree :: ScalarExprDirectionPairList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 13137 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 13143 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 13149 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 13155 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 13166 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 13172 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 178, column 20)
+              _fnOodbcFunction =
+                  ({-# LINE 178 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 13178 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 442, column 10)
+              _tpe =
+                  ({-# LINE 442 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _fnIoriginalTree of
+                     (App _ fnm@(Name _ [Nmc "count"]) [Star _]) ->
+                          fmap snd $ tcAppLike (tcfDialect _lhsIflags) _lhsIcat (nameComponents fnm) [] [Just $ mkTypeExtraNN UnknownType]
+                     _ -> maybe (Left []) Right _fnIupType
+                   {-# LINE 13187 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 461, column 9)
+              _fnOexpectedCast =
+                  ({-# LINE 461 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 13193 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 752, column 28)
+              _fnOexpectedType =
+                  ({-# LINE 752 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Nothing
+                   {-# LINE 13199 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AggregateApp _annIannotatedTree aggDistinct_ _fnIannotatedTree _orderByIannotatedTree
+                   {-# LINE 13205 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AggregateApp _annIoriginalTree aggDistinct_ _fnIoriginalTree _orderByIoriginalTree
+                   {-# LINE 13211 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 13217 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 13223 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 13229 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 13235 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 13241 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 13247 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 13253 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 13259 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 13265 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _orderByOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 13271 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _orderByOdownEnv =
+                  ({-# LINE 215 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 13277 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _orderByOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 13283 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _orderByOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 13289 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _fnIannotatedTree,_fnIcolExprs,_fnIoriginalTree,_fnIupType) =
+                  fn_ _fnOassignmentCastContext _fnOcat _fnOdownEnv _fnOexpectedCast _fnOexpectedType _fnOflags _fnOimCast _fnOodbcFunction
+              ( _orderByIannotatedTree,_orderByIoriginalTree) =
+                  orderBy_ _orderByOcat _orderByOdownEnv _orderByOflags _orderByOimCast
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_WindowApp :: T_Annotation ->
+                            T_ScalarExpr ->
+                            T_ScalarExprList ->
+                            T_ScalarExprDirectionPairList ->
+                            (Maybe FrameClause) ->
+                            T_ScalarExpr
+_sem_ScalarExpr_WindowApp ann_ fn_ partitionBy_ orderBy_ frm_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _fnOodbcFunction :: Bool
+              _fnOexpectedCast :: Bool
+              _partitionByOexpectedCast :: Bool
+              _fnOexpectedType :: (Maybe TypeExtra)
+              _partitionByOexpectedTypes :: ([TypeExtra])
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _fnOassignmentCastContext :: Bool
+              _fnOcat :: Catalog
+              _fnOdownEnv :: Environment
+              _fnOflags :: TypeCheckFlags
+              _fnOimCast :: (Maybe TypeExtra)
+              _partitionByOassignmentCastContext :: Bool
+              _partitionByOcat :: Catalog
+              _partitionByOdownEnv :: Environment
+              _partitionByOflags :: TypeCheckFlags
+              _partitionByOimCast :: (Maybe TypeExtra)
+              _orderByOcat :: Catalog
+              _orderByOdownEnv :: Environment
+              _orderByOflags :: TypeCheckFlags
+              _orderByOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _fnIannotatedTree :: ScalarExpr
+              _fnIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _fnIoriginalTree :: ScalarExpr
+              _fnIupType :: (Maybe TypeExtra)
+              _partitionByIannotatedTree :: ScalarExprList
+              _partitionByIoriginalTree :: ScalarExprList
+              _partitionByIupTypes :: ([Maybe TypeExtra])
+              _orderByIannotatedTree :: ScalarExprDirectionPairList
+              _orderByIoriginalTree :: ScalarExprDirectionPairList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 13371 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 13377 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 13383 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 13389 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 13400 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 13406 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 179, column 17)
+              _fnOodbcFunction =
+                  ({-# LINE 179 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 13412 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 448, column 10)
+              _tpe =
+                  ({-# LINE 448 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right _fnIupType
+                   {-# LINE 13418 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 461, column 9)
+              _fnOexpectedCast =
+                  ({-# LINE 461 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 13424 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 464, column 9)
+              _partitionByOexpectedCast =
+                  ({-# LINE 464 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 13430 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 752, column 28)
+              _fnOexpectedType =
+                  ({-# LINE 752 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Nothing
+                   {-# LINE 13436 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 774, column 15)
+              _partitionByOexpectedTypes =
+                  ({-# LINE 774 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   []
+                   {-# LINE 13442 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   WindowApp _annIannotatedTree _fnIannotatedTree _partitionByIannotatedTree _orderByIannotatedTree frm_
+                   {-# LINE 13448 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   WindowApp _annIoriginalTree _fnIoriginalTree _partitionByIoriginalTree _orderByIoriginalTree frm_
+                   {-# LINE 13454 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 13460 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 13466 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 13472 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 13478 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 13484 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 13490 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 13496 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 13502 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 13508 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _partitionByOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 13514 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _partitionByOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 13520 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _partitionByOdownEnv =
+                  ({-# LINE 189 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 13526 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _partitionByOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 13532 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _partitionByOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 13538 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _orderByOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 13544 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _orderByOdownEnv =
+                  ({-# LINE 215 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 13550 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _orderByOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 13556 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _orderByOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 13562 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _fnIannotatedTree,_fnIcolExprs,_fnIoriginalTree,_fnIupType) =
+                  fn_ _fnOassignmentCastContext _fnOcat _fnOdownEnv _fnOexpectedCast _fnOexpectedType _fnOflags _fnOimCast _fnOodbcFunction
+              ( _partitionByIannotatedTree,_partitionByIoriginalTree,_partitionByIupTypes) =
+                  partitionBy_ _partitionByOassignmentCastContext _partitionByOcat _partitionByOdownEnv _partitionByOexpectedCast _partitionByOexpectedTypes _partitionByOflags _partitionByOimCast
+              ( _orderByIannotatedTree,_orderByIoriginalTree) =
+                  orderBy_ _orderByOcat _orderByOdownEnv _orderByOflags _orderByOimCast
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_Cast :: T_Annotation ->
+                       T_ScalarExpr ->
+                       T_TypeName ->
+                       T_ScalarExpr
+_sem_ScalarExpr_Cast ann_ expr_ tn_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _exprOodbcFunction :: Bool
+              _exprOexpectedType :: (Maybe TypeExtra)
+              _exprOexpectedCast :: Bool
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _exprOassignmentCastContext :: Bool
+              _exprOcat :: Catalog
+              _exprOdownEnv :: Environment
+              _exprOflags :: TypeCheckFlags
+              _exprOimCast :: (Maybe TypeExtra)
+              _tnOcat :: Catalog
+              _tnOflags :: TypeCheckFlags
+              _tnOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exprIannotatedTree :: ScalarExpr
+              _exprIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exprIoriginalTree :: ScalarExpr
+              _exprIupType :: (Maybe TypeExtra)
+              _tnIannotatedTree :: TypeName
+              _tnInamedType :: (Maybe TypeExtra)
+              _tnIoriginalTree :: TypeName
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 13634 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 13640 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 13646 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 13652 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 13663 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 13669 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 172, column 12)
+              _exprOodbcFunction =
+                  ({-# LINE 172 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 13675 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 272, column 10)
+              _tpe =
+                  ({-# LINE 272 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   let nullability = fromMaybe False $ teNullable <$> _exprIupType
+                       setNullability te = te{teNullable = nullability}
+                   in maybe (Left []) (Right . setNullability) _tnInamedType
+                   {-# LINE 13683 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 276, column 10)
+              _exprOexpectedType =
+                  ({-# LINE 276 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Nothing
+                   {-# LINE 13689 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 277, column 10)
+              _exprOexpectedCast =
+                  ({-# LINE 277 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 13695 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Cast _annIannotatedTree _exprIannotatedTree _tnIannotatedTree
+                   {-# LINE 13701 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Cast _annIoriginalTree _exprIoriginalTree _tnIoriginalTree
+                   {-# LINE 13707 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 13713 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 13719 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 13725 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 13731 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 13737 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 13743 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 13749 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 13755 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 13761 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tnOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 13767 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tnOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 13773 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tnOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 13779 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exprIannotatedTree,_exprIcolExprs,_exprIoriginalTree,_exprIupType) =
+                  expr_ _exprOassignmentCastContext _exprOcat _exprOdownEnv _exprOexpectedCast _exprOexpectedType _exprOflags _exprOimCast _exprOodbcFunction
+              ( _tnIannotatedTree,_tnInamedType,_tnIoriginalTree) =
+                  tn_ _tnOcat _tnOflags _tnOimCast
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_ImplicitCast :: T_Annotation ->
+                               T_ScalarExpr ->
+                               TypeExtra ->
+                               T_ScalarExpr
+_sem_ScalarExpr_ImplicitCast ann_ expr_ te_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _exprOodbcFunction :: Bool
+              _exprOexpectedType :: (Maybe TypeExtra)
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _exprOassignmentCastContext :: Bool
+              _exprOcat :: Catalog
+              _exprOdownEnv :: Environment
+              _exprOexpectedCast :: Bool
+              _exprOflags :: TypeCheckFlags
+              _exprOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exprIannotatedTree :: ScalarExpr
+              _exprIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exprIoriginalTree :: ScalarExpr
+              _exprIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 13843 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 13849 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 13855 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 13861 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 13872 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 13878 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 173, column 20)
+              _exprOodbcFunction =
+                  ({-# LINE 173 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 13884 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 279, column 9)
+              _tpe =
+                  ({-# LINE 279 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Right te_
+                   {-# LINE 13890 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 280, column 9)
+              _exprOexpectedType =
+                  ({-# LINE 280 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Nothing
+                   {-# LINE 13896 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ImplicitCast _annIannotatedTree _exprIannotatedTree te_
+                   {-# LINE 13902 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ImplicitCast _annIoriginalTree _exprIoriginalTree te_
+                   {-# LINE 13908 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 13914 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 13920 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 13926 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 13932 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 13938 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 13944 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 13950 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOexpectedCast =
+                  ({-# LINE 111 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIexpectedCast
+                   {-# LINE 13956 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 13962 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 13968 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exprIannotatedTree,_exprIcolExprs,_exprIoriginalTree,_exprIupType) =
+                  expr_ _exprOassignmentCastContext _exprOcat _exprOdownEnv _exprOexpectedCast _exprOexpectedType _exprOflags _exprOimCast _exprOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_Case :: T_Annotation ->
+                       T_CaseScalarExprListScalarExprPairList ->
+                       T_MaybeScalarExpr ->
+                       T_ScalarExpr
+_sem_ScalarExpr_Case ann_ cases_ els_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _casesOwhenExpectedType :: (Maybe TypeExtra)
+              _casesOthenExpectedType :: (Maybe TypeExtra)
+              _elsOexpectedType :: (Maybe TypeExtra)
+              _elsOexpectedCast :: Bool
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _casesOcat :: Catalog
+              _casesOdownEnv :: Environment
+              _casesOflags :: TypeCheckFlags
+              _casesOimCast :: (Maybe TypeExtra)
+              _elsOassignmentCastContext :: Bool
+              _elsOcat :: Catalog
+              _elsOdownEnv :: Environment
+              _elsOflags :: TypeCheckFlags
+              _elsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _casesIannotatedTree :: CaseScalarExprListScalarExprPairList
+              _casesIoriginalTree :: CaseScalarExprListScalarExprPairList
+              _casesIthenTypes :: ([Maybe TypeExtra])
+              _casesIupTypes :: ([Maybe TypeExtra])
+              _casesIwhenTypes :: ([[Maybe TypeExtra]])
+              _elsIannotatedTree :: MaybeScalarExpr
+              _elsIoriginalTree :: MaybeScalarExpr
+              _elsIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 14039 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 14045 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 14051 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 14057 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 14068 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 14074 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 558, column 9)
+              _whenTypes =
+                  ({-# LINE 558 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _casesIwhenTypes
+                   {-# LINE 14080 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 559, column 9)
+              _thenTypes =
+                  ({-# LINE 559 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _casesIthenTypes ++ maybe [] ((:[]) . Just) _elsIupType
+                   {-# LINE 14086 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 561, column 9)
+              _tpe =
+                  ({-# LINE 561 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   do
+                   wt <- mapM (maybe (Left []) Right) $ concat _whenTypes
+                   bt <- ScalarType <$> _dialectTypeName     "boolean"
+                   when (any ((/= bt) . teType) wt)
+                       $ Left [WrongTypes bt $ map teType wt]
+                   tt <- mapM (maybe (Left []) Right) _thenTypes
+                   tse <- resolveResultSetTypeExtra _lhsIcat tt
+                   return $ if isNothing _elsIoriginalTree
+                            then tse{teNullable=True}
+                            else tse
+                   {-# LINE 14101 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 573, column 9)
+              _casesOwhenExpectedType =
+                  ({-# LINE 573 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   do
+                   ws <- sequence $ concat _whenTypes
+                   w <- either (const Nothing) Just $ resolveResultSetTypeExtra _lhsIcat ws
+                   bt <- ScalarType <$> either (const Nothing) Just (_dialectTypeName     "boolean")
+                   Just $ TypeExtra bt Nothing Nothing $ teNullable w
+                   {-# LINE 14111 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 579, column 9)
+              _casesOthenExpectedType =
+                  ({-# LINE 579 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 14117 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 580, column 9)
+              _elsOexpectedType =
+                  ({-# LINE 580 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 14123 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 581, column 9)
+              _elsOexpectedCast =
+                  ({-# LINE 581 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   True
+                   {-# LINE 14129 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Case _annIannotatedTree _casesIannotatedTree _elsIannotatedTree
+                   {-# LINE 14135 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Case _annIoriginalTree _casesIoriginalTree _elsIoriginalTree
+                   {-# LINE 14141 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 14147 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 14153 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 14159 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 14165 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 14171 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOdownEnv =
+                  ({-# LINE 553 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 14177 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 14183 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 14189 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 14195 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 14201 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 14207 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 14213 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 14219 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _casesIannotatedTree,_casesIoriginalTree,_casesIthenTypes,_casesIupTypes,_casesIwhenTypes) =
+                  cases_ _casesOcat _casesOdownEnv _casesOflags _casesOimCast _casesOthenExpectedType _casesOwhenExpectedType
+              ( _elsIannotatedTree,_elsIoriginalTree,_elsIupType) =
+                  els_ _elsOassignmentCastContext _elsOcat _elsOdownEnv _elsOexpectedCast _elsOexpectedType _elsOflags _elsOimCast
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_CaseSimple :: T_Annotation ->
+                             T_ScalarExpr ->
+                             T_CaseScalarExprListScalarExprPairList ->
+                             T_MaybeScalarExpr ->
+                             T_ScalarExpr
+_sem_ScalarExpr_CaseSimple ann_ value_ cases_ els_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _valueOodbcFunction :: Bool
+              _casesOwhenExpectedType :: (Maybe TypeExtra)
+              _valueOexpectedType :: (Maybe TypeExtra)
+              _valueOexpectedCast :: Bool
+              _casesOthenExpectedType :: (Maybe TypeExtra)
+              _elsOexpectedType :: (Maybe TypeExtra)
+              _elsOexpectedCast :: Bool
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _valueOassignmentCastContext :: Bool
+              _valueOcat :: Catalog
+              _valueOdownEnv :: Environment
+              _valueOflags :: TypeCheckFlags
+              _valueOimCast :: (Maybe TypeExtra)
+              _casesOcat :: Catalog
+              _casesOdownEnv :: Environment
+              _casesOflags :: TypeCheckFlags
+              _casesOimCast :: (Maybe TypeExtra)
+              _elsOassignmentCastContext :: Bool
+              _elsOcat :: Catalog
+              _elsOdownEnv :: Environment
+              _elsOflags :: TypeCheckFlags
+              _elsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _valueIannotatedTree :: ScalarExpr
+              _valueIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _valueIoriginalTree :: ScalarExpr
+              _valueIupType :: (Maybe TypeExtra)
+              _casesIannotatedTree :: CaseScalarExprListScalarExprPairList
+              _casesIoriginalTree :: CaseScalarExprListScalarExprPairList
+              _casesIthenTypes :: ([Maybe TypeExtra])
+              _casesIupTypes :: ([Maybe TypeExtra])
+              _casesIwhenTypes :: ([[Maybe TypeExtra]])
+              _elsIannotatedTree :: MaybeScalarExpr
+              _elsIoriginalTree :: MaybeScalarExpr
+              _elsIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 14305 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 14311 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 14317 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 14323 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 14334 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 14340 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 174, column 18)
+              _valueOodbcFunction =
+                  ({-# LINE 174 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 14346 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 558, column 9)
+              _whenTypes =
+                  ({-# LINE 558 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _casesIwhenTypes
+                   {-# LINE 14352 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 559, column 9)
+              _thenTypes =
+                  ({-# LINE 559 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _casesIthenTypes ++ maybe [] ((:[]) . Just) _elsIupType
+                   {-# LINE 14358 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 583, column 9)
+              _whent =
+                  ({-# LINE 583 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   do
+                   wt <- mapM (maybe (Left []) Right) $ concat _whenTypes
+                   vt <- maybe (Left []) Right _valueIupType
+                   resolveResultSetTypeExtra _lhsIcat (vt : wt)
+                   {-# LINE 14367 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 588, column 9)
+              _tpe =
+                  ({-# LINE 588 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   do
+                   _ <- _whent
+                   tt <- mapM (maybe (Left []) Right) _thenTypes
+                   resolveResultSetTypeExtra _lhsIcat tt
+                   {-# LINE 14376 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 593, column 9)
+              _casesOwhenExpectedType =
+                  ({-# LINE 593 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _whent
+                   {-# LINE 14382 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 594, column 9)
+              _valueOexpectedType =
+                  ({-# LINE 594 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _whent
+                   {-# LINE 14388 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 595, column 9)
+              _valueOexpectedCast =
+                  ({-# LINE 595 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 14394 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 596, column 9)
+              _casesOthenExpectedType =
+                  ({-# LINE 596 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 14400 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 597, column 9)
+              _elsOexpectedType =
+                  ({-# LINE 597 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 14406 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 598, column 9)
+              _elsOexpectedCast =
+                  ({-# LINE 598 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   True
+                   {-# LINE 14412 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CaseSimple _annIannotatedTree _valueIannotatedTree _casesIannotatedTree _elsIannotatedTree
+                   {-# LINE 14418 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CaseSimple _annIoriginalTree _valueIoriginalTree _casesIoriginalTree _elsIoriginalTree
+                   {-# LINE 14424 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 14430 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 14436 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 14442 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 14448 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _valueOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 14454 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _valueOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 14460 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _valueOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 14466 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _valueOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 14472 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _valueOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 14478 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 14484 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOdownEnv =
+                  ({-# LINE 553 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 14490 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 14496 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 14502 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 14508 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 14514 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 14520 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 14526 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 14532 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _valueIannotatedTree,_valueIcolExprs,_valueIoriginalTree,_valueIupType) =
+                  value_ _valueOassignmentCastContext _valueOcat _valueOdownEnv _valueOexpectedCast _valueOexpectedType _valueOflags _valueOimCast _valueOodbcFunction
+              ( _casesIannotatedTree,_casesIoriginalTree,_casesIthenTypes,_casesIupTypes,_casesIwhenTypes) =
+                  cases_ _casesOcat _casesOdownEnv _casesOflags _casesOimCast _casesOthenExpectedType _casesOwhenExpectedType
+              ( _elsIannotatedTree,_elsIoriginalTree,_elsIupType) =
+                  els_ _elsOassignmentCastContext _elsOcat _elsOdownEnv _elsOexpectedCast _elsOexpectedType _elsOflags _elsOimCast
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_Parens :: T_Annotation ->
+                         T_ScalarExpr ->
+                         T_ScalarExpr
+_sem_ScalarExpr_Parens ann_ ex_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _exOodbcFunction :: Bool
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _exOassignmentCastContext :: Bool
+              _exOcat :: Catalog
+              _exOdownEnv :: Environment
+              _exOexpectedCast :: Bool
+              _exOexpectedType :: (Maybe TypeExtra)
+              _exOflags :: TypeCheckFlags
+              _exOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exIannotatedTree :: ScalarExpr
+              _exIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exIoriginalTree :: ScalarExpr
+              _exIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 14597 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 14603 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 14609 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 14615 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 14626 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 14632 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 181, column 14)
+              _exOodbcFunction =
+                  ({-# LINE 181 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 14638 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 614, column 5)
+              _tpe =
+                  ({-# LINE 614 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right _exIupType
+                   {-# LINE 14644 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Parens _annIannotatedTree _exIannotatedTree
+                   {-# LINE 14650 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Parens _annIoriginalTree _exIoriginalTree
+                   {-# LINE 14656 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 14662 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 14668 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 14674 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 14680 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 14686 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 14692 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 14698 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOexpectedCast =
+                  ({-# LINE 111 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIexpectedCast
+                   {-# LINE 14704 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOexpectedType =
+                  ({-# LINE 110 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIexpectedType
+                   {-# LINE 14710 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 14716 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 14722 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exIannotatedTree,_exIcolExprs,_exIoriginalTree,_exIupType) =
+                  ex_ _exOassignmentCastContext _exOcat _exOdownEnv _exOexpectedCast _exOexpectedType _exOflags _exOimCast _exOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_InPredicate :: T_Annotation ->
+                              T_ScalarExpr ->
+                              Bool ->
+                              T_InList ->
+                              T_ScalarExpr
+_sem_ScalarExpr_InPredicate ann_ expr_ i_ list_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _exprOodbcFunction :: Bool
+              _rt :: (Either [TypeError] TypeExtra)
+              _listOexpectedType :: (Maybe TypeExtra)
+              _exprOexpectedType :: (Maybe TypeExtra)
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _exprOassignmentCastContext :: Bool
+              _exprOcat :: Catalog
+              _exprOdownEnv :: Environment
+              _exprOexpectedCast :: Bool
+              _exprOflags :: TypeCheckFlags
+              _exprOimCast :: (Maybe TypeExtra)
+              _listOcat :: Catalog
+              _listOdownEnv :: Environment
+              _listOexpectedCast :: Bool
+              _listOflags :: TypeCheckFlags
+              _listOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exprIannotatedTree :: ScalarExpr
+              _exprIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exprIoriginalTree :: ScalarExpr
+              _exprIupType :: (Maybe TypeExtra)
+              _listIannotatedTree :: InList
+              _listIlistType :: (Either [TypeError] TypeExtra)
+              _listIoriginalTree :: InList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 14795 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 14801 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 14807 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 14813 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 14824 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 14830 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 180, column 19)
+              _exprOodbcFunction =
+                  ({-# LINE 180 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 14836 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 668, column 9)
+              _rt =
+                  ({-# LINE 668 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   do
+                   lt <- _listIlistType
+                   expt <- maybe (Left []) Right _exprIupType
+                   resolveResultSetTypeExtra _lhsIcat [expt, lt]
+                   {-# LINE 14845 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 672, column 9)
+              _tpe =
+                  ({-# LINE 672 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   do
+                   r <- _rt
+                   bt <- ScalarType <$> _dialectTypeName     "boolean"
+                   return $ TypeExtra bt Nothing Nothing $ teNullable r
+                   {-# LINE 14854 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 676, column 9)
+              _listOexpectedType =
+                  ({-# LINE 676 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _rt
+                   {-# LINE 14860 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 677, column 9)
+              _exprOexpectedType =
+                  ({-# LINE 677 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _rt
+                   {-# LINE 14866 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   InPredicate _annIannotatedTree _exprIannotatedTree i_ _listIannotatedTree
+                   {-# LINE 14872 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   InPredicate _annIoriginalTree _exprIoriginalTree i_ _listIoriginalTree
+                   {-# LINE 14878 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 14884 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 14890 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 14896 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 14902 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 14908 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 14914 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 14920 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOexpectedCast =
+                  ({-# LINE 111 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIexpectedCast
+                   {-# LINE 14926 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 14932 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 14938 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _listOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 14944 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _listOdownEnv =
+                  ({-# LINE 215 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 14950 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _listOexpectedCast =
+                  ({-# LINE 661 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIexpectedCast
+                   {-# LINE 14956 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _listOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 14962 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _listOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 14968 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exprIannotatedTree,_exprIcolExprs,_exprIoriginalTree,_exprIupType) =
+                  expr_ _exprOassignmentCastContext _exprOcat _exprOdownEnv _exprOexpectedCast _exprOexpectedType _exprOflags _exprOimCast _exprOodbcFunction
+              ( _listIannotatedTree,_listIlistType,_listIoriginalTree) =
+                  list_ _listOcat _listOdownEnv _listOexpectedCast _listOexpectedType _listOflags _listOimCast
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_Exists :: T_Annotation ->
+                         T_QueryExpr ->
+                         T_ScalarExpr
+_sem_ScalarExpr_Exists ann_ sel_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _selOouterDownEnv :: (Maybe Environment)
+              _selOexpectedType :: (Maybe [TypeExtra])
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _selOassignmentCastContext :: Bool
+              _selOcat :: Catalog
+              _selOflags :: TypeCheckFlags
+              _selOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _selIannotatedTree :: QueryExpr
+              _selIoriginalTree :: QueryExpr
+              _selIupType :: (Maybe [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 15028 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 15034 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 15040 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 15046 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 15057 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 15063 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 627, column 9)
+              _tpe =
+                  ({-# LINE 627 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   (mkTypeExtraNN . ScalarType) <$> (_dialectTypeName     "boolean")
+                   {-# LINE 15069 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 649, column 9)
+              _selOouterDownEnv =
+                  ({-# LINE 649 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Just _lhsIdownEnv
+                   {-# LINE 15075 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 651, column 9)
+              _selOexpectedType =
+                  ({-# LINE 651 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   liftM (map snd) _selIupType
+                   {-# LINE 15081 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Exists _annIannotatedTree _selIannotatedTree
+                   {-# LINE 15087 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Exists _annIoriginalTree _selIoriginalTree
+                   {-# LINE 15093 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 15099 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 15105 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 15111 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 15117 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 15123 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 15129 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 15135 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 15141 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _selIannotatedTree,_selIoriginalTree,_selIupType) =
+                  sel_ _selOassignmentCastContext _selOcat _selOexpectedType _selOflags _selOimCast _selOouterDownEnv
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_ScalarSubQuery :: T_Annotation ->
+                                 T_QueryExpr ->
+                                 T_ScalarExpr
+_sem_ScalarExpr_ScalarSubQuery ann_ sel_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _selOouterDownEnv :: (Maybe Environment)
+              _selOexpectedType :: (Maybe [TypeExtra])
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _selOassignmentCastContext :: Bool
+              _selOcat :: Catalog
+              _selOflags :: TypeCheckFlags
+              _selOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _selIannotatedTree :: QueryExpr
+              _selIoriginalTree :: QueryExpr
+              _selIupType :: (Maybe [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 15199 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 15205 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 15211 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 15217 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 15228 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 15234 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 637, column 9)
+              _tpe =
+                  ({-# LINE 637 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   do
+                   selType <- maybe (Left []) Right _selIupType
+                   case length selType of
+                     0 -> Left [InternalError "no columns in scalar subquery?"]
+                     1 -> Right $ snd $ head selType
+                     _ -> Right $ mkTypeExtra $ AnonymousCompositeType
+                             $ map (teType . snd) selType
+                   {-# LINE 15246 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 647, column 9)
+              _selOouterDownEnv =
+                  ({-# LINE 647 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Just _lhsIdownEnv
+                   {-# LINE 15252 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 651, column 9)
+              _selOexpectedType =
+                  ({-# LINE 651 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   liftM (map snd) _selIupType
+                   {-# LINE 15258 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ScalarSubQuery _annIannotatedTree _selIannotatedTree
+                   {-# LINE 15264 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ScalarSubQuery _annIoriginalTree _selIoriginalTree
+                   {-# LINE 15270 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 15276 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 15282 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 15288 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 15294 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 15300 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 15306 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 15312 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 15318 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _selIannotatedTree,_selIoriginalTree,_selIupType) =
+                  sel_ _selOassignmentCastContext _selOcat _selOexpectedType _selOflags _selOimCast _selOouterDownEnv
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_LiftApp :: T_Annotation ->
+                          T_Name ->
+                          LiftFlavour ->
+                          T_ScalarExprList ->
+                          T_ScalarExpr
+_sem_ScalarExpr_LiftApp ann_ oper_ flav_ args_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _argsOexpectedCast :: Bool
+              _argsOexpectedTypes :: ([TypeExtra])
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _operOcat :: Catalog
+              _operOflags :: TypeCheckFlags
+              _operOimCast :: (Maybe TypeExtra)
+              _operOtpe :: (Either [TypeError] TypeExtra)
+              _argsOassignmentCastContext :: Bool
+              _argsOcat :: Catalog
+              _argsOdownEnv :: Environment
+              _argsOflags :: TypeCheckFlags
+              _argsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _operIannotatedTree :: Name
+              _operIoriginalTree :: Name
+              _argsIannotatedTree :: ScalarExprList
+              _argsIoriginalTree :: ScalarExprList
+              _argsIupTypes :: ([Maybe TypeExtra])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 15385 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 15391 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 15397 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 15403 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 15414 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 15420 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 454, column 9)
+              _argsOexpectedCast =
+                  ({-# LINE 454 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 15426 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 734, column 9)
+              _tpe =
+                  ({-# LINE 734 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Left []
+                   {-# LINE 15432 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 771, column 13)
+              _argsOexpectedTypes =
+                  ({-# LINE 771 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   []
+                   {-# LINE 15438 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   LiftApp _annIannotatedTree _operIannotatedTree flav_ _argsIannotatedTree
+                   {-# LINE 15444 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   LiftApp _annIoriginalTree _operIoriginalTree flav_ _argsIoriginalTree
+                   {-# LINE 15450 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 15456 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 15462 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 15468 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 15474 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _operOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 15480 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _operOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 15486 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _operOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 15492 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (from local)
+              _operOtpe =
+                  ({-# LINE 46 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   _tpe
+                   {-# LINE 15498 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 15504 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 15510 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOdownEnv =
+                  ({-# LINE 189 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 15516 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 15522 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 15528 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _operIannotatedTree,_operIoriginalTree) =
+                  oper_ _operOcat _operOflags _operOimCast _operOtpe
+              ( _argsIannotatedTree,_argsIoriginalTree,_argsIupTypes) =
+                  args_ _argsOassignmentCastContext _argsOcat _argsOdownEnv _argsOexpectedCast _argsOexpectedTypes _argsOflags _argsOimCast
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_OdbcLiteral :: T_Annotation ->
+                              OdbcLiteralType ->
+                              String ->
+                              T_ScalarExpr
+_sem_ScalarExpr_OdbcLiteral ann_ olt_ val_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 15580 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 15586 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 15592 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 15598 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 15609 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 15615 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 306, column 10)
+              _tpe =
+                  ({-# LINE 306 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case olt_ of
+                     OLDate -> (mkTypeExtra . ScalarType) <$> _dialectTypeName     "date"
+                     OLTime -> (mkTypeExtra . ScalarType) <$> _dialectTypeName     "time"
+                     OLTimestamp -> (mkTypeExtra . ScalarType) <$> _dialectTypeName     "timestamp"
+                   {-# LINE 15624 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   OdbcLiteral _annIannotatedTree olt_ val_
+                   {-# LINE 15630 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   OdbcLiteral _annIoriginalTree olt_ val_
+                   {-# LINE 15636 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 15642 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 15648 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 15654 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 15660 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_OdbcFunc :: T_Annotation ->
+                           T_ScalarExpr ->
+                           T_ScalarExpr
+_sem_ScalarExpr_OdbcFunc ann_ ex_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe TypeExtra)
+              _annOimCast :: (Maybe TypeExtra)
+              _dialectTypeName :: (Text -> Either [TypeError] Text)
+              _exOodbcFunction :: Bool
+              _exOcat :: Catalog
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _exOassignmentCastContext :: Bool
+              _exOdownEnv :: Environment
+              _exOexpectedCast :: Bool
+              _exOexpectedType :: (Maybe TypeExtra)
+              _exOflags :: TypeCheckFlags
+              _exOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exIannotatedTree :: ScalarExpr
+              _exIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exIoriginalTree :: ScalarExpr
+              _exIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 42, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   let a = _annIoriginalTree
+                       doStar is =
+                         map (\((q,n),t) ->
+                           let a' = a {anType = Just t}
+                           in (Nmc $ T.unpack n, Just t,
+                               Identifier a' $ Name a'
+                                             $ [Nmc q' | let q' = T.unpack q, not $ null q']
+                                               ++ [Nmc $ T.unpack n])
+                           ) is
+                   in case _originalTree of
+                       Star _ | Right is <- E.envExpandStar Nothing _lhsIdownEnv ->
+                          doStar is
+                       QStar _ q | Right is <- E.envExpandStar (Just q) _lhsIdownEnv ->
+                          doStar is
+                       _ ->
+                              [(columnName _originalTree,_upType,_annotatedTree)]
+                   {-# LINE 15719 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 35, column 9)
+              _annOtpe =
+                  ({-# LINE 35 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _tpe
+                   {-# LINE 15725 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 36, column 9)
+              _upType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 15731 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 37, column 9)
+              _lhsOupType =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _upType
+                   {-# LINE 15737 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 38, column 9)
+              _annOimCast =
+                  ({-# LINE 38 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _upType     of
+                      Nothing -> _lhsIexpectedType
+                      Just upType -> do
+                          expType <- _lhsIexpectedType
+                          guard $ needsImplicitCast _lhsIexpectedCast upType expType
+                          return $ implicitCastType _lhsIexpectedCast upType expType
+                   {-# LINE 15748 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 45, column 9)
+              _dialectTypeName =
+                  ({-# LINE 45 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   maybe (Left []) Right . ansiTypeNameToDialect (tcfDialect _lhsIflags)
+                   {-# LINE 15754 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 182, column 16)
+              _exOodbcFunction =
+                  ({-# LINE 182 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   True
+                   {-# LINE 15760 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 312, column 10)
+              _exOcat =
+                  ({-# LINE 312 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   id _lhsIcat
+                   {-# LINE 15766 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 313, column 10)
+              _tpe =
+                  ({-# LINE 313 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _exIoriginalTree of
+                     Extract {} -> maybe (Left []) Right _exIupType
+                     App {} -> maybe (Left []) Right _exIupType
+                     _ -> Left [OdbcFuncBadContent]
+                   {-# LINE 15775 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   OdbcFunc _annIannotatedTree _exIannotatedTree
+                   {-# LINE 15781 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   OdbcFunc _annIoriginalTree _exIoriginalTree
+                   {-# LINE 15787 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 15793 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 15799 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 15805 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 15811 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 15817 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 15823 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOexpectedCast =
+                  ({-# LINE 111 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIexpectedCast
+                   {-# LINE 15829 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOexpectedType =
+                  ({-# LINE 110 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIexpectedType
+                   {-# LINE 15835 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 15841 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 15847 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exIannotatedTree,_exIcolExprs,_exIoriginalTree,_exIupType) =
+                  ex_ _exOassignmentCastContext _exOcat _exOdownEnv _exOexpectedCast _exOexpectedType _exOflags _exOimCast _exOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExpr_AntiScalarExpr :: String ->
+                                 T_ScalarExpr
+_sem_ScalarExpr_AntiScalarExpr string_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast
+       _lhsIodbcFunction ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _lhsOupType :: (Maybe TypeExtra)
+              _lhsOannotatedTree :: ScalarExpr
+              _lhsOoriginalTree :: ScalarExpr
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 232, column 21)
+              _lhsOcolExprs =
+                  ({-# LINE 232 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   [(Nmc "?anti?",Nothing,_originalTree)]
+                   {-# LINE 15873 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 102, column 9)
+              _lhsOupType =
+                  ({-# LINE 102 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 15879 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 734, column 9)
+              _tpe =
+                  ({-# LINE 734 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Left []
+                   {-# LINE 15885 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AntiScalarExpr string_
+                   {-# LINE 15891 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AntiScalarExpr string_
+                   {-# LINE 15897 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 15903 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 15909 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupType)))
+-- ScalarExprDirectionPair -------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         downEnv              : Environment
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : ScalarExprDirectionPair 
+         originalTree         : ScalarExprDirectionPair 
+   alternatives:
+      alternative Tuple:
+         child x1             : ScalarExpr 
+         child x2             : {Direction}
+         child x3             : {NullsOrder}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type ScalarExprDirectionPair = ( ScalarExpr,(Direction),(NullsOrder))
+-- cata
+_sem_ScalarExprDirectionPair :: ScalarExprDirectionPair ->
+                               T_ScalarExprDirectionPair
+_sem_ScalarExprDirectionPair ( x1,x2,x3) =
+    (_sem_ScalarExprDirectionPair_Tuple (_sem_ScalarExpr x1) x2 x3)
+-- semantic domain
+type T_ScalarExprDirectionPair = Catalog ->
+                                 Environment ->
+                                 TypeCheckFlags ->
+                                 (Maybe TypeExtra) ->
+                                 ( ScalarExprDirectionPair,ScalarExprDirectionPair)
+data Inh_ScalarExprDirectionPair = Inh_ScalarExprDirectionPair {_cat_Inh_ScalarExprDirectionPair :: Catalog,_downEnv_Inh_ScalarExprDirectionPair :: Environment,_flags_Inh_ScalarExprDirectionPair :: TypeCheckFlags,_imCast_Inh_ScalarExprDirectionPair :: (Maybe TypeExtra)}
+data Syn_ScalarExprDirectionPair = Syn_ScalarExprDirectionPair {_annotatedTree_Syn_ScalarExprDirectionPair :: ScalarExprDirectionPair,_originalTree_Syn_ScalarExprDirectionPair :: ScalarExprDirectionPair}
+_wrap_ScalarExprDirectionPair :: T_ScalarExprDirectionPair ->
+                                Inh_ScalarExprDirectionPair ->
+                                Syn_ScalarExprDirectionPair
+_wrap_ScalarExprDirectionPair sem (Inh_ScalarExprDirectionPair _lhsIcat _lhsIdownEnv _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIdownEnv _lhsIflags _lhsIimCast
+     in  (Syn_ScalarExprDirectionPair _lhsOannotatedTree _lhsOoriginalTree))
+_sem_ScalarExprDirectionPair_Tuple :: T_ScalarExpr ->
+                                     Direction ->
+                                     NullsOrder ->
+                                     T_ScalarExprDirectionPair
+_sem_ScalarExprDirectionPair_Tuple x1_ x2_ x3_ =
+    (\ _lhsIcat
+       _lhsIdownEnv
+       _lhsIflags
+       _lhsIimCast ->
+         (let _x1OexpectedCast :: Bool
+              _x1OodbcFunction :: Bool
+              _x1OexpectedType :: (Maybe TypeExtra)
+              _x1OassignmentCastContext :: Bool
+              _lhsOannotatedTree :: ScalarExprDirectionPair
+              _lhsOoriginalTree :: ScalarExprDirectionPair
+              _x1Ocat :: Catalog
+              _x1OdownEnv :: Environment
+              _x1Oflags :: TypeCheckFlags
+              _x1OimCast :: (Maybe TypeExtra)
+              _x1IannotatedTree :: ScalarExpr
+              _x1IcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _x1IoriginalTree :: ScalarExpr
+              _x1IupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 92, column 37)
+              _x1OexpectedCast =
+                  ({-# LINE 92 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 15979 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 152, column 13)
+              _x1OodbcFunction =
+                  ({-# LINE 152 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 15985 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 757, column 11)
+              _x1OexpectedType =
+                  ({-# LINE 757 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Nothing
+                   {-# LINE 15991 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 817, column 37)
+              _x1OassignmentCastContext =
+                  ({-# LINE 817 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 15997 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (_x1IannotatedTree,x2_,x3_)
+                   {-# LINE 16003 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (_x1IoriginalTree,x2_,x3_)
+                   {-# LINE 16009 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 16015 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 16021 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1Ocat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 16027 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1OdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 16033 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1Oflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 16039 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1OimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 16045 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _x1IannotatedTree,_x1IcolExprs,_x1IoriginalTree,_x1IupType) =
+                  x1_ _x1OassignmentCastContext _x1Ocat _x1OdownEnv _x1OexpectedCast _x1OexpectedType _x1Oflags _x1OimCast _x1OodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- ScalarExprDirectionPairList ---------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         downEnv              : Environment
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : ScalarExprDirectionPairList 
+         originalTree         : ScalarExprDirectionPairList 
+   alternatives:
+      alternative Cons:
+         child hd             : ScalarExprDirectionPair 
+         child tl             : ScalarExprDirectionPairList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type ScalarExprDirectionPairList = [ScalarExprDirectionPair]
+-- cata
+_sem_ScalarExprDirectionPairList :: ScalarExprDirectionPairList ->
+                                   T_ScalarExprDirectionPairList
+_sem_ScalarExprDirectionPairList list =
+    (Prelude.foldr _sem_ScalarExprDirectionPairList_Cons _sem_ScalarExprDirectionPairList_Nil (Prelude.map _sem_ScalarExprDirectionPair list))
+-- semantic domain
+type T_ScalarExprDirectionPairList = Catalog ->
+                                     Environment ->
+                                     TypeCheckFlags ->
+                                     (Maybe TypeExtra) ->
+                                     ( ScalarExprDirectionPairList,ScalarExprDirectionPairList)
+data Inh_ScalarExprDirectionPairList = Inh_ScalarExprDirectionPairList {_cat_Inh_ScalarExprDirectionPairList :: Catalog,_downEnv_Inh_ScalarExprDirectionPairList :: Environment,_flags_Inh_ScalarExprDirectionPairList :: TypeCheckFlags,_imCast_Inh_ScalarExprDirectionPairList :: (Maybe TypeExtra)}
+data Syn_ScalarExprDirectionPairList = Syn_ScalarExprDirectionPairList {_annotatedTree_Syn_ScalarExprDirectionPairList :: ScalarExprDirectionPairList,_originalTree_Syn_ScalarExprDirectionPairList :: ScalarExprDirectionPairList}
+_wrap_ScalarExprDirectionPairList :: T_ScalarExprDirectionPairList ->
+                                    Inh_ScalarExprDirectionPairList ->
+                                    Syn_ScalarExprDirectionPairList
+_wrap_ScalarExprDirectionPairList sem (Inh_ScalarExprDirectionPairList _lhsIcat _lhsIdownEnv _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIdownEnv _lhsIflags _lhsIimCast
+     in  (Syn_ScalarExprDirectionPairList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_ScalarExprDirectionPairList_Cons :: T_ScalarExprDirectionPair ->
+                                        T_ScalarExprDirectionPairList ->
+                                        T_ScalarExprDirectionPairList
+_sem_ScalarExprDirectionPairList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIdownEnv
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: ScalarExprDirectionPairList
+              _lhsOoriginalTree :: ScalarExprDirectionPairList
+              _hdOcat :: Catalog
+              _hdOdownEnv :: Environment
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOdownEnv :: Environment
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: ScalarExprDirectionPair
+              _hdIoriginalTree :: ScalarExprDirectionPair
+              _tlIannotatedTree :: ScalarExprDirectionPairList
+              _tlIoriginalTree :: ScalarExprDirectionPairList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 16119 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 16125 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 16131 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 16137 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 16143 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOdownEnv =
+                  ({-# LINE 215 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 16149 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 16155 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 16161 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 16167 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOdownEnv =
+                  ({-# LINE 215 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 16173 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 16179 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 16185 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree) =
+                  hd_ _hdOcat _hdOdownEnv _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOdownEnv _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_ScalarExprDirectionPairList_Nil :: T_ScalarExprDirectionPairList
+_sem_ScalarExprDirectionPairList_Nil =
+    (\ _lhsIcat
+       _lhsIdownEnv
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: ScalarExprDirectionPairList
+              _lhsOoriginalTree :: ScalarExprDirectionPairList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 16204 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 16210 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 16216 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 16222 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- ScalarExprList ----------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         assignmentCastContext : Bool
+         cat                  : Catalog
+         downEnv              : Environment
+         expectedCast         : Bool
+         expectedTypes        : [TypeExtra]
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : ScalarExprList 
+         originalTree         : ScalarExprList 
+         upTypes              : [Maybe TypeExtra]
+   alternatives:
+      alternative Cons:
+         child hd             : ScalarExpr 
+         child tl             : ScalarExprList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type ScalarExprList = [ScalarExpr]
+-- cata
+_sem_ScalarExprList :: ScalarExprList ->
+                      T_ScalarExprList
+_sem_ScalarExprList list =
+    (Prelude.foldr _sem_ScalarExprList_Cons _sem_ScalarExprList_Nil (Prelude.map _sem_ScalarExpr list))
+-- semantic domain
+type T_ScalarExprList = Bool ->
+                        Catalog ->
+                        Environment ->
+                        Bool ->
+                        ([TypeExtra]) ->
+                        TypeCheckFlags ->
+                        (Maybe TypeExtra) ->
+                        ( ScalarExprList,ScalarExprList,([Maybe TypeExtra]))
+data Inh_ScalarExprList = Inh_ScalarExprList {_assignmentCastContext_Inh_ScalarExprList :: Bool,_cat_Inh_ScalarExprList :: Catalog,_downEnv_Inh_ScalarExprList :: Environment,_expectedCast_Inh_ScalarExprList :: Bool,_expectedTypes_Inh_ScalarExprList :: ([TypeExtra]),_flags_Inh_ScalarExprList :: TypeCheckFlags,_imCast_Inh_ScalarExprList :: (Maybe TypeExtra)}
+data Syn_ScalarExprList = Syn_ScalarExprList {_annotatedTree_Syn_ScalarExprList :: ScalarExprList,_originalTree_Syn_ScalarExprList :: ScalarExprList,_upTypes_Syn_ScalarExprList :: ([Maybe TypeExtra])}
+_wrap_ScalarExprList :: T_ScalarExprList ->
+                       Inh_ScalarExprList ->
+                       Syn_ScalarExprList
+_wrap_ScalarExprList sem (Inh_ScalarExprList _lhsIassignmentCastContext _lhsIcat _lhsIdownEnv _lhsIexpectedCast _lhsIexpectedTypes _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupTypes) = sem _lhsIassignmentCastContext _lhsIcat _lhsIdownEnv _lhsIexpectedCast _lhsIexpectedTypes _lhsIflags _lhsIimCast
+     in  (Syn_ScalarExprList _lhsOannotatedTree _lhsOoriginalTree _lhsOupTypes))
+_sem_ScalarExprList_Cons :: T_ScalarExpr ->
+                           T_ScalarExprList ->
+                           T_ScalarExprList
+_sem_ScalarExprList_Cons hd_ tl_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedTypes
+       _lhsIflags
+       _lhsIimCast ->
+         (let _hdOodbcFunction :: Bool
+              _lhsOupTypes :: ([Maybe TypeExtra])
+              _hdOexpectedType :: (Maybe TypeExtra)
+              _tlOexpectedTypes :: ([TypeExtra])
+              _hdOexpectedCast :: Bool
+              _lhsOannotatedTree :: ScalarExprList
+              _lhsOoriginalTree :: ScalarExprList
+              _hdOassignmentCastContext :: Bool
+              _hdOcat :: Catalog
+              _hdOdownEnv :: Environment
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOassignmentCastContext :: Bool
+              _tlOcat :: Catalog
+              _tlOdownEnv :: Environment
+              _tlOexpectedCast :: Bool
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: ScalarExpr
+              _hdIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _hdIoriginalTree :: ScalarExpr
+              _hdIupType :: (Maybe TypeExtra)
+              _tlIannotatedTree :: ScalarExprList
+              _tlIoriginalTree :: ScalarExprList
+              _tlIupTypes :: ([Maybe TypeExtra])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 155, column 12)
+              _hdOodbcFunction =
+                  ({-# LINE 155 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 16315 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 196, column 9)
+              _lhsOupTypes =
+                  ({-# LINE 196 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _hdIupType : _tlIupTypes
+                   {-# LINE 16321 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 197, column 9)
+              (_hdOexpectedType,_tlOexpectedTypes) =
+                  ({-# LINE 197 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   case _lhsIexpectedTypes of
+                       (x:xs) -> (Just x,xs)
+                       [] -> (Nothing,[])
+                   {-# LINE 16329 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 201, column 9)
+              _hdOexpectedCast =
+                  ({-# LINE 201 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIexpectedCast
+                   {-# LINE 16335 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 16341 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 16347 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 16353 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 16359 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 16365 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 16371 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 16377 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 16383 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 16389 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 16395 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 16401 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOdownEnv =
+                  ({-# LINE 189 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 16407 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOexpectedCast =
+                  ({-# LINE 192 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIexpectedCast
+                   {-# LINE 16413 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 16419 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 16425 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIcolExprs,_hdIoriginalTree,_hdIupType) =
+                  hd_ _hdOassignmentCastContext _hdOcat _hdOdownEnv _hdOexpectedCast _hdOexpectedType _hdOflags _hdOimCast _hdOodbcFunction
+              ( _tlIannotatedTree,_tlIoriginalTree,_tlIupTypes) =
+                  tl_ _tlOassignmentCastContext _tlOcat _tlOdownEnv _tlOexpectedCast _tlOexpectedTypes _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupTypes)))
+_sem_ScalarExprList_Nil :: T_ScalarExprList
+_sem_ScalarExprList_Nil =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedTypes
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOupTypes :: ([Maybe TypeExtra])
+              _lhsOannotatedTree :: ScalarExprList
+              _lhsOoriginalTree :: ScalarExprList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 202, column 11)
+              _lhsOupTypes =
+                  ({-# LINE 202 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   []
+                   {-# LINE 16448 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 16454 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 16460 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 16466 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 16472 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupTypes)))
+-- ScalarExprListList ------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         assignmentCastContext : Bool
+         cat                  : Catalog
+         downEnv              : Environment
+         expectedCast         : Bool
+         expectedType         : Maybe [TypeExtra]
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : ScalarExprListList 
+         originalTree         : ScalarExprListList 
+         upType               : Either [TypeError] [(Text,TypeExtra)]
+   alternatives:
+      alternative Cons:
+         child hd             : ScalarExprTransposedList 
+         child tl             : ScalarExprListList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type ScalarExprListList = [ScalarExprTransposedList]
+-- cata
+_sem_ScalarExprListList :: ScalarExprListList ->
+                          T_ScalarExprListList
+_sem_ScalarExprListList list =
+    (Prelude.foldr _sem_ScalarExprListList_Cons _sem_ScalarExprListList_Nil (Prelude.map _sem_ScalarExprTransposedList list))
+-- semantic domain
+type T_ScalarExprListList = Bool ->
+                            Catalog ->
+                            Environment ->
+                            Bool ->
+                            (Maybe [TypeExtra]) ->
+                            TypeCheckFlags ->
+                            (Maybe TypeExtra) ->
+                            ( ScalarExprListList,ScalarExprListList,(Either [TypeError] [(Text,TypeExtra)]))
+data Inh_ScalarExprListList = Inh_ScalarExprListList {_assignmentCastContext_Inh_ScalarExprListList :: Bool,_cat_Inh_ScalarExprListList :: Catalog,_downEnv_Inh_ScalarExprListList :: Environment,_expectedCast_Inh_ScalarExprListList :: Bool,_expectedType_Inh_ScalarExprListList :: (Maybe [TypeExtra]),_flags_Inh_ScalarExprListList :: TypeCheckFlags,_imCast_Inh_ScalarExprListList :: (Maybe TypeExtra)}
+data Syn_ScalarExprListList = Syn_ScalarExprListList {_annotatedTree_Syn_ScalarExprListList :: ScalarExprListList,_originalTree_Syn_ScalarExprListList :: ScalarExprListList,_upType_Syn_ScalarExprListList :: (Either [TypeError] [(Text,TypeExtra)])}
+_wrap_ScalarExprListList :: T_ScalarExprListList ->
+                           Inh_ScalarExprListList ->
+                           Syn_ScalarExprListList
+_wrap_ScalarExprListList sem (Inh_ScalarExprListList _lhsIassignmentCastContext _lhsIcat _lhsIdownEnv _lhsIexpectedCast _lhsIexpectedType _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupType) = sem _lhsIassignmentCastContext _lhsIcat _lhsIdownEnv _lhsIexpectedCast _lhsIexpectedType _lhsIflags _lhsIimCast
+     in  (Syn_ScalarExprListList _lhsOannotatedTree _lhsOoriginalTree _lhsOupType))
+_sem_ScalarExprListList_Cons :: T_ScalarExprTransposedList ->
+                               T_ScalarExprListList ->
+                               T_ScalarExprListList
+_sem_ScalarExprListList_Cons hd_ tl_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOupType :: (Either [TypeError] [(Text,TypeExtra)])
+              _hdOexpectedCast :: Bool
+              _tlOexpectedCast :: Bool
+              _lhsOannotatedTree :: ScalarExprListList
+              _lhsOoriginalTree :: ScalarExprListList
+              _hdOcat :: Catalog
+              _hdOexpectedType :: (Maybe [TypeExtra])
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOassignmentCastContext :: Bool
+              _tlOcat :: Catalog
+              _tlOdownEnv :: Environment
+              _tlOexpectedType :: (Maybe [TypeExtra])
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: ScalarExprTransposedList
+              _hdIoriginalTree :: ScalarExprTransposedList
+              _hdIupType :: (Maybe [TypeExtra])
+              _tlIannotatedTree :: ScalarExprListList
+              _tlIoriginalTree :: ScalarExprListList
+              _tlIupType :: (Either [TypeError] [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 191, column 9)
+              _lhsOupType =
+                  ({-# LINE 191 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   do
+                   a <- maybe (Left [InternalError "type error in VALUES clause"]) Right _hdIupType
+                   b <- _tlIupType
+                   unless (not $ null a) $ Left [InternalError "empty row in VALUES clause"]
+                   let a' = map ("",) a
+                       itError = Left [IncompatibleUnionTypes (CompositeType a') (CompositeType b)]
+                   unless (null b || length a == length b) itError
+                   if null b
+                     then return $ zip [T.pack ("values%" ++ show k) | k <- [(0::Int)..]] a
+                     else
+                       do
+                       let uts = zipWithM (\te1 (_,te2) -> resolveResultSetTypeExtra _lhsIcat [te1,te2])
+                                     a b
+                       case uts of
+                         Left{} -> itError
+                         Right uts' -> return $ zipWith (\(n,_) te -> (n,te)) b uts'
+                   {-# LINE 16576 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 209, column 9)
+              _hdOexpectedCast =
+                  ({-# LINE 209 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIexpectedCast
+                   {-# LINE 16582 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 210, column 9)
+              _tlOexpectedCast =
+                  ({-# LINE 210 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIexpectedCast
+                   {-# LINE 16588 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 16594 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 16600 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 16606 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 16612 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 16618 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOexpectedType =
+                  ({-# LINE 169 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIexpectedType
+                   {-# LINE 16624 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 16630 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 16636 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 16642 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 16648 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOdownEnv =
+                  ({-# LINE 183 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 16654 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOexpectedType =
+                  ({-# LINE 186 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIexpectedType
+                   {-# LINE 16660 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 16666 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 16672 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree,_hdIupType) =
+                  hd_ _hdOcat _hdOexpectedCast _hdOexpectedType _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree,_tlIupType) =
+                  tl_ _tlOassignmentCastContext _tlOcat _tlOdownEnv _tlOexpectedCast _tlOexpectedType _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExprListList_Nil :: T_ScalarExprListList
+_sem_ScalarExprListList_Nil =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOupType :: (Either [TypeError] [(Text,TypeExtra)])
+              _lhsOannotatedTree :: ScalarExprListList
+              _lhsOoriginalTree :: ScalarExprListList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 211, column 11)
+              _lhsOupType =
+                  ({-# LINE 211 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   Right []
+                   {-# LINE 16695 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 16701 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 16707 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 16713 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 16719 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupType)))
+-- ScalarExprListStatementListTriple ---------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : ScalarExprListStatementListTriple 
+         originalTree         : ScalarExprListStatementListTriple 
+   alternatives:
+      alternative Tuple:
+         child x1             : ScalarExprList 
+         child x2             : StatementList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type ScalarExprListStatementListTriple = ( ScalarExprList,StatementList)
+-- cata
+_sem_ScalarExprListStatementListTriple :: ScalarExprListStatementListTriple ->
+                                         T_ScalarExprListStatementListTriple
+_sem_ScalarExprListStatementListTriple ( x1,x2) =
+    (_sem_ScalarExprListStatementListTriple_Tuple (_sem_ScalarExprList x1) (_sem_StatementList x2))
+-- semantic domain
+type T_ScalarExprListStatementListTriple = Catalog ->
+                                           TypeCheckFlags ->
+                                           (Maybe TypeExtra) ->
+                                           ( ScalarExprListStatementListTriple,ScalarExprListStatementListTriple)
+data Inh_ScalarExprListStatementListTriple = Inh_ScalarExprListStatementListTriple {_cat_Inh_ScalarExprListStatementListTriple :: Catalog,_flags_Inh_ScalarExprListStatementListTriple :: TypeCheckFlags,_imCast_Inh_ScalarExprListStatementListTriple :: (Maybe TypeExtra)}
+data Syn_ScalarExprListStatementListTriple = Syn_ScalarExprListStatementListTriple {_annotatedTree_Syn_ScalarExprListStatementListTriple :: ScalarExprListStatementListTriple,_originalTree_Syn_ScalarExprListStatementListTriple :: ScalarExprListStatementListTriple}
+_wrap_ScalarExprListStatementListTriple :: T_ScalarExprListStatementListTriple ->
+                                          Inh_ScalarExprListStatementListTriple ->
+                                          Syn_ScalarExprListStatementListTriple
+_wrap_ScalarExprListStatementListTriple sem (Inh_ScalarExprListStatementListTriple _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_ScalarExprListStatementListTriple _lhsOannotatedTree _lhsOoriginalTree))
+_sem_ScalarExprListStatementListTriple_Tuple :: T_ScalarExprList ->
+                                               T_StatementList ->
+                                               T_ScalarExprListStatementListTriple
+_sem_ScalarExprListStatementListTriple_Tuple x1_ x2_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _x1OdownEnv :: Environment
+              _x1OexpectedCast :: Bool
+              _x1OexpectedTypes :: ([TypeExtra])
+              _x1OassignmentCastContext :: Bool
+              _lhsOannotatedTree :: ScalarExprListStatementListTriple
+              _lhsOoriginalTree :: ScalarExprListStatementListTriple
+              _x1Ocat :: Catalog
+              _x1Oflags :: TypeCheckFlags
+              _x1OimCast :: (Maybe TypeExtra)
+              _x2Ocat :: Catalog
+              _x2Oflags :: TypeCheckFlags
+              _x2OimCast :: (Maybe TypeExtra)
+              _x1IannotatedTree :: ScalarExprList
+              _x1IoriginalTree :: ScalarExprList
+              _x1IupTypes :: ([Maybe TypeExtra])
+              _x2IannotatedTree :: StatementList
+              _x2IoriginalTree :: StatementList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 93, column 47)
+              _x1OdownEnv =
+                  ({-# LINE 93 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 16787 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 94, column 47)
+              _x1OexpectedCast =
+                  ({-# LINE 94 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 16793 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 95, column 47)
+              _x1OexpectedTypes =
+                  ({-# LINE 95 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   []
+                   {-# LINE 16799 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 818, column 47)
+              _x1OassignmentCastContext =
+                  ({-# LINE 818 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 16805 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (_x1IannotatedTree,_x2IannotatedTree)
+                   {-# LINE 16811 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (_x1IoriginalTree,_x2IoriginalTree)
+                   {-# LINE 16817 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 16823 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 16829 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1Ocat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 16835 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1Oflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 16841 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1OimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 16847 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x2Ocat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 16853 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x2Oflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 16859 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x2OimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 16865 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _x1IannotatedTree,_x1IoriginalTree,_x1IupTypes) =
+                  x1_ _x1OassignmentCastContext _x1Ocat _x1OdownEnv _x1OexpectedCast _x1OexpectedTypes _x1Oflags _x1OimCast
+              ( _x2IannotatedTree,_x2IoriginalTree) =
+                  x2_ _x2Ocat _x2Oflags _x2OimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- ScalarExprListStatementListTripleList -----------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : ScalarExprListStatementListTripleList 
+         originalTree         : ScalarExprListStatementListTripleList 
+   alternatives:
+      alternative Cons:
+         child hd             : ScalarExprListStatementListTriple 
+         child tl             : ScalarExprListStatementListTripleList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type ScalarExprListStatementListTripleList = [ScalarExprListStatementListTriple]
+-- cata
+_sem_ScalarExprListStatementListTripleList :: ScalarExprListStatementListTripleList ->
+                                             T_ScalarExprListStatementListTripleList
+_sem_ScalarExprListStatementListTripleList list =
+    (Prelude.foldr _sem_ScalarExprListStatementListTripleList_Cons _sem_ScalarExprListStatementListTripleList_Nil (Prelude.map _sem_ScalarExprListStatementListTriple list))
+-- semantic domain
+type T_ScalarExprListStatementListTripleList = Catalog ->
+                                               TypeCheckFlags ->
+                                               (Maybe TypeExtra) ->
+                                               ( ScalarExprListStatementListTripleList,ScalarExprListStatementListTripleList)
+data Inh_ScalarExprListStatementListTripleList = Inh_ScalarExprListStatementListTripleList {_cat_Inh_ScalarExprListStatementListTripleList :: Catalog,_flags_Inh_ScalarExprListStatementListTripleList :: TypeCheckFlags,_imCast_Inh_ScalarExprListStatementListTripleList :: (Maybe TypeExtra)}
+data Syn_ScalarExprListStatementListTripleList = Syn_ScalarExprListStatementListTripleList {_annotatedTree_Syn_ScalarExprListStatementListTripleList :: ScalarExprListStatementListTripleList,_originalTree_Syn_ScalarExprListStatementListTripleList :: ScalarExprListStatementListTripleList}
+_wrap_ScalarExprListStatementListTripleList :: T_ScalarExprListStatementListTripleList ->
+                                              Inh_ScalarExprListStatementListTripleList ->
+                                              Syn_ScalarExprListStatementListTripleList
+_wrap_ScalarExprListStatementListTripleList sem (Inh_ScalarExprListStatementListTripleList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_ScalarExprListStatementListTripleList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_ScalarExprListStatementListTripleList_Cons :: T_ScalarExprListStatementListTriple ->
+                                                  T_ScalarExprListStatementListTripleList ->
+                                                  T_ScalarExprListStatementListTripleList
+_sem_ScalarExprListStatementListTripleList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: ScalarExprListStatementListTripleList
+              _lhsOoriginalTree :: ScalarExprListStatementListTripleList
+              _hdOcat :: Catalog
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: ScalarExprListStatementListTriple
+              _hdIoriginalTree :: ScalarExprListStatementListTriple
+              _tlIannotatedTree :: ScalarExprListStatementListTripleList
+              _tlIoriginalTree :: ScalarExprListStatementListTripleList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 16936 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 16942 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 16948 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 16954 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 16960 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 16966 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 16972 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 16978 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 16984 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 16990 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree) =
+                  hd_ _hdOcat _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_ScalarExprListStatementListTripleList_Nil :: T_ScalarExprListStatementListTripleList
+_sem_ScalarExprListStatementListTripleList_Nil =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: ScalarExprListStatementListTripleList
+              _lhsOoriginalTree :: ScalarExprListStatementListTripleList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 17008 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 17014 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 17020 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 17026 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- ScalarExprRoot ----------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         downEnv              : Environment
+         flags                : TypeCheckFlags
+      synthesized attributes:
+         annotatedTree        : ScalarExprRoot 
+         originalTree         : ScalarExprRoot 
+   alternatives:
+      alternative ScalarExprRoot:
+         child expr           : ScalarExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data ScalarExprRoot = ScalarExprRoot (ScalarExpr)
+                    deriving ( Show)
+-- cata
+_sem_ScalarExprRoot :: ScalarExprRoot ->
+                      T_ScalarExprRoot
+_sem_ScalarExprRoot (ScalarExprRoot _expr) =
+    (_sem_ScalarExprRoot_ScalarExprRoot (_sem_ScalarExpr _expr))
+-- semantic domain
+type T_ScalarExprRoot = Catalog ->
+                        Environment ->
+                        TypeCheckFlags ->
+                        ( ScalarExprRoot,ScalarExprRoot)
+data Inh_ScalarExprRoot = Inh_ScalarExprRoot {_cat_Inh_ScalarExprRoot :: Catalog,_downEnv_Inh_ScalarExprRoot :: Environment,_flags_Inh_ScalarExprRoot :: TypeCheckFlags}
+data Syn_ScalarExprRoot = Syn_ScalarExprRoot {_annotatedTree_Syn_ScalarExprRoot :: ScalarExprRoot,_originalTree_Syn_ScalarExprRoot :: ScalarExprRoot}
+_wrap_ScalarExprRoot :: T_ScalarExprRoot ->
+                       Inh_ScalarExprRoot ->
+                       Syn_ScalarExprRoot
+_wrap_ScalarExprRoot sem (Inh_ScalarExprRoot _lhsIcat _lhsIdownEnv _lhsIflags) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIdownEnv _lhsIflags
+     in  (Syn_ScalarExprRoot _lhsOannotatedTree _lhsOoriginalTree))
+_sem_ScalarExprRoot_ScalarExprRoot :: T_ScalarExpr ->
+                                     T_ScalarExprRoot
+_sem_ScalarExprRoot_ScalarExprRoot expr_ =
+    (\ _lhsIcat
+       _lhsIdownEnv
+       _lhsIflags ->
+         (let _exprOexpectedCast :: Bool
+              _exprOodbcFunction :: Bool
+              _exprOdownEnv :: Environment
+              _exprOexpectedType :: (Maybe TypeExtra)
+              _exprOassignmentCastContext :: Bool
+              _exprOimCast :: (Maybe TypeExtra)
+              _lhsOannotatedTree :: ScalarExprRoot
+              _lhsOoriginalTree :: ScalarExprRoot
+              _exprOcat :: Catalog
+              _exprOflags :: TypeCheckFlags
+              _exprIannotatedTree :: ScalarExpr
+              _exprIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exprIoriginalTree :: ScalarExpr
+              _exprIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 96, column 37)
+              _exprOexpectedCast =
+                  ({-# LINE 96 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 17090 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 158, column 22)
+              _exprOodbcFunction =
+                  ({-# LINE 158 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 17096 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 236, column 9)
+              _exprOdownEnv =
+                  ({-# LINE 236 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 17102 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 740, column 20)
+              _exprOexpectedType =
+                  ({-# LINE 740 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   Nothing
+                   {-# LINE 17108 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 819, column 37)
+              _exprOassignmentCastContext =
+                  ({-# LINE 819 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 17114 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag"(line 136, column 8)
+              _exprOimCast =
+                  ({-# LINE 136 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Nothing
+                   {-# LINE 17120 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ScalarExprRoot _exprIannotatedTree
+                   {-# LINE 17126 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ScalarExprRoot _exprIoriginalTree
+                   {-# LINE 17132 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 17138 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 17144 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 17150 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 17156 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _exprIannotatedTree,_exprIcolExprs,_exprIoriginalTree,_exprIupType) =
+                  expr_ _exprOassignmentCastContext _exprOcat _exprOdownEnv _exprOexpectedCast _exprOexpectedType _exprOflags _exprOimCast _exprOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- ScalarExprStatementListPair ---------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : ScalarExprStatementListPair 
+         originalTree         : ScalarExprStatementListPair 
+   alternatives:
+      alternative Tuple:
+         child x1             : ScalarExpr 
+         child x2             : StatementList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type ScalarExprStatementListPair = ( ScalarExpr,StatementList)
+-- cata
+_sem_ScalarExprStatementListPair :: ScalarExprStatementListPair ->
+                                   T_ScalarExprStatementListPair
+_sem_ScalarExprStatementListPair ( x1,x2) =
+    (_sem_ScalarExprStatementListPair_Tuple (_sem_ScalarExpr x1) (_sem_StatementList x2))
+-- semantic domain
+type T_ScalarExprStatementListPair = Catalog ->
+                                     TypeCheckFlags ->
+                                     (Maybe TypeExtra) ->
+                                     ( ScalarExprStatementListPair,ScalarExprStatementListPair)
+data Inh_ScalarExprStatementListPair = Inh_ScalarExprStatementListPair {_cat_Inh_ScalarExprStatementListPair :: Catalog,_flags_Inh_ScalarExprStatementListPair :: TypeCheckFlags,_imCast_Inh_ScalarExprStatementListPair :: (Maybe TypeExtra)}
+data Syn_ScalarExprStatementListPair = Syn_ScalarExprStatementListPair {_annotatedTree_Syn_ScalarExprStatementListPair :: ScalarExprStatementListPair,_originalTree_Syn_ScalarExprStatementListPair :: ScalarExprStatementListPair}
+_wrap_ScalarExprStatementListPair :: T_ScalarExprStatementListPair ->
+                                    Inh_ScalarExprStatementListPair ->
+                                    Syn_ScalarExprStatementListPair
+_wrap_ScalarExprStatementListPair sem (Inh_ScalarExprStatementListPair _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_ScalarExprStatementListPair _lhsOannotatedTree _lhsOoriginalTree))
+_sem_ScalarExprStatementListPair_Tuple :: T_ScalarExpr ->
+                                         T_StatementList ->
+                                         T_ScalarExprStatementListPair
+_sem_ScalarExprStatementListPair_Tuple x1_ x2_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _x1OdownEnv :: Environment
+              _x1OexpectedCast :: Bool
+              _x1OexpectedType :: (Maybe TypeExtra)
+              _x1OodbcFunction :: Bool
+              _x1OassignmentCastContext :: Bool
+              _lhsOannotatedTree :: ScalarExprStatementListPair
+              _lhsOoriginalTree :: ScalarExprStatementListPair
+              _x1Ocat :: Catalog
+              _x1Oflags :: TypeCheckFlags
+              _x1OimCast :: (Maybe TypeExtra)
+              _x2Ocat :: Catalog
+              _x2Oflags :: TypeCheckFlags
+              _x2OimCast :: (Maybe TypeExtra)
+              _x1IannotatedTree :: ScalarExpr
+              _x1IcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _x1IoriginalTree :: ScalarExpr
+              _x1IupType :: (Maybe TypeExtra)
+              _x2IannotatedTree :: StatementList
+              _x2IoriginalTree :: StatementList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 97, column 41)
+              _x1OdownEnv =
+                  ({-# LINE 97 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 17228 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 98, column 41)
+              _x1OexpectedCast =
+                  ({-# LINE 98 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 17234 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 99, column 41)
+              _x1OexpectedType =
+                  ({-# LINE 99 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 17240 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 100, column 41)
+              _x1OodbcFunction =
+                  ({-# LINE 100 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 17246 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 820, column 41)
+              _x1OassignmentCastContext =
+                  ({-# LINE 820 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 17252 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (_x1IannotatedTree,_x2IannotatedTree)
+                   {-# LINE 17258 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (_x1IoriginalTree,_x2IoriginalTree)
+                   {-# LINE 17264 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 17270 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 17276 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1Ocat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 17282 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1Oflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 17288 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x1OimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 17294 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x2Ocat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 17300 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x2Oflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 17306 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _x2OimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 17312 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _x1IannotatedTree,_x1IcolExprs,_x1IoriginalTree,_x1IupType) =
+                  x1_ _x1OassignmentCastContext _x1Ocat _x1OdownEnv _x1OexpectedCast _x1OexpectedType _x1Oflags _x1OimCast _x1OodbcFunction
+              ( _x2IannotatedTree,_x2IoriginalTree) =
+                  x2_ _x2Ocat _x2Oflags _x2OimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- ScalarExprStatementListPairList -----------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : ScalarExprStatementListPairList 
+         originalTree         : ScalarExprStatementListPairList 
+   alternatives:
+      alternative Cons:
+         child hd             : ScalarExprStatementListPair 
+         child tl             : ScalarExprStatementListPairList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type ScalarExprStatementListPairList = [ScalarExprStatementListPair]
+-- cata
+_sem_ScalarExprStatementListPairList :: ScalarExprStatementListPairList ->
+                                       T_ScalarExprStatementListPairList
+_sem_ScalarExprStatementListPairList list =
+    (Prelude.foldr _sem_ScalarExprStatementListPairList_Cons _sem_ScalarExprStatementListPairList_Nil (Prelude.map _sem_ScalarExprStatementListPair list))
+-- semantic domain
+type T_ScalarExprStatementListPairList = Catalog ->
+                                         TypeCheckFlags ->
+                                         (Maybe TypeExtra) ->
+                                         ( ScalarExprStatementListPairList,ScalarExprStatementListPairList)
+data Inh_ScalarExprStatementListPairList = Inh_ScalarExprStatementListPairList {_cat_Inh_ScalarExprStatementListPairList :: Catalog,_flags_Inh_ScalarExprStatementListPairList :: TypeCheckFlags,_imCast_Inh_ScalarExprStatementListPairList :: (Maybe TypeExtra)}
+data Syn_ScalarExprStatementListPairList = Syn_ScalarExprStatementListPairList {_annotatedTree_Syn_ScalarExprStatementListPairList :: ScalarExprStatementListPairList,_originalTree_Syn_ScalarExprStatementListPairList :: ScalarExprStatementListPairList}
+_wrap_ScalarExprStatementListPairList :: T_ScalarExprStatementListPairList ->
+                                        Inh_ScalarExprStatementListPairList ->
+                                        Syn_ScalarExprStatementListPairList
+_wrap_ScalarExprStatementListPairList sem (Inh_ScalarExprStatementListPairList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_ScalarExprStatementListPairList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_ScalarExprStatementListPairList_Cons :: T_ScalarExprStatementListPair ->
+                                            T_ScalarExprStatementListPairList ->
+                                            T_ScalarExprStatementListPairList
+_sem_ScalarExprStatementListPairList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: ScalarExprStatementListPairList
+              _lhsOoriginalTree :: ScalarExprStatementListPairList
+              _hdOcat :: Catalog
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: ScalarExprStatementListPair
+              _hdIoriginalTree :: ScalarExprStatementListPair
+              _tlIannotatedTree :: ScalarExprStatementListPairList
+              _tlIoriginalTree :: ScalarExprStatementListPairList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 17383 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 17389 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 17395 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 17401 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 17407 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 17413 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 17419 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 17425 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 17431 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 17437 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree) =
+                  hd_ _hdOcat _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_ScalarExprStatementListPairList_Nil :: T_ScalarExprStatementListPairList
+_sem_ScalarExprStatementListPairList_Nil =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: ScalarExprStatementListPairList
+              _lhsOoriginalTree :: ScalarExprStatementListPairList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 17455 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 17461 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 17467 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 17473 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- ScalarExprTransposedList ------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         expectedCast         : Bool
+         expectedType         : Maybe [TypeExtra]
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : ScalarExprTransposedList 
+         originalTree         : ScalarExprTransposedList 
+         upType               : Maybe [TypeExtra]
+   alternatives:
+      alternative Cons:
+         child hd             : ScalarExpr 
+         child tl             : ScalarExprTransposedList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type ScalarExprTransposedList = [ScalarExpr]
+-- cata
+_sem_ScalarExprTransposedList :: ScalarExprTransposedList ->
+                                T_ScalarExprTransposedList
+_sem_ScalarExprTransposedList list =
+    (Prelude.foldr _sem_ScalarExprTransposedList_Cons _sem_ScalarExprTransposedList_Nil (Prelude.map _sem_ScalarExpr list))
+-- semantic domain
+type T_ScalarExprTransposedList = Catalog ->
+                                  Bool ->
+                                  (Maybe [TypeExtra]) ->
+                                  TypeCheckFlags ->
+                                  (Maybe TypeExtra) ->
+                                  ( ScalarExprTransposedList,ScalarExprTransposedList,(Maybe [TypeExtra]))
+data Inh_ScalarExprTransposedList = Inh_ScalarExprTransposedList {_cat_Inh_ScalarExprTransposedList :: Catalog,_expectedCast_Inh_ScalarExprTransposedList :: Bool,_expectedType_Inh_ScalarExprTransposedList :: (Maybe [TypeExtra]),_flags_Inh_ScalarExprTransposedList :: TypeCheckFlags,_imCast_Inh_ScalarExprTransposedList :: (Maybe TypeExtra)}
+data Syn_ScalarExprTransposedList = Syn_ScalarExprTransposedList {_annotatedTree_Syn_ScalarExprTransposedList :: ScalarExprTransposedList,_originalTree_Syn_ScalarExprTransposedList :: ScalarExprTransposedList,_upType_Syn_ScalarExprTransposedList :: (Maybe [TypeExtra])}
+_wrap_ScalarExprTransposedList :: T_ScalarExprTransposedList ->
+                                 Inh_ScalarExprTransposedList ->
+                                 Syn_ScalarExprTransposedList
+_wrap_ScalarExprTransposedList sem (Inh_ScalarExprTransposedList _lhsIcat _lhsIexpectedCast _lhsIexpectedType _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupType) = sem _lhsIcat _lhsIexpectedCast _lhsIexpectedType _lhsIflags _lhsIimCast
+     in  (Syn_ScalarExprTransposedList _lhsOannotatedTree _lhsOoriginalTree _lhsOupType))
+_sem_ScalarExprTransposedList_Cons :: T_ScalarExpr ->
+                                     T_ScalarExprTransposedList ->
+                                     T_ScalarExprTransposedList
+_sem_ScalarExprTransposedList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast ->
+         (let _hdOdownEnv :: Environment
+              _lhsOupType :: (Maybe [TypeExtra])
+              _hdOexpectedType :: (Maybe TypeExtra)
+              _tlOexpectedType :: (Maybe [TypeExtra])
+              _hdOexpectedCast :: Bool
+              _tlOexpectedCast :: Bool
+              _hdOodbcFunction :: Bool
+              _hdOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: ScalarExprTransposedList
+              _lhsOoriginalTree :: ScalarExprTransposedList
+              _hdOcat :: Catalog
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: ScalarExpr
+              _hdIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _hdIoriginalTree :: ScalarExpr
+              _hdIupType :: (Maybe TypeExtra)
+              _tlIannotatedTree :: ScalarExprTransposedList
+              _tlIoriginalTree :: ScalarExprTransposedList
+              _tlIupType :: (Maybe [TypeExtra])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 101, column 37)
+              _hdOdownEnv =
+                  ({-# LINE 101 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 17558 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 174, column 9)
+              _lhsOupType =
+                  ({-# LINE 174 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   liftM2 (:) _hdIupType _tlIupType
+                   {-# LINE 17564 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 175, column 9)
+              _hdOexpectedType =
+                  ({-# LINE 175 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   liftM fst $ splitTypeExtraList _lhsIexpectedType
+                   {-# LINE 17570 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 176, column 9)
+              _tlOexpectedType =
+                  ({-# LINE 176 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   liftM snd $ splitTypeExtraList _lhsIexpectedType
+                   {-# LINE 17576 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 177, column 9)
+              _hdOexpectedCast =
+                  ({-# LINE 177 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIexpectedCast
+                   {-# LINE 17582 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 178, column 9)
+              _tlOexpectedCast =
+                  ({-# LINE 178 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIexpectedCast
+                   {-# LINE 17588 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 162, column 12)
+              _hdOodbcFunction =
+                  ({-# LINE 162 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 17594 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 821, column 37)
+              _hdOassignmentCastContext =
+                  ({-# LINE 821 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 17600 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 17606 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 17612 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 17618 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 17624 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 17630 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 17636 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 17642 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 17648 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 17654 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 17660 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIcolExprs,_hdIoriginalTree,_hdIupType) =
+                  hd_ _hdOassignmentCastContext _hdOcat _hdOdownEnv _hdOexpectedCast _hdOexpectedType _hdOflags _hdOimCast _hdOodbcFunction
+              ( _tlIannotatedTree,_tlIoriginalTree,_tlIupType) =
+                  tl_ _tlOcat _tlOexpectedCast _tlOexpectedType _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupType)))
+_sem_ScalarExprTransposedList_Nil :: T_ScalarExprTransposedList
+_sem_ScalarExprTransposedList_Nil =
+    (\ _lhsIcat
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOupType :: (Maybe [TypeExtra])
+              _lhsOannotatedTree :: ScalarExprTransposedList
+              _lhsOoriginalTree :: ScalarExprTransposedList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 180, column 9)
+              _lhsOupType =
+                  ({-# LINE 180 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   Just []
+                   {-# LINE 17681 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 17687 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 17693 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 17699 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 17705 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupType)))
+-- SelectItem --------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         assignmentCastContext : Bool
+         cat                  : Catalog
+         downEnv              : Environment
+         expectedCast         : Bool
+         expectedType         : Maybe TypeExtra
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : SelectItem 
+         colExprs             : [(NameComponent,Maybe TypeExtra,ScalarExpr)]
+         originalTree         : SelectItem 
+   alternatives:
+      alternative SelExp:
+         child ann            : Annotation 
+         child ex             : ScalarExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative SelectItem:
+         child ann            : Annotation 
+         child ex             : ScalarExpr 
+         child name           : {NameComponent}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data SelectItem = SelExp (Annotation) (ScalarExpr)
+                | SelectItem (Annotation) (ScalarExpr) (NameComponent)
+                deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_SelectItem :: SelectItem ->
+                  T_SelectItem
+_sem_SelectItem (SelExp _ann _ex) =
+    (_sem_SelectItem_SelExp (_sem_Annotation _ann) (_sem_ScalarExpr _ex))
+_sem_SelectItem (SelectItem _ann _ex _name) =
+    (_sem_SelectItem_SelectItem (_sem_Annotation _ann) (_sem_ScalarExpr _ex) _name)
+-- semantic domain
+type T_SelectItem = Bool ->
+                    Catalog ->
+                    Environment ->
+                    Bool ->
+                    (Maybe TypeExtra) ->
+                    TypeCheckFlags ->
+                    (Maybe TypeExtra) ->
+                    ( SelectItem,([(NameComponent,Maybe TypeExtra,ScalarExpr)]),SelectItem)
+data Inh_SelectItem = Inh_SelectItem {_assignmentCastContext_Inh_SelectItem :: Bool,_cat_Inh_SelectItem :: Catalog,_downEnv_Inh_SelectItem :: Environment,_expectedCast_Inh_SelectItem :: Bool,_expectedType_Inh_SelectItem :: (Maybe TypeExtra),_flags_Inh_SelectItem :: TypeCheckFlags,_imCast_Inh_SelectItem :: (Maybe TypeExtra)}
+data Syn_SelectItem = Syn_SelectItem {_annotatedTree_Syn_SelectItem :: SelectItem,_colExprs_Syn_SelectItem :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)]),_originalTree_Syn_SelectItem :: SelectItem}
+_wrap_SelectItem :: T_SelectItem ->
+                   Inh_SelectItem ->
+                   Syn_SelectItem
+_wrap_SelectItem sem (Inh_SelectItem _lhsIassignmentCastContext _lhsIcat _lhsIdownEnv _lhsIexpectedCast _lhsIexpectedType _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree) = sem _lhsIassignmentCastContext _lhsIcat _lhsIdownEnv _lhsIexpectedCast _lhsIexpectedType _lhsIflags _lhsIimCast
+     in  (Syn_SelectItem _lhsOannotatedTree _lhsOcolExprs _lhsOoriginalTree))
+_sem_SelectItem_SelExp :: T_Annotation ->
+                         T_ScalarExpr ->
+                         T_SelectItem
+_sem_SelectItem_SelExp ann_ ex_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: SelectItem
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _exOexpectedType :: (Maybe TypeExtra)
+              _exOexpectedCast :: Bool
+              _exOodbcFunction :: Bool
+              _lhsOoriginalTree :: SelectItem
+              _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _exOassignmentCastContext :: Bool
+              _exOcat :: Catalog
+              _exOdownEnv :: Environment
+              _exOflags :: TypeCheckFlags
+              _exOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exIannotatedTree :: ScalarExpr
+              _exIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exIoriginalTree :: ScalarExpr
+              _exIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 117, column 7)
+              _lhsOannotatedTree =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   if tcfAddSelectItemAliases _lhsIflags
+                   then case _exIcolExprs of
+                          [(n,_,_)] -> SelectItem _annIannotatedTree _exIannotatedTree n
+                          _ ->
+                               _annotatedTree
+                   else _annotatedTree
+                   {-# LINE 17806 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 208, column 7)
+              _annOtpe =
+                  ({-# LINE 208 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   Left []
+                   {-# LINE 17812 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 209, column 7)
+              _exOexpectedType =
+                  ({-# LINE 209 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _lhsIexpectedType
+                   {-# LINE 17818 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 210, column 7)
+              _exOexpectedCast =
+                  ({-# LINE 210 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _lhsIexpectedCast
+                   {-# LINE 17824 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 165, column 25)
+              _exOodbcFunction =
+                  ({-# LINE 165 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 17830 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SelExp _annIannotatedTree _exIannotatedTree
+                   {-# LINE 17836 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SelExp _annIoriginalTree _exIoriginalTree
+                   {-# LINE 17842 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 17848 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (up)
+              _lhsOcolExprs =
+                  ({-# LINE 150 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _exIcolExprs
+                   {-# LINE 17854 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 17860 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 17866 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 17872 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 17878 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 17884 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 17890 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 17896 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 17902 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exIannotatedTree,_exIcolExprs,_exIoriginalTree,_exIupType) =
+                  ex_ _exOassignmentCastContext _exOcat _exOdownEnv _exOexpectedCast _exOexpectedType _exOflags _exOimCast _exOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree)))
+_sem_SelectItem_SelectItem :: T_Annotation ->
+                             T_ScalarExpr ->
+                             NameComponent ->
+                             T_SelectItem
+_sem_SelectItem_SelectItem ann_ ex_ name_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _exOexpectedType :: (Maybe TypeExtra)
+              _exOexpectedCast :: Bool
+              _exOodbcFunction :: Bool
+              _lhsOannotatedTree :: SelectItem
+              _lhsOoriginalTree :: SelectItem
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _exOassignmentCastContext :: Bool
+              _exOcat :: Catalog
+              _exOdownEnv :: Environment
+              _exOflags :: TypeCheckFlags
+              _exOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exIannotatedTree :: ScalarExpr
+              _exIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exIoriginalTree :: ScalarExpr
+              _exIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 112, column 7)
+              _lhsOcolExprs =
+                  ({-# LINE 112 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   case _exIcolExprs of
+                     [(_,t,e)] -> [(name_, t,e)]
+                     x -> x
+                   {-# LINE 17948 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 208, column 7)
+              _annOtpe =
+                  ({-# LINE 208 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   Left []
+                   {-# LINE 17954 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 209, column 7)
+              _exOexpectedType =
+                  ({-# LINE 209 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _lhsIexpectedType
+                   {-# LINE 17960 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 210, column 7)
+              _exOexpectedCast =
+                  ({-# LINE 210 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _lhsIexpectedCast
+                   {-# LINE 17966 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 165, column 25)
+              _exOodbcFunction =
+                  ({-# LINE 165 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 17972 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SelectItem _annIannotatedTree _exIannotatedTree name_
+                   {-# LINE 17978 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SelectItem _annIoriginalTree _exIoriginalTree name_
+                   {-# LINE 17984 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 17990 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 17996 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 18002 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 18008 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 18014 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 18020 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 18026 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOdownEnv =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 18032 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 18038 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 18044 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exIannotatedTree,_exIcolExprs,_exIoriginalTree,_exIupType) =
+                  ex_ _exOassignmentCastContext _exOcat _exOdownEnv _exOexpectedCast _exOexpectedType _exOflags _exOimCast _exOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree)))
+-- SelectItemList ----------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         assignmentCastContext : Bool
+         cat                  : Catalog
+         downEnv              : Environment
+         expectedCast         : Bool
+         expectedType         : Maybe [TypeExtra]
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : SelectItemList 
+         colExprs             : [(NameComponent,Maybe TypeExtra,ScalarExpr)]
+         originalTree         : SelectItemList 
+         upEnv                : Environment
+         upType               : Maybe [(Text,TypeExtra)]
+   alternatives:
+      alternative Cons:
+         child hd             : SelectItem 
+         child tl             : SelectItemList 
+         visit 0:
+            local colExprs    : _
+            local upType      : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local upType      : _
+            local annotatedTree : _
+            local originalTree : _
+-}
+type SelectItemList = [SelectItem]
+-- cata
+_sem_SelectItemList :: SelectItemList ->
+                      T_SelectItemList
+_sem_SelectItemList list =
+    (Prelude.foldr _sem_SelectItemList_Cons _sem_SelectItemList_Nil (Prelude.map _sem_SelectItem list))
+-- semantic domain
+type T_SelectItemList = Bool ->
+                        Catalog ->
+                        Environment ->
+                        Bool ->
+                        (Maybe [TypeExtra]) ->
+                        TypeCheckFlags ->
+                        (Maybe TypeExtra) ->
+                        ( SelectItemList,([(NameComponent,Maybe TypeExtra,ScalarExpr)]),SelectItemList,Environment,(Maybe [(Text,TypeExtra)]))
+data Inh_SelectItemList = Inh_SelectItemList {_assignmentCastContext_Inh_SelectItemList :: Bool,_cat_Inh_SelectItemList :: Catalog,_downEnv_Inh_SelectItemList :: Environment,_expectedCast_Inh_SelectItemList :: Bool,_expectedType_Inh_SelectItemList :: (Maybe [TypeExtra]),_flags_Inh_SelectItemList :: TypeCheckFlags,_imCast_Inh_SelectItemList :: (Maybe TypeExtra)}
+data Syn_SelectItemList = Syn_SelectItemList {_annotatedTree_Syn_SelectItemList :: SelectItemList,_colExprs_Syn_SelectItemList :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)]),_originalTree_Syn_SelectItemList :: SelectItemList,_upEnv_Syn_SelectItemList :: Environment,_upType_Syn_SelectItemList :: (Maybe [(Text,TypeExtra)])}
+_wrap_SelectItemList :: T_SelectItemList ->
+                       Inh_SelectItemList ->
+                       Syn_SelectItemList
+_wrap_SelectItemList sem (Inh_SelectItemList _lhsIassignmentCastContext _lhsIcat _lhsIdownEnv _lhsIexpectedCast _lhsIexpectedType _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupEnv,_lhsOupType) = sem _lhsIassignmentCastContext _lhsIcat _lhsIdownEnv _lhsIexpectedCast _lhsIexpectedType _lhsIflags _lhsIimCast
+     in  (Syn_SelectItemList _lhsOannotatedTree _lhsOcolExprs _lhsOoriginalTree _lhsOupEnv _lhsOupType))
+_sem_SelectItemList_Cons :: T_SelectItem ->
+                           T_SelectItemList ->
+                           T_SelectItemList
+_sem_SelectItemList_Cons hd_ tl_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: SelectItemList
+              _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _hdOexpectedType :: (Maybe TypeExtra)
+              _tlOexpectedType :: (Maybe [TypeExtra])
+              _hdOexpectedCast :: Bool
+              _tlOexpectedCast :: Bool
+              _lhsOupType :: (Maybe [(Text,TypeExtra)])
+              _lhsOupEnv :: Environment
+              _lhsOoriginalTree :: SelectItemList
+              _hdOassignmentCastContext :: Bool
+              _hdOcat :: Catalog
+              _hdOdownEnv :: Environment
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOassignmentCastContext :: Bool
+              _tlOcat :: Catalog
+              _tlOdownEnv :: Environment
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: SelectItem
+              _hdIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _hdIoriginalTree :: SelectItem
+              _tlIannotatedTree :: SelectItemList
+              _tlIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _tlIoriginalTree :: SelectItemList
+              _tlIupEnv :: Environment
+              _tlIupType :: (Maybe [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 132, column 10)
+              _lhsOannotatedTree =
+                  ({-# LINE 132 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   if tcfExpandStars _lhsIflags
+                   then flip map _colExprs $ \(n,_t,e) ->
+                         if ncStr n == ncStr (columnName e) && not (tcfAddSelectItemAliases _lhsIflags)
+                         then SelExp emptyAnnotation e
+                         else SelectItem emptyAnnotation e n
+                   else _annotatedTree
+                   {-# LINE 18153 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 177, column 9)
+              _colExprs =
+                  ({-# LINE 177 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _hdIcolExprs ++ _tlIcolExprs
+                   {-# LINE 18159 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 178, column 9)
+              _lhsOcolExprs =
+                  ({-# LINE 178 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _colExprs
+                   {-# LINE 18165 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 179, column 9)
+              _upType =
+                  ({-# LINE 179 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   sequence $ flip map _colExprs
+                   $ \(n,t,_) -> fmap (ncStrT n,) t
+                   {-# LINE 18172 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 181, column 9)
+              _hdOexpectedType =
+                  ({-# LINE 181 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   liftM fst $ splitTypeExtraList _lhsIexpectedType
+                   {-# LINE 18178 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 182, column 9)
+              _tlOexpectedType =
+                  ({-# LINE 182 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   liftM snd $ splitTypeExtraList _lhsIexpectedType
+                   {-# LINE 18184 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 183, column 9)
+              _hdOexpectedCast =
+                  ({-# LINE 183 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _lhsIexpectedCast
+                   {-# LINE 18190 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 184, column 9)
+              _tlOexpectedCast =
+                  ({-# LINE 184 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _lhsIexpectedCast
+                   {-# LINE 18196 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 186, column 7)
+              _lhsOupType =
+                  ({-# LINE 186 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _upType
+                   {-# LINE 18202 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 187, column 7)
+              _lhsOupEnv =
+                  ({-# LINE 187 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   case fmap E.envSelectListEnvironment _upType     of
+                     (Just (Right e)) -> e
+                     _ -> E.brokeEnvironment
+                   {-# LINE 18210 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 18216 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 18222 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 18228 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 18234 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 18240 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOdownEnv =
+                  ({-# LINE 151 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 18246 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 18252 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 18258 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 18264 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 18270 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOdownEnv =
+                  ({-# LINE 156 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 18276 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 18282 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 18288 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIcolExprs,_hdIoriginalTree) =
+                  hd_ _hdOassignmentCastContext _hdOcat _hdOdownEnv _hdOexpectedCast _hdOexpectedType _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIcolExprs,_tlIoriginalTree,_tlIupEnv,_tlIupType) =
+                  tl_ _tlOassignmentCastContext _tlOcat _tlOdownEnv _tlOexpectedCast _tlOexpectedType _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupEnv,_lhsOupType)))
+_sem_SelectItemList_Nil :: T_SelectItemList
+_sem_SelectItemList_Nil =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: SelectItemList
+              _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _lhsOupType :: (Maybe [(Text,TypeExtra)])
+              _lhsOupEnv :: Environment
+              _lhsOoriginalTree :: SelectItemList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 131, column 9)
+              _lhsOannotatedTree =
+                  ({-# LINE 131 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   []
+                   {-# LINE 18313 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 174, column 9)
+              _lhsOcolExprs =
+                  ({-# LINE 174 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   []
+                   {-# LINE 18319 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 175, column 9)
+              _upType =
+                  ({-# LINE 175 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   Nothing
+                   {-# LINE 18325 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 186, column 7)
+              _lhsOupType =
+                  ({-# LINE 186 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _upType
+                   {-# LINE 18331 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 187, column 7)
+              _lhsOupEnv =
+                  ({-# LINE 187 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   case fmap E.envSelectListEnvironment _upType     of
+                     (Just (Right e)) -> e
+                     _ -> E.brokeEnvironment
+                   {-# LINE 18339 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 18345 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 18351 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 18357 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupEnv,_lhsOupType)))
+-- SelectList --------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         assignmentCastContext : Bool
+         cat                  : Catalog
+         downEnv              : Environment
+         expectedCast         : Bool
+         expectedType         : Maybe [TypeExtra]
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : SelectList 
+         colExprs             : [(NameComponent,Maybe TypeExtra,ScalarExpr)]
+         originalTree         : SelectList 
+         upEnv                : Environment
+         upType               : Maybe [(Text,TypeExtra)]
+   alternatives:
+      alternative SelectList:
+         child ann            : Annotation 
+         child items          : SelectItemList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data SelectList = SelectList (Annotation) (SelectItemList)
+                deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_SelectList :: SelectList ->
+                  T_SelectList
+_sem_SelectList (SelectList _ann _items) =
+    (_sem_SelectList_SelectList (_sem_Annotation _ann) (_sem_SelectItemList _items))
+-- semantic domain
+type T_SelectList = Bool ->
+                    Catalog ->
+                    Environment ->
+                    Bool ->
+                    (Maybe [TypeExtra]) ->
+                    TypeCheckFlags ->
+                    (Maybe TypeExtra) ->
+                    ( SelectList,([(NameComponent,Maybe TypeExtra,ScalarExpr)]),SelectList,Environment,(Maybe [(Text,TypeExtra)]))
+data Inh_SelectList = Inh_SelectList {_assignmentCastContext_Inh_SelectList :: Bool,_cat_Inh_SelectList :: Catalog,_downEnv_Inh_SelectList :: Environment,_expectedCast_Inh_SelectList :: Bool,_expectedType_Inh_SelectList :: (Maybe [TypeExtra]),_flags_Inh_SelectList :: TypeCheckFlags,_imCast_Inh_SelectList :: (Maybe TypeExtra)}
+data Syn_SelectList = Syn_SelectList {_annotatedTree_Syn_SelectList :: SelectList,_colExprs_Syn_SelectList :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)]),_originalTree_Syn_SelectList :: SelectList,_upEnv_Syn_SelectList :: Environment,_upType_Syn_SelectList :: (Maybe [(Text,TypeExtra)])}
+_wrap_SelectList :: T_SelectList ->
+                   Inh_SelectList ->
+                   Syn_SelectList
+_wrap_SelectList sem (Inh_SelectList _lhsIassignmentCastContext _lhsIcat _lhsIdownEnv _lhsIexpectedCast _lhsIexpectedType _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupEnv,_lhsOupType) = sem _lhsIassignmentCastContext _lhsIcat _lhsIdownEnv _lhsIexpectedCast _lhsIexpectedType _lhsIflags _lhsIimCast
+     in  (Syn_SelectList _lhsOannotatedTree _lhsOcolExprs _lhsOoriginalTree _lhsOupEnv _lhsOupType))
+_sem_SelectList_SelectList :: T_Annotation ->
+                             T_SelectItemList ->
+                             T_SelectList
+_sem_SelectList_SelectList ann_ items_ =
+    (\ _lhsIassignmentCastContext
+       _lhsIcat
+       _lhsIdownEnv
+       _lhsIexpectedCast
+       _lhsIexpectedType
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _itemsOexpectedCast :: Bool
+              _lhsOannotatedTree :: SelectList
+              _lhsOoriginalTree :: SelectList
+              _lhsOcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _lhsOupEnv :: Environment
+              _lhsOupType :: (Maybe [(Text,TypeExtra)])
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _itemsOassignmentCastContext :: Bool
+              _itemsOcat :: Catalog
+              _itemsOdownEnv :: Environment
+              _itemsOexpectedType :: (Maybe [TypeExtra])
+              _itemsOflags :: TypeCheckFlags
+              _itemsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _itemsIannotatedTree :: SelectItemList
+              _itemsIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _itemsIoriginalTree :: SelectItemList
+              _itemsIupEnv :: Environment
+              _itemsIupType :: (Maybe [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 204, column 7)
+              _annOtpe =
+                  ({-# LINE 204 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   Left []
+                   {-# LINE 18447 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag"(line 205, column 7)
+              _itemsOexpectedCast =
+                  ({-# LINE 205 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   True
+                   {-# LINE 18453 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SelectList _annIannotatedTree _itemsIannotatedTree
+                   {-# LINE 18459 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SelectList _annIoriginalTree _itemsIoriginalTree
+                   {-# LINE 18465 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 18471 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 18477 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (up)
+              _lhsOcolExprs =
+                  ({-# LINE 157 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _itemsIcolExprs
+                   {-# LINE 18483 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (up)
+              _lhsOupEnv =
+                  ({-# LINE 161 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _itemsIupEnv
+                   {-# LINE 18489 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (up)
+              _lhsOupType =
+                  ({-# LINE 158 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _itemsIupType
+                   {-# LINE 18495 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 18501 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 18507 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 18513 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _itemsOassignmentCastContext =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   _lhsIassignmentCastContext
+                   {-# LINE 18519 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _itemsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 18525 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _itemsOdownEnv =
+                  ({-# LINE 156 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _lhsIdownEnv
+                   {-# LINE 18531 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _itemsOexpectedType =
+                  ({-# LINE 159 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/SelectLists.ag" #-}
+                   _lhsIexpectedType
+                   {-# LINE 18537 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _itemsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 18543 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _itemsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 18549 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _itemsIannotatedTree,_itemsIcolExprs,_itemsIoriginalTree,_itemsIupEnv,_itemsIupType) =
+                  items_ _itemsOassignmentCastContext _itemsOcat _itemsOdownEnv _itemsOexpectedCast _itemsOexpectedType _itemsOflags _itemsOimCast
+          in  ( _lhsOannotatedTree,_lhsOcolExprs,_lhsOoriginalTree,_lhsOupEnv,_lhsOupType)))
+-- SetClause ---------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : SetClause 
+         originalTree         : SetClause 
+   alternatives:
+      alternative SetClause:
+         child ann            : Annotation 
+         child setTarget      : {NameComponent}
+         child ex             : ScalarExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative MultiSetClause:
+         child ann            : Annotation 
+         child setTargets     : {[NameComponent]}
+         child ex             : ScalarExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data SetClause = SetClause (Annotation) (NameComponent) (ScalarExpr)
+               | MultiSetClause (Annotation) (([NameComponent])) (ScalarExpr)
+               deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_SetClause :: SetClause ->
+                 T_SetClause
+_sem_SetClause (SetClause _ann _setTarget _ex) =
+    (_sem_SetClause_SetClause (_sem_Annotation _ann) _setTarget (_sem_ScalarExpr _ex))
+_sem_SetClause (MultiSetClause _ann _setTargets _ex) =
+    (_sem_SetClause_MultiSetClause (_sem_Annotation _ann) _setTargets (_sem_ScalarExpr _ex))
+-- semantic domain
+type T_SetClause = Catalog ->
+                   TypeCheckFlags ->
+                   (Maybe TypeExtra) ->
+                   ( SetClause,SetClause)
+data Inh_SetClause = Inh_SetClause {_cat_Inh_SetClause :: Catalog,_flags_Inh_SetClause :: TypeCheckFlags,_imCast_Inh_SetClause :: (Maybe TypeExtra)}
+data Syn_SetClause = Syn_SetClause {_annotatedTree_Syn_SetClause :: SetClause,_originalTree_Syn_SetClause :: SetClause}
+_wrap_SetClause :: T_SetClause ->
+                  Inh_SetClause ->
+                  Syn_SetClause
+_wrap_SetClause sem (Inh_SetClause _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_SetClause _lhsOannotatedTree _lhsOoriginalTree))
+_sem_SetClause_SetClause :: T_Annotation ->
+                           NameComponent ->
+                           T_ScalarExpr ->
+                           T_SetClause
+_sem_SetClause_SetClause ann_ setTarget_ ex_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _exOdownEnv :: Environment
+              _exOexpectedCast :: Bool
+              _exOexpectedType :: (Maybe TypeExtra)
+              _exOodbcFunction :: Bool
+              _exOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: SetClause
+              _lhsOoriginalTree :: SetClause
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _exOcat :: Catalog
+              _exOflags :: TypeCheckFlags
+              _exOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exIannotatedTree :: ScalarExpr
+              _exIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exIoriginalTree :: ScalarExpr
+              _exIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 106, column 27)
+              _annOtpe =
+                  ({-# LINE 106 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 18637 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 107, column 27)
+              _exOdownEnv =
+                  ({-# LINE 107 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 18643 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 108, column 27)
+              _exOexpectedCast =
+                  ({-# LINE 108 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 18649 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 109, column 27)
+              _exOexpectedType =
+                  ({-# LINE 109 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 18655 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 168, column 32)
+              _exOodbcFunction =
+                  ({-# LINE 168 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 18661 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 823, column 27)
+              _exOassignmentCastContext =
+                  ({-# LINE 823 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 18667 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SetClause _annIannotatedTree setTarget_ _exIannotatedTree
+                   {-# LINE 18673 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SetClause _annIoriginalTree setTarget_ _exIoriginalTree
+                   {-# LINE 18679 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 18685 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 18691 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 18697 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 18703 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 18709 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 18715 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 18721 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 18727 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exIannotatedTree,_exIcolExprs,_exIoriginalTree,_exIupType) =
+                  ex_ _exOassignmentCastContext _exOcat _exOdownEnv _exOexpectedCast _exOexpectedType _exOflags _exOimCast _exOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_SetClause_MultiSetClause :: T_Annotation ->
+                                ([NameComponent]) ->
+                                T_ScalarExpr ->
+                                T_SetClause
+_sem_SetClause_MultiSetClause ann_ setTargets_ ex_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _exOdownEnv :: Environment
+              _exOexpectedCast :: Bool
+              _exOexpectedType :: (Maybe TypeExtra)
+              _exOodbcFunction :: Bool
+              _exOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: SetClause
+              _lhsOoriginalTree :: SetClause
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _exOcat :: Catalog
+              _exOflags :: TypeCheckFlags
+              _exOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exIannotatedTree :: ScalarExpr
+              _exIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exIoriginalTree :: ScalarExpr
+              _exIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 102, column 32)
+              _annOtpe =
+                  ({-# LINE 102 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 18766 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 103, column 32)
+              _exOdownEnv =
+                  ({-# LINE 103 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 18772 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 104, column 32)
+              _exOexpectedCast =
+                  ({-# LINE 104 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 18778 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 105, column 32)
+              _exOexpectedType =
+                  ({-# LINE 105 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 18784 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 168, column 32)
+              _exOodbcFunction =
+                  ({-# LINE 168 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 18790 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 822, column 32)
+              _exOassignmentCastContext =
+                  ({-# LINE 822 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 18796 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   MultiSetClause _annIannotatedTree setTargets_ _exIannotatedTree
+                   {-# LINE 18802 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   MultiSetClause _annIoriginalTree setTargets_ _exIoriginalTree
+                   {-# LINE 18808 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 18814 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 18820 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 18826 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 18832 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 18838 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 18844 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 18850 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 18856 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exIannotatedTree,_exIcolExprs,_exIoriginalTree,_exIupType) =
+                  ex_ _exOassignmentCastContext _exOcat _exOdownEnv _exOexpectedCast _exOexpectedType _exOflags _exOimCast _exOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- SetClauseList -----------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : SetClauseList 
+         originalTree         : SetClauseList 
+   alternatives:
+      alternative Cons:
+         child hd             : SetClause 
+         child tl             : SetClauseList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type SetClauseList = [SetClause]
+-- cata
+_sem_SetClauseList :: SetClauseList ->
+                     T_SetClauseList
+_sem_SetClauseList list =
+    (Prelude.foldr _sem_SetClauseList_Cons _sem_SetClauseList_Nil (Prelude.map _sem_SetClause list))
+-- semantic domain
+type T_SetClauseList = Catalog ->
+                       TypeCheckFlags ->
+                       (Maybe TypeExtra) ->
+                       ( SetClauseList,SetClauseList)
+data Inh_SetClauseList = Inh_SetClauseList {_cat_Inh_SetClauseList :: Catalog,_flags_Inh_SetClauseList :: TypeCheckFlags,_imCast_Inh_SetClauseList :: (Maybe TypeExtra)}
+data Syn_SetClauseList = Syn_SetClauseList {_annotatedTree_Syn_SetClauseList :: SetClauseList,_originalTree_Syn_SetClauseList :: SetClauseList}
+_wrap_SetClauseList :: T_SetClauseList ->
+                      Inh_SetClauseList ->
+                      Syn_SetClauseList
+_wrap_SetClauseList sem (Inh_SetClauseList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_SetClauseList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_SetClauseList_Cons :: T_SetClause ->
+                          T_SetClauseList ->
+                          T_SetClauseList
+_sem_SetClauseList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: SetClauseList
+              _lhsOoriginalTree :: SetClauseList
+              _hdOcat :: Catalog
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: SetClause
+              _hdIoriginalTree :: SetClause
+              _tlIannotatedTree :: SetClauseList
+              _tlIoriginalTree :: SetClauseList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 18927 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 18933 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 18939 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 18945 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 18951 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 18957 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 18963 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 18969 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 18975 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 18981 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree) =
+                  hd_ _hdOcat _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_SetClauseList_Nil :: T_SetClauseList
+_sem_SetClauseList_Nil =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: SetClauseList
+              _lhsOoriginalTree :: SetClauseList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 18999 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 19005 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 19011 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 19017 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- Statement ---------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : Statement 
+         originalTree         : Statement 
+   alternatives:
+      alternative QueryStatement:
+         child ann            : Annotation 
+         child ex             : QueryExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Insert:
+         child ann            : Annotation 
+         child table          : Name 
+         child targetCols     : {[NameComponent]}
+         child insData        : QueryExpr 
+         child returning      : MaybeSelectList 
+         visit 0:
+            local tpe         : {Either [TypeError] [TypeExtra]}
+            local tooManyCols : {Maybe [TypeError]}
+            local annotatedTree : _
+            local originalTree : _
+      alternative Update:
+         child ann            : Annotation 
+         child table          : Name 
+         child assigns        : SetClauseList 
+         child fromList       : TableRefList 
+         child whr            : MaybeBoolExpr 
+         child returning      : MaybeSelectList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Delete:
+         child ann            : Annotation 
+         child table          : Name 
+         child using          : TableRefList 
+         child whr            : MaybeBoolExpr 
+         child returning      : MaybeSelectList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CopyFrom:
+         child ann            : Annotation 
+         child table          : Name 
+         child targetCols     : {[NameComponent]}
+         child source         : {CopyFromSource}
+         child opts           : {[CopyFromOption]}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CopyData:
+         child ann            : Annotation 
+         child insData        : {String}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CopyTo:
+         child ann            : Annotation 
+         child cp             : {CopyToSource}
+         child fn             : {String}
+         child opts           : {[CopyToOption]}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Truncate:
+         child ann            : Annotation 
+         child tables         : {[Name]}
+         child restartIdentity : {RestartIdentity}
+         child cascade        : {Cascade}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CreateTable:
+         child ann            : Annotation 
+         child name           : Name 
+         child atts           : AttributeDefList 
+         child cons           : ConstraintList 
+         child partition      : MaybeTablePartitionDef 
+         child rep            : {Replace}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterTable:
+         child ann            : Annotation 
+         child name           : Name 
+         child operation      : AlterTableOperation 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterDatabase:
+         child ann            : Annotation 
+         child name           : Name 
+         child operation      : AlterDatabaseOperation 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CreateSequence:
+         child ann            : Annotation 
+         child name           : Name 
+         child incr           : {Integer}
+         child min            : {Maybe Integer}
+         child max            : {Maybe Integer}
+         child start          : {Integer}
+         child cache          : {Integer}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterSequence:
+         child ann            : Annotation 
+         child name           : Name 
+         child operation      : AlterSequenceOperation 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CreateTableAs:
+         child ann            : Annotation 
+         child name           : Name 
+         child rep            : {Replace}
+         child expr           : QueryExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CreateView:
+         child ann            : Annotation 
+         child name           : Name 
+         child colNames       : {MaybeNameComponentList}
+         child expr           : QueryExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterView:
+         child ann            : Annotation 
+         child name           : Name 
+         child colNames       : {MaybeNameComponentList}
+         child expr           : QueryExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CreateType:
+         child ann            : Annotation 
+         child name           : Name 
+         child atts           : TypeAttributeDefList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CreateUser:
+         child ann            : Annotation 
+         child name           : Name 
+         child password       : {String}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CreateLogin:
+         child ann            : Annotation 
+         child name           : Name 
+         child password       : {String}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterUser:
+         child ann            : Annotation 
+         child name           : Name 
+         child password       : {String}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterLogin:
+         child ann            : Annotation 
+         child name           : Name 
+         child password       : {String}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CreateSchema:
+         child ann            : Annotation 
+         child name           : {NameComponent}
+         child owner          : {Maybe Name}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AlterSchema:
+         child ann            : Annotation 
+         child name           : {NameComponent}
+         child operation      : AlterSchemaOperation 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CreateFunction:
+         child ann            : Annotation 
+         child name           : Name 
+         child params         : ParamDefList 
+         child rettype        : TypeName 
+         child rep            : {Replace}
+         child lang           : {Language}
+         child body           : FnBody 
+         child vol            : {Volatility}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CreateDomain:
+         child ann            : Annotation 
+         child name           : Name 
+         child typ            : TypeName 
+         child constraintName : {String}
+         child check          : MaybeBoolExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CreateLanguage:
+         child ann            : Annotation 
+         child name           : {String}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CreateTrigger:
+         child ann            : Annotation 
+         child name           : {NameComponent}
+         child wh             : {TriggerWhen}
+         child events         : {[TriggerEvent]}
+         child tbl            : Name 
+         child firing         : {TriggerFire}
+         child fnName         : Name 
+         child fnArgs         : ScalarExprList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative DropFunction:
+         child ann            : Annotation 
+         child ifE            : {IfExists}
+         child sigs           : NameTypeNameListPairList 
+         child cascade        : {Cascade}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative DropSomething:
+         child ann            : Annotation 
+         child dropType       : {DropType}
+         child ifE            : {IfExists}
+         child names          : {[Name]}
+         child cascade        : {Cascade}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative DropTrigger:
+         child ann            : Annotation 
+         child ifE            : {IfExists}
+         child name           : {NameComponent}
+         child tbl            : Name 
+         child cascade        : {Cascade}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CreateDatabase:
+         child ann            : Annotation 
+         child nm             : Name 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Set:
+         child ann            : Annotation 
+         child name           : {String}
+         child values         : {[SetValue]}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Notify:
+         child ann            : Annotation 
+         child name           : {String}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Into:
+         child ann            : Annotation 
+         child strict         : {Bool}
+         child into           : {[Name]}
+         child stmt           : Statement 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Assignment:
+         child ann            : Annotation 
+         child target         : Name 
+         child value          : ScalarExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Return:
+         child ann            : Annotation 
+         child value          : MaybeScalarExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative ReturnNext:
+         child ann            : Annotation 
+         child expr           : ScalarExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative ReturnQuery:
+         child ann            : Annotation 
+         child sel            : QueryExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Raise:
+         child ann            : Annotation 
+         child level          : {RaiseType}
+         child message        : {String}
+         child args           : ScalarExprList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative NullStatement:
+         child ann            : Annotation 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Perform:
+         child ann            : Annotation 
+         child expr           : ScalarExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Execute:
+         child ann            : Annotation 
+         child expr           : ScalarExpr 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative ForQueryStatement:
+         child ann            : Annotation 
+         child lb             : {Maybe String}
+         child var            : {NameComponent}
+         child sel            : QueryExpr 
+         child sts            : StatementList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative ForIntegerStatement:
+         child ann            : Annotation 
+         child lb             : {Maybe String}
+         child var            : {NameComponent}
+         child from           : ScalarExpr 
+         child to             : ScalarExpr 
+         child sts            : StatementList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative LoopStatement:
+         child ann            : Annotation 
+         child lb             : {Maybe String}
+         child sts            : StatementList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative WhileStatement:
+         child ann            : Annotation 
+         child lb             : {Maybe String}
+         child expr           : ScalarExpr 
+         child sts            : StatementList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative ContinueStatement:
+         child ann            : Annotation 
+         child lb             : {Maybe String}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative ExitStatement:
+         child ann            : Annotation 
+         child lb             : {Maybe String}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CaseStatementSimple:
+         child ann            : Annotation 
+         child val            : ScalarExpr 
+         child cases          : ScalarExprListStatementListTripleList 
+         child els            : StatementList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CaseStatement:
+         child ann            : Annotation 
+         child cases          : ScalarExprListStatementListTripleList 
+         child els            : StatementList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative If:
+         child ann            : Annotation 
+         child cases          : ScalarExprStatementListPairList 
+         child els            : StatementList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Block:
+         child ann            : Annotation 
+         child lb             : {Maybe String}
+         child vars           : VarDefList 
+         child sts            : StatementList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative AntiStatement:
+         child string         : {String}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative DeclareStatement:
+         child ann            : Annotation 
+         child ds             : {[(String,TypeName,Maybe ScalarExpr)]}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative ExecStatement:
+         child ann            : Annotation 
+         child spName         : Name 
+         child args           : ScalarExprList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative CreateIndexTSQL:
+         child ann            : Annotation 
+         child nm             : {NameComponent}
+         child obj            : Name 
+         child cols           : {[NameComponent]}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data Statement = QueryStatement (Annotation) (QueryExpr)
+               | Insert (Annotation) (Name) (([NameComponent])) (QueryExpr) (MaybeSelectList)
+               | Update (Annotation) (Name) (SetClauseList) (TableRefList) (MaybeBoolExpr) (MaybeSelectList)
+               | Delete (Annotation) (Name) (TableRefList) (MaybeBoolExpr) (MaybeSelectList)
+               | CopyFrom (Annotation) (Name) (([NameComponent])) (CopyFromSource) (([CopyFromOption]))
+               | CopyData (Annotation) (String)
+               | CopyTo (Annotation) (CopyToSource) (String) (([CopyToOption]))
+               | Truncate (Annotation) (([Name])) (RestartIdentity) (Cascade)
+               | CreateTable (Annotation) (Name) (AttributeDefList) (ConstraintList) (MaybeTablePartitionDef) (Replace)
+               | AlterTable (Annotation) (Name) (AlterTableOperation)
+               | AlterDatabase (Annotation) (Name) (AlterDatabaseOperation)
+               | CreateSequence (Annotation) (Name) (Integer) ((Maybe Integer)) ((Maybe Integer)) (Integer) (Integer)
+               | AlterSequence (Annotation) (Name) (AlterSequenceOperation)
+               | CreateTableAs (Annotation) (Name) (Replace) (QueryExpr)
+               | CreateView (Annotation) (Name) (MaybeNameComponentList) (QueryExpr)
+               | AlterView (Annotation) (Name) (MaybeNameComponentList) (QueryExpr)
+               | CreateType (Annotation) (Name) (TypeAttributeDefList)
+               | CreateUser (Annotation) (Name) (String)
+               | CreateLogin (Annotation) (Name) (String)
+               | AlterUser (Annotation) (Name) (String)
+               | AlterLogin (Annotation) (Name) (String)
+               | CreateSchema (Annotation) (NameComponent) ((Maybe Name))
+               | AlterSchema (Annotation) (NameComponent) (AlterSchemaOperation)
+               | CreateFunction (Annotation) (Name) (ParamDefList) (TypeName) (Replace) (Language) (FnBody) (Volatility)
+               | CreateDomain (Annotation) (Name) (TypeName) (String) (MaybeBoolExpr)
+               | CreateLanguage (Annotation) (String)
+               | CreateTrigger (Annotation) (NameComponent) (TriggerWhen) (([TriggerEvent])) (Name) (TriggerFire) (Name) (ScalarExprList)
+               | DropFunction (Annotation) (IfExists) (NameTypeNameListPairList) (Cascade)
+               | DropSomething (Annotation) (DropType) (IfExists) (([Name])) (Cascade)
+               | DropTrigger (Annotation) (IfExists) (NameComponent) (Name) (Cascade)
+               | CreateDatabase (Annotation) (Name)
+               | Set (Annotation) (String) (([SetValue]))
+               | Notify (Annotation) (String)
+               | Into (Annotation) (Bool) (([Name])) (Statement)
+               | Assignment (Annotation) (Name) (ScalarExpr)
+               | Return (Annotation) (MaybeScalarExpr)
+               | ReturnNext (Annotation) (ScalarExpr)
+               | ReturnQuery (Annotation) (QueryExpr)
+               | Raise (Annotation) (RaiseType) (String) (ScalarExprList)
+               | NullStatement (Annotation)
+               | Perform (Annotation) (ScalarExpr)
+               | Execute (Annotation) (ScalarExpr)
+               | ForQueryStatement (Annotation) ((Maybe String)) (NameComponent) (QueryExpr) (StatementList)
+               | ForIntegerStatement (Annotation) ((Maybe String)) (NameComponent) (ScalarExpr) (ScalarExpr) (StatementList)
+               | LoopStatement (Annotation) ((Maybe String)) (StatementList)
+               | WhileStatement (Annotation) ((Maybe String)) (ScalarExpr) (StatementList)
+               | ContinueStatement (Annotation) ((Maybe String))
+               | ExitStatement (Annotation) ((Maybe String))
+               | CaseStatementSimple (Annotation) (ScalarExpr) (ScalarExprListStatementListTripleList) (StatementList)
+               | CaseStatement (Annotation) (ScalarExprListStatementListTripleList) (StatementList)
+               | If (Annotation) (ScalarExprStatementListPairList) (StatementList)
+               | Block (Annotation) ((Maybe String)) (VarDefList) (StatementList)
+               | AntiStatement (String)
+               | DeclareStatement (Annotation) (([(String,TypeName,Maybe ScalarExpr)]))
+               | ExecStatement (Annotation) (Name) (ScalarExprList)
+               | CreateIndexTSQL (Annotation) (NameComponent) (Name) (([NameComponent]))
+               deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_Statement :: Statement ->
+                 T_Statement
+_sem_Statement (QueryStatement _ann _ex) =
+    (_sem_Statement_QueryStatement (_sem_Annotation _ann) (_sem_QueryExpr _ex))
+_sem_Statement (Insert _ann _table _targetCols _insData _returning) =
+    (_sem_Statement_Insert (_sem_Annotation _ann) (_sem_Name _table) _targetCols (_sem_QueryExpr _insData) (_sem_MaybeSelectList _returning))
+_sem_Statement (Update _ann _table _assigns _fromList _whr _returning) =
+    (_sem_Statement_Update (_sem_Annotation _ann) (_sem_Name _table) (_sem_SetClauseList _assigns) (_sem_TableRefList _fromList) (_sem_MaybeBoolExpr _whr) (_sem_MaybeSelectList _returning))
+_sem_Statement (Delete _ann _table _using _whr _returning) =
+    (_sem_Statement_Delete (_sem_Annotation _ann) (_sem_Name _table) (_sem_TableRefList _using) (_sem_MaybeBoolExpr _whr) (_sem_MaybeSelectList _returning))
+_sem_Statement (CopyFrom _ann _table _targetCols _source _opts) =
+    (_sem_Statement_CopyFrom (_sem_Annotation _ann) (_sem_Name _table) _targetCols _source _opts)
+_sem_Statement (CopyData _ann _insData) =
+    (_sem_Statement_CopyData (_sem_Annotation _ann) _insData)
+_sem_Statement (CopyTo _ann _cp _fn _opts) =
+    (_sem_Statement_CopyTo (_sem_Annotation _ann) _cp _fn _opts)
+_sem_Statement (Truncate _ann _tables _restartIdentity _cascade) =
+    (_sem_Statement_Truncate (_sem_Annotation _ann) _tables _restartIdentity _cascade)
+_sem_Statement (CreateTable _ann _name _atts _cons _partition _rep) =
+    (_sem_Statement_CreateTable (_sem_Annotation _ann) (_sem_Name _name) (_sem_AttributeDefList _atts) (_sem_ConstraintList _cons) (_sem_MaybeTablePartitionDef _partition) _rep)
+_sem_Statement (AlterTable _ann _name _operation) =
+    (_sem_Statement_AlterTable (_sem_Annotation _ann) (_sem_Name _name) (_sem_AlterTableOperation _operation))
+_sem_Statement (AlterDatabase _ann _name _operation) =
+    (_sem_Statement_AlterDatabase (_sem_Annotation _ann) (_sem_Name _name) (_sem_AlterDatabaseOperation _operation))
+_sem_Statement (CreateSequence _ann _name _incr _min _max _start _cache) =
+    (_sem_Statement_CreateSequence (_sem_Annotation _ann) (_sem_Name _name) _incr _min _max _start _cache)
+_sem_Statement (AlterSequence _ann _name _operation) =
+    (_sem_Statement_AlterSequence (_sem_Annotation _ann) (_sem_Name _name) (_sem_AlterSequenceOperation _operation))
+_sem_Statement (CreateTableAs _ann _name _rep _expr) =
+    (_sem_Statement_CreateTableAs (_sem_Annotation _ann) (_sem_Name _name) _rep (_sem_QueryExpr _expr))
+_sem_Statement (CreateView _ann _name _colNames _expr) =
+    (_sem_Statement_CreateView (_sem_Annotation _ann) (_sem_Name _name) _colNames (_sem_QueryExpr _expr))
+_sem_Statement (AlterView _ann _name _colNames _expr) =
+    (_sem_Statement_AlterView (_sem_Annotation _ann) (_sem_Name _name) _colNames (_sem_QueryExpr _expr))
+_sem_Statement (CreateType _ann _name _atts) =
+    (_sem_Statement_CreateType (_sem_Annotation _ann) (_sem_Name _name) (_sem_TypeAttributeDefList _atts))
+_sem_Statement (CreateUser _ann _name _password) =
+    (_sem_Statement_CreateUser (_sem_Annotation _ann) (_sem_Name _name) _password)
+_sem_Statement (CreateLogin _ann _name _password) =
+    (_sem_Statement_CreateLogin (_sem_Annotation _ann) (_sem_Name _name) _password)
+_sem_Statement (AlterUser _ann _name _password) =
+    (_sem_Statement_AlterUser (_sem_Annotation _ann) (_sem_Name _name) _password)
+_sem_Statement (AlterLogin _ann _name _password) =
+    (_sem_Statement_AlterLogin (_sem_Annotation _ann) (_sem_Name _name) _password)
+_sem_Statement (CreateSchema _ann _name _owner) =
+    (_sem_Statement_CreateSchema (_sem_Annotation _ann) _name _owner)
+_sem_Statement (AlterSchema _ann _name _operation) =
+    (_sem_Statement_AlterSchema (_sem_Annotation _ann) _name (_sem_AlterSchemaOperation _operation))
+_sem_Statement (CreateFunction _ann _name _params _rettype _rep _lang _body _vol) =
+    (_sem_Statement_CreateFunction (_sem_Annotation _ann) (_sem_Name _name) (_sem_ParamDefList _params) (_sem_TypeName _rettype) _rep _lang (_sem_FnBody _body) _vol)
+_sem_Statement (CreateDomain _ann _name _typ _constraintName _check) =
+    (_sem_Statement_CreateDomain (_sem_Annotation _ann) (_sem_Name _name) (_sem_TypeName _typ) _constraintName (_sem_MaybeBoolExpr _check))
+_sem_Statement (CreateLanguage _ann _name) =
+    (_sem_Statement_CreateLanguage (_sem_Annotation _ann) _name)
+_sem_Statement (CreateTrigger _ann _name _wh _events _tbl _firing _fnName _fnArgs) =
+    (_sem_Statement_CreateTrigger (_sem_Annotation _ann) _name _wh _events (_sem_Name _tbl) _firing (_sem_Name _fnName) (_sem_ScalarExprList _fnArgs))
+_sem_Statement (DropFunction _ann _ifE _sigs _cascade) =
+    (_sem_Statement_DropFunction (_sem_Annotation _ann) _ifE (_sem_NameTypeNameListPairList _sigs) _cascade)
+_sem_Statement (DropSomething _ann _dropType _ifE _names _cascade) =
+    (_sem_Statement_DropSomething (_sem_Annotation _ann) _dropType _ifE _names _cascade)
+_sem_Statement (DropTrigger _ann _ifE _name _tbl _cascade) =
+    (_sem_Statement_DropTrigger (_sem_Annotation _ann) _ifE _name (_sem_Name _tbl) _cascade)
+_sem_Statement (CreateDatabase _ann _nm) =
+    (_sem_Statement_CreateDatabase (_sem_Annotation _ann) (_sem_Name _nm))
+_sem_Statement (Set _ann _name _values) =
+    (_sem_Statement_Set (_sem_Annotation _ann) _name _values)
+_sem_Statement (Notify _ann _name) =
+    (_sem_Statement_Notify (_sem_Annotation _ann) _name)
+_sem_Statement (Into _ann _strict _into _stmt) =
+    (_sem_Statement_Into (_sem_Annotation _ann) _strict _into (_sem_Statement _stmt))
+_sem_Statement (Assignment _ann _target _value) =
+    (_sem_Statement_Assignment (_sem_Annotation _ann) (_sem_Name _target) (_sem_ScalarExpr _value))
+_sem_Statement (Return _ann _value) =
+    (_sem_Statement_Return (_sem_Annotation _ann) (_sem_MaybeScalarExpr _value))
+_sem_Statement (ReturnNext _ann _expr) =
+    (_sem_Statement_ReturnNext (_sem_Annotation _ann) (_sem_ScalarExpr _expr))
+_sem_Statement (ReturnQuery _ann _sel) =
+    (_sem_Statement_ReturnQuery (_sem_Annotation _ann) (_sem_QueryExpr _sel))
+_sem_Statement (Raise _ann _level _message _args) =
+    (_sem_Statement_Raise (_sem_Annotation _ann) _level _message (_sem_ScalarExprList _args))
+_sem_Statement (NullStatement _ann) =
+    (_sem_Statement_NullStatement (_sem_Annotation _ann))
+_sem_Statement (Perform _ann _expr) =
+    (_sem_Statement_Perform (_sem_Annotation _ann) (_sem_ScalarExpr _expr))
+_sem_Statement (Execute _ann _expr) =
+    (_sem_Statement_Execute (_sem_Annotation _ann) (_sem_ScalarExpr _expr))
+_sem_Statement (ForQueryStatement _ann _lb _var _sel _sts) =
+    (_sem_Statement_ForQueryStatement (_sem_Annotation _ann) _lb _var (_sem_QueryExpr _sel) (_sem_StatementList _sts))
+_sem_Statement (ForIntegerStatement _ann _lb _var _from _to _sts) =
+    (_sem_Statement_ForIntegerStatement (_sem_Annotation _ann) _lb _var (_sem_ScalarExpr _from) (_sem_ScalarExpr _to) (_sem_StatementList _sts))
+_sem_Statement (LoopStatement _ann _lb _sts) =
+    (_sem_Statement_LoopStatement (_sem_Annotation _ann) _lb (_sem_StatementList _sts))
+_sem_Statement (WhileStatement _ann _lb _expr _sts) =
+    (_sem_Statement_WhileStatement (_sem_Annotation _ann) _lb (_sem_ScalarExpr _expr) (_sem_StatementList _sts))
+_sem_Statement (ContinueStatement _ann _lb) =
+    (_sem_Statement_ContinueStatement (_sem_Annotation _ann) _lb)
+_sem_Statement (ExitStatement _ann _lb) =
+    (_sem_Statement_ExitStatement (_sem_Annotation _ann) _lb)
+_sem_Statement (CaseStatementSimple _ann _val _cases _els) =
+    (_sem_Statement_CaseStatementSimple (_sem_Annotation _ann) (_sem_ScalarExpr _val) (_sem_ScalarExprListStatementListTripleList _cases) (_sem_StatementList _els))
+_sem_Statement (CaseStatement _ann _cases _els) =
+    (_sem_Statement_CaseStatement (_sem_Annotation _ann) (_sem_ScalarExprListStatementListTripleList _cases) (_sem_StatementList _els))
+_sem_Statement (If _ann _cases _els) =
+    (_sem_Statement_If (_sem_Annotation _ann) (_sem_ScalarExprStatementListPairList _cases) (_sem_StatementList _els))
+_sem_Statement (Block _ann _lb _vars _sts) =
+    (_sem_Statement_Block (_sem_Annotation _ann) _lb (_sem_VarDefList _vars) (_sem_StatementList _sts))
+_sem_Statement (AntiStatement _string) =
+    (_sem_Statement_AntiStatement _string)
+_sem_Statement (DeclareStatement _ann _ds) =
+    (_sem_Statement_DeclareStatement (_sem_Annotation _ann) _ds)
+_sem_Statement (ExecStatement _ann _spName _args) =
+    (_sem_Statement_ExecStatement (_sem_Annotation _ann) (_sem_Name _spName) (_sem_ScalarExprList _args))
+_sem_Statement (CreateIndexTSQL _ann _nm _obj _cols) =
+    (_sem_Statement_CreateIndexTSQL (_sem_Annotation _ann) _nm (_sem_Name _obj) _cols)
+-- semantic domain
+type T_Statement = Catalog ->
+                   TypeCheckFlags ->
+                   (Maybe TypeExtra) ->
+                   ( Statement,Statement)
+data Inh_Statement = Inh_Statement {_cat_Inh_Statement :: Catalog,_flags_Inh_Statement :: TypeCheckFlags,_imCast_Inh_Statement :: (Maybe TypeExtra)}
+data Syn_Statement = Syn_Statement {_annotatedTree_Syn_Statement :: Statement,_originalTree_Syn_Statement :: Statement}
+_wrap_Statement :: T_Statement ->
+                  Inh_Statement ->
+                  Syn_Statement
+_wrap_Statement sem (Inh_Statement _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_Statement _lhsOannotatedTree _lhsOoriginalTree))
+_sem_Statement_QueryStatement :: T_Annotation ->
+                                T_QueryExpr ->
+                                T_Statement
+_sem_Statement_QueryStatement ann_ ex_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _exOexpectedType :: (Maybe [TypeExtra])
+              _exOouterDownEnv :: (Maybe Environment)
+              _exOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _exOcat :: Catalog
+              _exOflags :: TypeCheckFlags
+              _exOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exIannotatedTree :: QueryExpr
+              _exIoriginalTree :: QueryExpr
+              _exIupType :: (Maybe [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 13, column 5)
+              _annOtpe =
+                  ({-# LINE 13 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag" #-}
+                   Left []
+                   {-# LINE 19671 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 16, column 5)
+              _exOexpectedType =
+                  ({-# LINE 16 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag" #-}
+                   liftM (map snd) _exIupType
+                   {-# LINE 19677 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 91, column 20)
+              _exOouterDownEnv =
+                  ({-# LINE 91 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   Nothing
+                   {-# LINE 19683 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 837, column 32)
+              _exOassignmentCastContext =
+                  ({-# LINE 837 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 19689 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   QueryStatement _annIannotatedTree _exIannotatedTree
+                   {-# LINE 19695 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   QueryStatement _annIoriginalTree _exIoriginalTree
+                   {-# LINE 19701 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 19707 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 19713 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 19719 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 19725 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 19731 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 19737 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 19743 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 19749 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exIannotatedTree,_exIoriginalTree,_exIupType) =
+                  ex_ _exOassignmentCastContext _exOcat _exOexpectedType _exOflags _exOimCast _exOouterDownEnv
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_Insert :: T_Annotation ->
+                        T_Name ->
+                        ([NameComponent]) ->
+                        T_QueryExpr ->
+                        T_MaybeSelectList ->
+                        T_Statement
+_sem_Statement_Insert ann_ table_ targetCols_ insData_ returning_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _tpe :: (Either [TypeError] [TypeExtra])
+              _tableOtpe :: (Either [TypeError] TypeExtra)
+              _insDataOexpectedType :: (Maybe [TypeExtra])
+              _insDataOouterDownEnv :: (Maybe Environment)
+              _tooManyCols :: (Maybe [TypeError])
+              _insDataOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _tableOcat :: Catalog
+              _tableOflags :: TypeCheckFlags
+              _tableOimCast :: (Maybe TypeExtra)
+              _insDataOcat :: Catalog
+              _insDataOflags :: TypeCheckFlags
+              _insDataOimCast :: (Maybe TypeExtra)
+              _returningOcat :: Catalog
+              _returningOflags :: TypeCheckFlags
+              _returningOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _tableIannotatedTree :: Name
+              _tableIoriginalTree :: Name
+              _insDataIannotatedTree :: QueryExpr
+              _insDataIoriginalTree :: QueryExpr
+              _insDataIupType :: (Maybe [(Text,TypeExtra)])
+              _returningIannotatedTree :: MaybeSelectList
+              _returningIoriginalTree :: MaybeSelectList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag"(line 19, column 5)
+              _annOtpe =
+                  ({-# LINE 19 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag" #-}
+                   Left []
+                   {-# LINE 19800 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag"(line 25, column 5)
+              _tpe =
+                  ({-# LINE 25 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag" #-}
+                   do
+                   let tnm = nameComponents _tableIoriginalTree
+                   (_,pub,_) <- catLookupTableAndAttrs _lhsIcat tnm
+                   case targetCols_ of
+                        []  -> return $ map snd pub
+                        tcs -> do
+                               tcs' <- mapM xnmcString tcs
+                               let utcs' = nub tcs'
+                               when (length utcs' /= length tcs') $
+                                   Left $ map DuplicateColumnName
+                                        $ nub (tcs' \\ utcs')
+                               forM tcs' $ \x ->
+                                   maybe (Left [UnrecognisedIdentifier x])
+                                         Right $ lookup x pub
+                   {-# LINE 19819 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag"(line 44, column 5)
+              _tableOtpe =
+                  ({-# LINE 44 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag" #-}
+                   Left (either id (const []) _tpe
+                         ++ maybe [] id _tooManyCols    )
+                   {-# LINE 19826 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag"(line 47, column 5)
+              _insDataOexpectedType =
+                  ({-# LINE 47 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 19832 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag"(line 49, column 5)
+              _insDataOouterDownEnv =
+                  ({-# LINE 49 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag" #-}
+                   Nothing
+                   {-# LINE 19838 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag"(line 54, column 5)
+              _tooManyCols =
+                  ({-# LINE 54 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag" #-}
+                   do
+                   x <- _insDataIupType
+                   y <- either (const Nothing) Just _tpe
+                   if (length x > length y)
+                       then Just [TooManyColumnsInInsert]
+                       else Nothing
+                   {-# LINE 19849 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 835, column 24)
+              _insDataOassignmentCastContext =
+                  ({-# LINE 835 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 19855 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Insert _annIannotatedTree _tableIannotatedTree targetCols_ _insDataIannotatedTree _returningIannotatedTree
+                   {-# LINE 19861 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Insert _annIoriginalTree _tableIoriginalTree targetCols_ _insDataIoriginalTree _returningIoriginalTree
+                   {-# LINE 19867 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 19873 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 19879 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 19885 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 19891 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 19897 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 19903 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 19909 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 19915 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _insDataOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 19921 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _insDataOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 19927 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _insDataOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 19933 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _returningOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 19939 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _returningOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 19945 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _returningOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 19951 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _tableIannotatedTree,_tableIoriginalTree) =
+                  table_ _tableOcat _tableOflags _tableOimCast _tableOtpe
+              ( _insDataIannotatedTree,_insDataIoriginalTree,_insDataIupType) =
+                  insData_ _insDataOassignmentCastContext _insDataOcat _insDataOexpectedType _insDataOflags _insDataOimCast _insDataOouterDownEnv
+              ( _returningIannotatedTree,_returningIoriginalTree) =
+                  returning_ _returningOcat _returningOflags _returningOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_Update :: T_Annotation ->
+                        T_Name ->
+                        T_SetClauseList ->
+                        T_TableRefList ->
+                        T_MaybeBoolExpr ->
+                        T_MaybeSelectList ->
+                        T_Statement
+_sem_Statement_Update ann_ table_ assigns_ fromList_ whr_ returning_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _tableOtpe :: (Either [TypeError] TypeExtra)
+              _whrOdownEnv :: Environment
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _tableOcat :: Catalog
+              _tableOflags :: TypeCheckFlags
+              _tableOimCast :: (Maybe TypeExtra)
+              _assignsOcat :: Catalog
+              _assignsOflags :: TypeCheckFlags
+              _assignsOimCast :: (Maybe TypeExtra)
+              _fromListOcat :: Catalog
+              _fromListOflags :: TypeCheckFlags
+              _fromListOimCast :: (Maybe TypeExtra)
+              _whrOcat :: Catalog
+              _whrOflags :: TypeCheckFlags
+              _whrOimCast :: (Maybe TypeExtra)
+              _returningOcat :: Catalog
+              _returningOflags :: TypeCheckFlags
+              _returningOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _tableIannotatedTree :: Name
+              _tableIoriginalTree :: Name
+              _assignsIannotatedTree :: SetClauseList
+              _assignsIoriginalTree :: SetClauseList
+              _fromListIannotatedTree :: TableRefList
+              _fromListIoriginalTree :: TableRefList
+              _fromListIupEnv :: Environment
+              _whrIannotatedTree :: MaybeBoolExpr
+              _whrIoriginalTree :: MaybeBoolExpr
+              _returningIannotatedTree :: MaybeSelectList
+              _returningIoriginalTree :: MaybeSelectList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 219, column 24)
+              _tableOtpe =
+                  ({-# LINE 219 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 20013 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 220, column 24)
+              _whrOdownEnv =
+                  ({-# LINE 220 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 20019 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag"(line 19, column 5)
+              _annOtpe =
+                  ({-# LINE 19 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag" #-}
+                   Left []
+                   {-# LINE 20025 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Update _annIannotatedTree _tableIannotatedTree _assignsIannotatedTree _fromListIannotatedTree _whrIannotatedTree _returningIannotatedTree
+                   {-# LINE 20031 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Update _annIoriginalTree _tableIoriginalTree _assignsIoriginalTree _fromListIoriginalTree _whrIoriginalTree _returningIoriginalTree
+                   {-# LINE 20037 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 20043 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 20049 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20055 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20061 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20067 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20073 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20079 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20085 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _assignsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20091 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _assignsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20097 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _assignsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20103 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fromListOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20109 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fromListOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20115 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fromListOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20121 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _whrOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20127 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _whrOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20133 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _whrOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20139 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _returningOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20145 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _returningOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20151 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _returningOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20157 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _tableIannotatedTree,_tableIoriginalTree) =
+                  table_ _tableOcat _tableOflags _tableOimCast _tableOtpe
+              ( _assignsIannotatedTree,_assignsIoriginalTree) =
+                  assigns_ _assignsOcat _assignsOflags _assignsOimCast
+              ( _fromListIannotatedTree,_fromListIoriginalTree,_fromListIupEnv) =
+                  fromList_ _fromListOcat _fromListOflags _fromListOimCast
+              ( _whrIannotatedTree,_whrIoriginalTree) =
+                  whr_ _whrOcat _whrOdownEnv _whrOflags _whrOimCast
+              ( _returningIannotatedTree,_returningIoriginalTree) =
+                  returning_ _returningOcat _returningOflags _returningOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_Delete :: T_Annotation ->
+                        T_Name ->
+                        T_TableRefList ->
+                        T_MaybeBoolExpr ->
+                        T_MaybeSelectList ->
+                        T_Statement
+_sem_Statement_Delete ann_ table_ using_ whr_ returning_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _tableOtpe :: (Either [TypeError] TypeExtra)
+              _whrOdownEnv :: Environment
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _tableOcat :: Catalog
+              _tableOflags :: TypeCheckFlags
+              _tableOimCast :: (Maybe TypeExtra)
+              _usingOcat :: Catalog
+              _usingOflags :: TypeCheckFlags
+              _usingOimCast :: (Maybe TypeExtra)
+              _whrOcat :: Catalog
+              _whrOflags :: TypeCheckFlags
+              _whrOimCast :: (Maybe TypeExtra)
+              _returningOcat :: Catalog
+              _returningOflags :: TypeCheckFlags
+              _returningOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _tableIannotatedTree :: Name
+              _tableIoriginalTree :: Name
+              _usingIannotatedTree :: TableRefList
+              _usingIoriginalTree :: TableRefList
+              _usingIupEnv :: Environment
+              _whrIannotatedTree :: MaybeBoolExpr
+              _whrIoriginalTree :: MaybeBoolExpr
+              _returningIannotatedTree :: MaybeSelectList
+              _returningIoriginalTree :: MaybeSelectList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 170, column 24)
+              _tableOtpe =
+                  ({-# LINE 170 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 20217 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 171, column 24)
+              _whrOdownEnv =
+                  ({-# LINE 171 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 20223 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag"(line 19, column 5)
+              _annOtpe =
+                  ({-# LINE 19 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag" #-}
+                   Left []
+                   {-# LINE 20229 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Delete _annIannotatedTree _tableIannotatedTree _usingIannotatedTree _whrIannotatedTree _returningIannotatedTree
+                   {-# LINE 20235 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Delete _annIoriginalTree _tableIoriginalTree _usingIoriginalTree _whrIoriginalTree _returningIoriginalTree
+                   {-# LINE 20241 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 20247 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 20253 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20259 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20265 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20271 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20277 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20283 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20289 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _usingOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20295 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _usingOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20301 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _usingOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20307 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _whrOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20313 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _whrOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20319 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _whrOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20325 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _returningOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20331 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _returningOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20337 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _returningOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20343 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _tableIannotatedTree,_tableIoriginalTree) =
+                  table_ _tableOcat _tableOflags _tableOimCast _tableOtpe
+              ( _usingIannotatedTree,_usingIoriginalTree,_usingIupEnv) =
+                  using_ _usingOcat _usingOflags _usingOimCast
+              ( _whrIannotatedTree,_whrIoriginalTree) =
+                  whr_ _whrOcat _whrOdownEnv _whrOflags _whrOimCast
+              ( _returningIannotatedTree,_returningIoriginalTree) =
+                  returning_ _returningOcat _returningOflags _returningOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CopyFrom :: T_Annotation ->
+                          T_Name ->
+                          ([NameComponent]) ->
+                          CopyFromSource ->
+                          ([CopyFromOption]) ->
+                          T_Statement
+_sem_Statement_CopyFrom ann_ table_ targetCols_ source_ opts_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _tableOtpe :: (Either [TypeError] TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _tableOcat :: Catalog
+              _tableOflags :: TypeCheckFlags
+              _tableOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _tableIannotatedTree :: Name
+              _tableIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 137, column 26)
+              _tableOtpe =
+                  ({-# LINE 137 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 20384 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag"(line 19, column 5)
+              _annOtpe =
+                  ({-# LINE 19 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag" #-}
+                   Left []
+                   {-# LINE 20390 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CopyFrom _annIannotatedTree _tableIannotatedTree targetCols_ source_ opts_
+                   {-# LINE 20396 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CopyFrom _annIoriginalTree _tableIoriginalTree targetCols_ source_ opts_
+                   {-# LINE 20402 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 20408 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 20414 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20420 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20426 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20432 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20438 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20444 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tableOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20450 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _tableIannotatedTree,_tableIoriginalTree) =
+                  table_ _tableOcat _tableOflags _tableOimCast _tableOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CopyData :: T_Annotation ->
+                          String ->
+                          T_Statement
+_sem_Statement_CopyData ann_ insData_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 136, column 26)
+              _annOtpe =
+                  ({-# LINE 136 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 20476 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CopyData _annIannotatedTree insData_
+                   {-# LINE 20482 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CopyData _annIoriginalTree insData_
+                   {-# LINE 20488 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 20494 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 20500 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20506 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20512 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20518 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CopyTo :: T_Annotation ->
+                        CopyToSource ->
+                        String ->
+                        ([CopyToOption]) ->
+                        T_Statement
+_sem_Statement_CopyTo ann_ cp_ fn_ opts_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag"(line 19, column 5)
+              _annOtpe =
+                  ({-# LINE 19 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag" #-}
+                   Left []
+                   {-# LINE 20544 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CopyTo _annIannotatedTree cp_ fn_ opts_
+                   {-# LINE 20550 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CopyTo _annIoriginalTree cp_ fn_ opts_
+                   {-# LINE 20556 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 20562 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 20568 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20574 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20580 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20586 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_Truncate :: T_Annotation ->
+                          ([Name]) ->
+                          RestartIdentity ->
+                          Cascade ->
+                          T_Statement
+_sem_Statement_Truncate ann_ tables_ restartIdentity_ cascade_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag"(line 19, column 5)
+              _annOtpe =
+                  ({-# LINE 19 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Updates.ag" #-}
+                   Left []
+                   {-# LINE 20612 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Truncate _annIannotatedTree tables_ restartIdentity_ cascade_
+                   {-# LINE 20618 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Truncate _annIoriginalTree tables_ restartIdentity_ cascade_
+                   {-# LINE 20624 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 20630 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 20636 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20642 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20648 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20654 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CreateTable :: T_Annotation ->
+                             T_Name ->
+                             T_AttributeDefList ->
+                             T_ConstraintList ->
+                             T_MaybeTablePartitionDef ->
+                             Replace ->
+                             T_Statement
+_sem_Statement_CreateTable ann_ name_ atts_ cons_ partition_ rep_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _nameOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nameOcat :: Catalog
+              _nameOflags :: TypeCheckFlags
+              _nameOimCast :: (Maybe TypeExtra)
+              _attsOcat :: Catalog
+              _attsOflags :: TypeCheckFlags
+              _attsOimCast :: (Maybe TypeExtra)
+              _consOcat :: Catalog
+              _consOflags :: TypeCheckFlags
+              _consOimCast :: (Maybe TypeExtra)
+              _partitionOcat :: Catalog
+              _partitionOflags :: TypeCheckFlags
+              _partitionOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nameIannotatedTree :: Name
+              _nameIoriginalTree :: Name
+              _attsIannotatedTree :: AttributeDefList
+              _attsIoriginalTree :: AttributeDefList
+              _consIannotatedTree :: ConstraintList
+              _consIoriginalTree :: ConstraintList
+              _partitionIannotatedTree :: MaybeTablePartitionDef
+              _partitionIoriginalTree :: MaybeTablePartitionDef
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 152, column 29)
+              _annOtpe =
+                  ({-# LINE 152 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 20703 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 153, column 29)
+              _nameOtpe =
+                  ({-# LINE 153 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 20709 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateTable _annIannotatedTree _nameIannotatedTree _attsIannotatedTree _consIannotatedTree _partitionIannotatedTree rep_
+                   {-# LINE 20715 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateTable _annIoriginalTree _nameIoriginalTree _attsIoriginalTree _consIoriginalTree _partitionIoriginalTree rep_
+                   {-# LINE 20721 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 20727 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 20733 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20739 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20745 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20751 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20757 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20763 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20769 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _attsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20775 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _attsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20781 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _attsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20787 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _consOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20793 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _consOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20799 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _consOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20805 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _partitionOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20811 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _partitionOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20817 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _partitionOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20823 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nameIannotatedTree,_nameIoriginalTree) =
+                  name_ _nameOcat _nameOflags _nameOimCast _nameOtpe
+              ( _attsIannotatedTree,_attsIoriginalTree) =
+                  atts_ _attsOcat _attsOflags _attsOimCast
+              ( _consIannotatedTree,_consIoriginalTree) =
+                  cons_ _consOcat _consOflags _consOimCast
+              ( _partitionIannotatedTree,_partitionIoriginalTree) =
+                  partition_ _partitionOcat _partitionOflags _partitionOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_AlterTable :: T_Annotation ->
+                            T_Name ->
+                            T_AlterTableOperation ->
+                            T_Statement
+_sem_Statement_AlterTable ann_ name_ operation_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _nameOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nameOcat :: Catalog
+              _nameOflags :: TypeCheckFlags
+              _nameOimCast :: (Maybe TypeExtra)
+              _operationOcat :: Catalog
+              _operationOflags :: TypeCheckFlags
+              _operationOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nameIannotatedTree :: Name
+              _nameIoriginalTree :: Name
+              _operationIannotatedTree :: AlterTableOperation
+              _operationIoriginalTree :: AlterTableOperation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 117, column 28)
+              _annOtpe =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 20867 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 118, column 28)
+              _nameOtpe =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 20873 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterTable _annIannotatedTree _nameIannotatedTree _operationIannotatedTree
+                   {-# LINE 20879 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterTable _annIoriginalTree _nameIoriginalTree _operationIoriginalTree
+                   {-# LINE 20885 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 20891 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 20897 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20903 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20909 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20915 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20921 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20927 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20933 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _operationOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 20939 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _operationOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 20945 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _operationOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 20951 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nameIannotatedTree,_nameIoriginalTree) =
+                  name_ _nameOcat _nameOflags _nameOimCast _nameOtpe
+              ( _operationIannotatedTree,_operationIoriginalTree) =
+                  operation_ _operationOcat _operationOflags _operationOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_AlterDatabase :: T_Annotation ->
+                               T_Name ->
+                               T_AlterDatabaseOperation ->
+                               T_Statement
+_sem_Statement_AlterDatabase ann_ name_ operation_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _nameOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nameOcat :: Catalog
+              _nameOflags :: TypeCheckFlags
+              _nameOimCast :: (Maybe TypeExtra)
+              _operationOcat :: Catalog
+              _operationOflags :: TypeCheckFlags
+              _operationOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nameIannotatedTree :: Name
+              _nameIoriginalTree :: Name
+              _operationIannotatedTree :: AlterDatabaseOperation
+              _operationIoriginalTree :: AlterDatabaseOperation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 110, column 31)
+              _annOtpe =
+                  ({-# LINE 110 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 20991 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 111, column 31)
+              _nameOtpe =
+                  ({-# LINE 111 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 20997 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterDatabase _annIannotatedTree _nameIannotatedTree _operationIannotatedTree
+                   {-# LINE 21003 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterDatabase _annIoriginalTree _nameIoriginalTree _operationIoriginalTree
+                   {-# LINE 21009 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 21015 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 21021 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21027 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21033 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21039 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21045 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21051 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21057 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _operationOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21063 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _operationOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21069 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _operationOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21075 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nameIannotatedTree,_nameIoriginalTree) =
+                  name_ _nameOcat _nameOflags _nameOimCast _nameOtpe
+              ( _operationIannotatedTree,_operationIoriginalTree) =
+                  operation_ _operationOcat _operationOflags _operationOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CreateSequence :: T_Annotation ->
+                                T_Name ->
+                                Integer ->
+                                (Maybe Integer) ->
+                                (Maybe Integer) ->
+                                Integer ->
+                                Integer ->
+                                T_Statement
+_sem_Statement_CreateSequence ann_ name_ incr_ min_ max_ start_ cache_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _nameOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nameOcat :: Catalog
+              _nameOflags :: TypeCheckFlags
+              _nameOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nameIannotatedTree :: Name
+              _nameIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 150, column 32)
+              _annOtpe =
+                  ({-# LINE 150 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 21114 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 151, column 32)
+              _nameOtpe =
+                  ({-# LINE 151 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 21120 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateSequence _annIannotatedTree _nameIannotatedTree incr_ min_ max_ start_ cache_
+                   {-# LINE 21126 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateSequence _annIoriginalTree _nameIoriginalTree incr_ min_ max_ start_ cache_
+                   {-# LINE 21132 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 21138 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 21144 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21150 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21156 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21162 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21168 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21174 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21180 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nameIannotatedTree,_nameIoriginalTree) =
+                  name_ _nameOcat _nameOflags _nameOimCast _nameOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_AlterSequence :: T_Annotation ->
+                               T_Name ->
+                               T_AlterSequenceOperation ->
+                               T_Statement
+_sem_Statement_AlterSequence ann_ name_ operation_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _nameOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nameOcat :: Catalog
+              _nameOflags :: TypeCheckFlags
+              _nameOimCast :: (Maybe TypeExtra)
+              _operationOcat :: Catalog
+              _operationOflags :: TypeCheckFlags
+              _operationOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nameIannotatedTree :: Name
+              _nameIoriginalTree :: Name
+              _operationIannotatedTree :: AlterSequenceOperation
+              _operationIoriginalTree :: AlterSequenceOperation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 115, column 31)
+              _annOtpe =
+                  ({-# LINE 115 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 21218 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 116, column 31)
+              _nameOtpe =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 21224 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequence _annIannotatedTree _nameIannotatedTree _operationIannotatedTree
+                   {-# LINE 21230 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSequence _annIoriginalTree _nameIoriginalTree _operationIoriginalTree
+                   {-# LINE 21236 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 21242 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 21248 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21254 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21260 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21266 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21272 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21278 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21284 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _operationOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21290 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _operationOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21296 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _operationOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21302 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nameIannotatedTree,_nameIoriginalTree) =
+                  name_ _nameOcat _nameOflags _nameOimCast _nameOtpe
+              ( _operationIannotatedTree,_operationIoriginalTree) =
+                  operation_ _operationOcat _operationOflags _operationOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CreateTableAs :: T_Annotation ->
+                               T_Name ->
+                               Replace ->
+                               T_QueryExpr ->
+                               T_Statement
+_sem_Statement_CreateTableAs ann_ name_ rep_ expr_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _exprOouterDownEnv :: (Maybe Environment)
+              _nameOtpe :: (Either [TypeError] TypeExtra)
+              _exprOexpectedType :: (Maybe [TypeExtra])
+              _exprOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nameOcat :: Catalog
+              _nameOflags :: TypeCheckFlags
+              _nameOimCast :: (Maybe TypeExtra)
+              _exprOcat :: Catalog
+              _exprOflags :: TypeCheckFlags
+              _exprOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nameIannotatedTree :: Name
+              _nameIoriginalTree :: Name
+              _exprIannotatedTree :: QueryExpr
+              _exprIoriginalTree :: QueryExpr
+              _exprIupType :: (Maybe [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 154, column 31)
+              _annOtpe =
+                  ({-# LINE 154 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 21347 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 155, column 31)
+              _exprOouterDownEnv =
+                  ({-# LINE 155 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 21353 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 156, column 31)
+              _nameOtpe =
+                  ({-# LINE 156 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 21359 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 19, column 5)
+              _exprOexpectedType =
+                  ({-# LINE 19 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag" #-}
+                   liftM (map snd) _exprIupType
+                   {-# LINE 21365 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 827, column 31)
+              _exprOassignmentCastContext =
+                  ({-# LINE 827 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 21371 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateTableAs _annIannotatedTree _nameIannotatedTree rep_ _exprIannotatedTree
+                   {-# LINE 21377 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateTableAs _annIoriginalTree _nameIoriginalTree rep_ _exprIoriginalTree
+                   {-# LINE 21383 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 21389 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 21395 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21401 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21407 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21413 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21419 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21425 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21431 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21437 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21443 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21449 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nameIannotatedTree,_nameIoriginalTree) =
+                  name_ _nameOcat _nameOflags _nameOimCast _nameOtpe
+              ( _exprIannotatedTree,_exprIoriginalTree,_exprIupType) =
+                  expr_ _exprOassignmentCastContext _exprOcat _exprOexpectedType _exprOflags _exprOimCast _exprOouterDownEnv
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CreateView :: T_Annotation ->
+                            T_Name ->
+                            MaybeNameComponentList ->
+                            T_QueryExpr ->
+                            T_Statement
+_sem_Statement_CreateView ann_ name_ colNames_ expr_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _exprOouterDownEnv :: (Maybe Environment)
+              _nameOtpe :: (Either [TypeError] TypeExtra)
+              _exprOexpectedType :: (Maybe [TypeExtra])
+              _exprOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nameOcat :: Catalog
+              _nameOflags :: TypeCheckFlags
+              _nameOimCast :: (Maybe TypeExtra)
+              _exprOcat :: Catalog
+              _exprOflags :: TypeCheckFlags
+              _exprOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nameIannotatedTree :: Name
+              _nameIoriginalTree :: Name
+              _exprIannotatedTree :: QueryExpr
+              _exprIoriginalTree :: QueryExpr
+              _exprIupType :: (Maybe [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 167, column 28)
+              _annOtpe =
+                  ({-# LINE 167 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 21494 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 168, column 28)
+              _exprOouterDownEnv =
+                  ({-# LINE 168 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 21500 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 169, column 28)
+              _nameOtpe =
+                  ({-# LINE 169 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 21506 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 19, column 5)
+              _exprOexpectedType =
+                  ({-# LINE 19 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag" #-}
+                   liftM (map snd) _exprIupType
+                   {-# LINE 21512 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 829, column 28)
+              _exprOassignmentCastContext =
+                  ({-# LINE 829 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 21518 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateView _annIannotatedTree _nameIannotatedTree colNames_ _exprIannotatedTree
+                   {-# LINE 21524 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateView _annIoriginalTree _nameIoriginalTree colNames_ _exprIoriginalTree
+                   {-# LINE 21530 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 21536 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 21542 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21548 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21554 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21560 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21566 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21572 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21578 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21584 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21590 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21596 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nameIannotatedTree,_nameIoriginalTree) =
+                  name_ _nameOcat _nameOflags _nameOimCast _nameOtpe
+              ( _exprIannotatedTree,_exprIoriginalTree,_exprIupType) =
+                  expr_ _exprOassignmentCastContext _exprOcat _exprOexpectedType _exprOflags _exprOimCast _exprOouterDownEnv
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_AlterView :: T_Annotation ->
+                           T_Name ->
+                           MaybeNameComponentList ->
+                           T_QueryExpr ->
+                           T_Statement
+_sem_Statement_AlterView ann_ name_ colNames_ expr_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _exprOexpectedType :: (Maybe [TypeExtra])
+              _exprOouterDownEnv :: (Maybe Environment)
+              _nameOtpe :: (Either [TypeError] TypeExtra)
+              _exprOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nameOcat :: Catalog
+              _nameOflags :: TypeCheckFlags
+              _nameOimCast :: (Maybe TypeExtra)
+              _exprOcat :: Catalog
+              _exprOflags :: TypeCheckFlags
+              _exprOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nameIannotatedTree :: Name
+              _nameIoriginalTree :: Name
+              _exprIannotatedTree :: QueryExpr
+              _exprIoriginalTree :: QueryExpr
+              _exprIupType :: (Maybe [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 121, column 27)
+              _annOtpe =
+                  ({-# LINE 121 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 21641 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 122, column 27)
+              _exprOexpectedType =
+                  ({-# LINE 122 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 21647 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 123, column 27)
+              _exprOouterDownEnv =
+                  ({-# LINE 123 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 21653 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 124, column 27)
+              _nameOtpe =
+                  ({-# LINE 124 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 21659 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 824, column 27)
+              _exprOassignmentCastContext =
+                  ({-# LINE 824 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 21665 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterView _annIannotatedTree _nameIannotatedTree colNames_ _exprIannotatedTree
+                   {-# LINE 21671 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterView _annIoriginalTree _nameIoriginalTree colNames_ _exprIoriginalTree
+                   {-# LINE 21677 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 21683 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 21689 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21695 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21701 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21707 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21713 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21719 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21725 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21731 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21737 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21743 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nameIannotatedTree,_nameIoriginalTree) =
+                  name_ _nameOcat _nameOflags _nameOimCast _nameOtpe
+              ( _exprIannotatedTree,_exprIoriginalTree,_exprIupType) =
+                  expr_ _exprOassignmentCastContext _exprOcat _exprOexpectedType _exprOflags _exprOimCast _exprOouterDownEnv
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CreateType :: T_Annotation ->
+                            T_Name ->
+                            T_TypeAttributeDefList ->
+                            T_Statement
+_sem_Statement_CreateType ann_ name_ atts_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _nameOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nameOcat :: Catalog
+              _nameOflags :: TypeCheckFlags
+              _nameOimCast :: (Maybe TypeExtra)
+              _attsOcat :: Catalog
+              _attsOflags :: TypeCheckFlags
+              _attsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nameIannotatedTree :: Name
+              _nameIoriginalTree :: Name
+              _attsIannotatedTree :: TypeAttributeDefList
+              _attsIoriginalTree :: TypeAttributeDefList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 163, column 28)
+              _annOtpe =
+                  ({-# LINE 163 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 21783 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 164, column 28)
+              _nameOtpe =
+                  ({-# LINE 164 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 21789 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateType _annIannotatedTree _nameIannotatedTree _attsIannotatedTree
+                   {-# LINE 21795 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateType _annIoriginalTree _nameIoriginalTree _attsIoriginalTree
+                   {-# LINE 21801 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 21807 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 21813 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21819 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21825 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21831 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21837 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21843 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21849 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _attsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21855 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _attsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21861 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _attsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21867 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nameIannotatedTree,_nameIoriginalTree) =
+                  name_ _nameOcat _nameOflags _nameOimCast _nameOtpe
+              ( _attsIannotatedTree,_attsIoriginalTree) =
+                  atts_ _attsOcat _attsOflags _attsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CreateUser :: T_Annotation ->
+                            T_Name ->
+                            String ->
+                            T_Statement
+_sem_Statement_CreateUser ann_ name_ password_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _nameOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nameOcat :: Catalog
+              _nameOflags :: TypeCheckFlags
+              _nameOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nameIannotatedTree :: Name
+              _nameIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 165, column 28)
+              _annOtpe =
+                  ({-# LINE 165 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 21902 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 166, column 28)
+              _nameOtpe =
+                  ({-# LINE 166 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 21908 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateUser _annIannotatedTree _nameIannotatedTree password_
+                   {-# LINE 21914 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateUser _annIoriginalTree _nameIoriginalTree password_
+                   {-# LINE 21920 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 21926 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 21932 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21938 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21944 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21950 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 21956 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 21962 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 21968 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nameIannotatedTree,_nameIoriginalTree) =
+                  name_ _nameOcat _nameOflags _nameOimCast _nameOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CreateLogin :: T_Annotation ->
+                             T_Name ->
+                             String ->
+                             T_Statement
+_sem_Statement_CreateLogin ann_ name_ password_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _nameOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nameOcat :: Catalog
+              _nameOflags :: TypeCheckFlags
+              _nameOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nameIannotatedTree :: Name
+              _nameIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 147, column 29)
+              _annOtpe =
+                  ({-# LINE 147 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 22001 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 148, column 29)
+              _nameOtpe =
+                  ({-# LINE 148 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 22007 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateLogin _annIannotatedTree _nameIannotatedTree password_
+                   {-# LINE 22013 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateLogin _annIoriginalTree _nameIoriginalTree password_
+                   {-# LINE 22019 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 22025 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 22031 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22037 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22043 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22049 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22055 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22061 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22067 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nameIannotatedTree,_nameIoriginalTree) =
+                  name_ _nameOcat _nameOflags _nameOimCast _nameOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_AlterUser :: T_Annotation ->
+                           T_Name ->
+                           String ->
+                           T_Statement
+_sem_Statement_AlterUser ann_ name_ password_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _nameOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nameOcat :: Catalog
+              _nameOflags :: TypeCheckFlags
+              _nameOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nameIannotatedTree :: Name
+              _nameIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 119, column 27)
+              _annOtpe =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 22100 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 120, column 27)
+              _nameOtpe =
+                  ({-# LINE 120 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 22106 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterUser _annIannotatedTree _nameIannotatedTree password_
+                   {-# LINE 22112 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterUser _annIoriginalTree _nameIoriginalTree password_
+                   {-# LINE 22118 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 22124 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 22130 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22136 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22142 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22148 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22154 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22160 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22166 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nameIannotatedTree,_nameIoriginalTree) =
+                  name_ _nameOcat _nameOflags _nameOimCast _nameOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_AlterLogin :: T_Annotation ->
+                            T_Name ->
+                            String ->
+                            T_Statement
+_sem_Statement_AlterLogin ann_ name_ password_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _nameOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nameOcat :: Catalog
+              _nameOflags :: TypeCheckFlags
+              _nameOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nameIannotatedTree :: Name
+              _nameIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 112, column 28)
+              _annOtpe =
+                  ({-# LINE 112 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 22199 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 113, column 28)
+              _nameOtpe =
+                  ({-# LINE 113 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 22205 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterLogin _annIannotatedTree _nameIannotatedTree password_
+                   {-# LINE 22211 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterLogin _annIoriginalTree _nameIoriginalTree password_
+                   {-# LINE 22217 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 22223 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 22229 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22235 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22241 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22247 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22253 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22259 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22265 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nameIannotatedTree,_nameIoriginalTree) =
+                  name_ _nameOcat _nameOflags _nameOimCast _nameOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CreateSchema :: T_Annotation ->
+                              NameComponent ->
+                              (Maybe Name) ->
+                              T_Statement
+_sem_Statement_CreateSchema ann_ name_ owner_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 149, column 30)
+              _annOtpe =
+                  ({-# LINE 149 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 22292 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateSchema _annIannotatedTree name_ owner_
+                   {-# LINE 22298 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateSchema _annIoriginalTree name_ owner_
+                   {-# LINE 22304 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 22310 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 22316 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22322 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22328 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22334 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_AlterSchema :: T_Annotation ->
+                             NameComponent ->
+                             T_AlterSchemaOperation ->
+                             T_Statement
+_sem_Statement_AlterSchema ann_ name_ operation_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _operationOcat :: Catalog
+              _operationOflags :: TypeCheckFlags
+              _operationOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _operationIannotatedTree :: AlterSchemaOperation
+              _operationIoriginalTree :: AlterSchemaOperation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 114, column 29)
+              _annOtpe =
+                  ({-# LINE 114 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 22364 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSchema _annIannotatedTree name_ _operationIannotatedTree
+                   {-# LINE 22370 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AlterSchema _annIoriginalTree name_ _operationIoriginalTree
+                   {-# LINE 22376 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 22382 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 22388 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22394 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22400 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22406 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _operationOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22412 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _operationOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22418 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _operationOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22424 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _operationIannotatedTree,_operationIoriginalTree) =
+                  operation_ _operationOcat _operationOflags _operationOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CreateFunction :: T_Annotation ->
+                                T_Name ->
+                                T_ParamDefList ->
+                                T_TypeName ->
+                                Replace ->
+                                Language ->
+                                T_FnBody ->
+                                Volatility ->
+                                T_Statement
+_sem_Statement_CreateFunction ann_ name_ params_ rettype_ rep_ lang_ body_ vol_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _nameOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nameOcat :: Catalog
+              _nameOflags :: TypeCheckFlags
+              _nameOimCast :: (Maybe TypeExtra)
+              _paramsOcat :: Catalog
+              _paramsOflags :: TypeCheckFlags
+              _paramsOimCast :: (Maybe TypeExtra)
+              _rettypeOcat :: Catalog
+              _rettypeOflags :: TypeCheckFlags
+              _rettypeOimCast :: (Maybe TypeExtra)
+              _bodyOcat :: Catalog
+              _bodyOflags :: TypeCheckFlags
+              _bodyOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nameIannotatedTree :: Name
+              _nameIoriginalTree :: Name
+              _paramsIannotatedTree :: ParamDefList
+              _paramsIoriginalTree :: ParamDefList
+              _rettypeIannotatedTree :: TypeName
+              _rettypeInamedType :: (Maybe TypeExtra)
+              _rettypeIoriginalTree :: TypeName
+              _bodyIannotatedTree :: FnBody
+              _bodyIoriginalTree :: FnBody
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 143, column 32)
+              _annOtpe =
+                  ({-# LINE 143 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 22478 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 144, column 32)
+              _nameOtpe =
+                  ({-# LINE 144 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 22484 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateFunction _annIannotatedTree _nameIannotatedTree _paramsIannotatedTree _rettypeIannotatedTree rep_ lang_ _bodyIannotatedTree vol_
+                   {-# LINE 22490 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateFunction _annIoriginalTree _nameIoriginalTree _paramsIoriginalTree _rettypeIoriginalTree rep_ lang_ _bodyIoriginalTree vol_
+                   {-# LINE 22496 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 22502 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 22508 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22514 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22520 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22526 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22532 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22538 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22544 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _paramsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22550 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _paramsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22556 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _paramsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22562 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _rettypeOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22568 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _rettypeOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22574 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _rettypeOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22580 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _bodyOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22586 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _bodyOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22592 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _bodyOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22598 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nameIannotatedTree,_nameIoriginalTree) =
+                  name_ _nameOcat _nameOflags _nameOimCast _nameOtpe
+              ( _paramsIannotatedTree,_paramsIoriginalTree) =
+                  params_ _paramsOcat _paramsOflags _paramsOimCast
+              ( _rettypeIannotatedTree,_rettypeInamedType,_rettypeIoriginalTree) =
+                  rettype_ _rettypeOcat _rettypeOflags _rettypeOimCast
+              ( _bodyIannotatedTree,_bodyIoriginalTree) =
+                  body_ _bodyOcat _bodyOflags _bodyOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CreateDomain :: T_Annotation ->
+                              T_Name ->
+                              T_TypeName ->
+                              String ->
+                              T_MaybeBoolExpr ->
+                              T_Statement
+_sem_Statement_CreateDomain ann_ name_ typ_ constraintName_ check_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _checkOdownEnv :: Environment
+              _nameOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nameOcat :: Catalog
+              _nameOflags :: TypeCheckFlags
+              _nameOimCast :: (Maybe TypeExtra)
+              _typOcat :: Catalog
+              _typOflags :: TypeCheckFlags
+              _typOimCast :: (Maybe TypeExtra)
+              _checkOcat :: Catalog
+              _checkOflags :: TypeCheckFlags
+              _checkOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nameIannotatedTree :: Name
+              _nameIoriginalTree :: Name
+              _typIannotatedTree :: TypeName
+              _typInamedType :: (Maybe TypeExtra)
+              _typIoriginalTree :: TypeName
+              _checkIannotatedTree :: MaybeBoolExpr
+              _checkIoriginalTree :: MaybeBoolExpr
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 140, column 30)
+              _annOtpe =
+                  ({-# LINE 140 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 22651 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 141, column 30)
+              _checkOdownEnv =
+                  ({-# LINE 141 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 22657 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 142, column 30)
+              _nameOtpe =
+                  ({-# LINE 142 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 22663 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateDomain _annIannotatedTree _nameIannotatedTree _typIannotatedTree constraintName_ _checkIannotatedTree
+                   {-# LINE 22669 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateDomain _annIoriginalTree _nameIoriginalTree _typIoriginalTree constraintName_ _checkIoriginalTree
+                   {-# LINE 22675 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 22681 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 22687 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22693 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22699 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22705 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22711 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22717 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22723 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22729 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22735 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22741 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _checkOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22747 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _checkOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22753 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _checkOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22759 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nameIannotatedTree,_nameIoriginalTree) =
+                  name_ _nameOcat _nameOflags _nameOimCast _nameOtpe
+              ( _typIannotatedTree,_typInamedType,_typIoriginalTree) =
+                  typ_ _typOcat _typOflags _typOimCast
+              ( _checkIannotatedTree,_checkIoriginalTree) =
+                  check_ _checkOcat _checkOdownEnv _checkOflags _checkOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CreateLanguage :: T_Annotation ->
+                                String ->
+                                T_Statement
+_sem_Statement_CreateLanguage ann_ name_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 146, column 32)
+              _annOtpe =
+                  ({-# LINE 146 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 22789 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateLanguage _annIannotatedTree name_
+                   {-# LINE 22795 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateLanguage _annIoriginalTree name_
+                   {-# LINE 22801 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 22807 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 22813 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22819 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22825 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22831 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CreateTrigger :: T_Annotation ->
+                               NameComponent ->
+                               TriggerWhen ->
+                               ([TriggerEvent]) ->
+                               T_Name ->
+                               TriggerFire ->
+                               T_Name ->
+                               T_ScalarExprList ->
+                               T_Statement
+_sem_Statement_CreateTrigger ann_ name_ wh_ events_ tbl_ firing_ fnName_ fnArgs_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _fnArgsOdownEnv :: Environment
+              _fnArgsOexpectedCast :: Bool
+              _fnArgsOexpectedTypes :: ([TypeExtra])
+              _fnNameOtpe :: (Either [TypeError] TypeExtra)
+              _tblOtpe :: (Either [TypeError] TypeExtra)
+              _fnArgsOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _tblOcat :: Catalog
+              _tblOflags :: TypeCheckFlags
+              _tblOimCast :: (Maybe TypeExtra)
+              _fnNameOcat :: Catalog
+              _fnNameOflags :: TypeCheckFlags
+              _fnNameOimCast :: (Maybe TypeExtra)
+              _fnArgsOcat :: Catalog
+              _fnArgsOflags :: TypeCheckFlags
+              _fnArgsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _tblIannotatedTree :: Name
+              _tblIoriginalTree :: Name
+              _fnNameIannotatedTree :: Name
+              _fnNameIoriginalTree :: Name
+              _fnArgsIannotatedTree :: ScalarExprList
+              _fnArgsIoriginalTree :: ScalarExprList
+              _fnArgsIupTypes :: ([Maybe TypeExtra])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 157, column 31)
+              _annOtpe =
+                  ({-# LINE 157 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 22883 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 158, column 31)
+              _fnArgsOdownEnv =
+                  ({-# LINE 158 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 22889 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 159, column 31)
+              _fnArgsOexpectedCast =
+                  ({-# LINE 159 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 22895 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 160, column 31)
+              _fnArgsOexpectedTypes =
+                  ({-# LINE 160 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   []
+                   {-# LINE 22901 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 161, column 31)
+              _fnNameOtpe =
+                  ({-# LINE 161 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 22907 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 162, column 31)
+              _tblOtpe =
+                  ({-# LINE 162 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 22913 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 828, column 31)
+              _fnArgsOassignmentCastContext =
+                  ({-# LINE 828 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 22919 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateTrigger _annIannotatedTree name_ wh_ events_ _tblIannotatedTree firing_ _fnNameIannotatedTree _fnArgsIannotatedTree
+                   {-# LINE 22925 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateTrigger _annIoriginalTree name_ wh_ events_ _tblIoriginalTree firing_ _fnNameIoriginalTree _fnArgsIoriginalTree
+                   {-# LINE 22931 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 22937 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 22943 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22949 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22955 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22961 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tblOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22967 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tblOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22973 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tblOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22979 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnNameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 22985 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnNameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 22991 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnNameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 22997 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnArgsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23003 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnArgsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23009 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnArgsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23015 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _tblIannotatedTree,_tblIoriginalTree) =
+                  tbl_ _tblOcat _tblOflags _tblOimCast _tblOtpe
+              ( _fnNameIannotatedTree,_fnNameIoriginalTree) =
+                  fnName_ _fnNameOcat _fnNameOflags _fnNameOimCast _fnNameOtpe
+              ( _fnArgsIannotatedTree,_fnArgsIoriginalTree,_fnArgsIupTypes) =
+                  fnArgs_ _fnArgsOassignmentCastContext _fnArgsOcat _fnArgsOdownEnv _fnArgsOexpectedCast _fnArgsOexpectedTypes _fnArgsOflags _fnArgsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_DropFunction :: T_Annotation ->
+                              IfExists ->
+                              T_NameTypeNameListPairList ->
+                              Cascade ->
+                              T_Statement
+_sem_Statement_DropFunction ann_ ifE_ sigs_ cascade_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _sigsOcat :: Catalog
+              _sigsOflags :: TypeCheckFlags
+              _sigsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _sigsIannotatedTree :: NameTypeNameListPairList
+              _sigsIoriginalTree :: NameTypeNameListPairList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 172, column 30)
+              _annOtpe =
+                  ({-# LINE 172 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 23052 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   DropFunction _annIannotatedTree ifE_ _sigsIannotatedTree cascade_
+                   {-# LINE 23058 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   DropFunction _annIoriginalTree ifE_ _sigsIoriginalTree cascade_
+                   {-# LINE 23064 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 23070 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 23076 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23082 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23088 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23094 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _sigsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23100 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _sigsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23106 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _sigsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23112 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _sigsIannotatedTree,_sigsIoriginalTree) =
+                  sigs_ _sigsOcat _sigsOflags _sigsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_DropSomething :: T_Annotation ->
+                               DropType ->
+                               IfExists ->
+                               ([Name]) ->
+                               Cascade ->
+                               T_Statement
+_sem_Statement_DropSomething ann_ dropType_ ifE_ names_ cascade_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 13, column 5)
+              _annOtpe =
+                  ({-# LINE 13 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag" #-}
+                   Left []
+                   {-# LINE 23141 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   DropSomething _annIannotatedTree dropType_ ifE_ names_ cascade_
+                   {-# LINE 23147 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   DropSomething _annIoriginalTree dropType_ ifE_ names_ cascade_
+                   {-# LINE 23153 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 23159 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 23165 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23171 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23177 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23183 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_DropTrigger :: T_Annotation ->
+                             IfExists ->
+                             NameComponent ->
+                             T_Name ->
+                             Cascade ->
+                             T_Statement
+_sem_Statement_DropTrigger ann_ ifE_ name_ tbl_ cascade_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _tblOtpe :: (Either [TypeError] TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _tblOcat :: Catalog
+              _tblOflags :: TypeCheckFlags
+              _tblOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _tblIannotatedTree :: Name
+              _tblIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 173, column 29)
+              _tblOtpe =
+                  ({-# LINE 173 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 23216 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 13, column 5)
+              _annOtpe =
+                  ({-# LINE 13 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag" #-}
+                   Left []
+                   {-# LINE 23222 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   DropTrigger _annIannotatedTree ifE_ name_ _tblIannotatedTree cascade_
+                   {-# LINE 23228 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   DropTrigger _annIoriginalTree ifE_ name_ _tblIoriginalTree cascade_
+                   {-# LINE 23234 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 23240 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 23246 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23252 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23258 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23264 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tblOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23270 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tblOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23276 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tblOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23282 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _tblIannotatedTree,_tblIoriginalTree) =
+                  tbl_ _tblOcat _tblOflags _tblOimCast _tblOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CreateDatabase :: T_Annotation ->
+                                T_Name ->
+                                T_Statement
+_sem_Statement_CreateDatabase ann_ nm_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _nmOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _nmOcat :: Catalog
+              _nmOflags :: TypeCheckFlags
+              _nmOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _nmIannotatedTree :: Name
+              _nmIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 138, column 32)
+              _annOtpe =
+                  ({-# LINE 138 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 23314 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 139, column 32)
+              _nmOtpe =
+                  ({-# LINE 139 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 23320 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateDatabase _annIannotatedTree _nmIannotatedTree
+                   {-# LINE 23326 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateDatabase _annIoriginalTree _nmIoriginalTree
+                   {-# LINE 23332 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 23338 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 23344 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23350 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23356 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23362 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nmOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23368 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nmOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23374 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _nmOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23380 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _nmIannotatedTree,_nmIoriginalTree) =
+                  nm_ _nmOcat _nmOflags _nmOimCast _nmOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_Set :: T_Annotation ->
+                     String ->
+                     ([SetValue]) ->
+                     T_Statement
+_sem_Statement_Set ann_ name_ values_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 218, column 21)
+              _annOtpe =
+                  ({-# LINE 218 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 23407 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Set _annIannotatedTree name_ values_
+                   {-# LINE 23413 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Set _annIoriginalTree name_ values_
+                   {-# LINE 23419 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 23425 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 23431 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23437 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23443 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23449 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_Notify :: T_Annotation ->
+                        String ->
+                        T_Statement
+_sem_Statement_Notify ann_ name_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 196, column 24)
+              _annOtpe =
+                  ({-# LINE 196 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 23473 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Notify _annIannotatedTree name_
+                   {-# LINE 23479 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Notify _annIoriginalTree name_
+                   {-# LINE 23485 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 23491 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 23497 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23503 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23509 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23515 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_Into :: T_Annotation ->
+                      Bool ->
+                      ([Name]) ->
+                      T_Statement ->
+                      T_Statement
+_sem_Statement_Into ann_ strict_ into_ stmt_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _stmtOcat :: Catalog
+              _stmtOflags :: TypeCheckFlags
+              _stmtOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _stmtIannotatedTree :: Statement
+              _stmtIoriginalTree :: Statement
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 13, column 5)
+              _annOtpe =
+                  ({-# LINE 13 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag" #-}
+                   Left []
+                   {-# LINE 23546 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Into _annIannotatedTree strict_ into_ _stmtIannotatedTree
+                   {-# LINE 23552 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Into _annIoriginalTree strict_ into_ _stmtIoriginalTree
+                   {-# LINE 23558 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 23564 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 23570 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23576 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23582 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23588 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stmtOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23594 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stmtOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23600 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stmtOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23606 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _stmtIannotatedTree,_stmtIoriginalTree) =
+                  stmt_ _stmtOcat _stmtOflags _stmtOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_Assignment :: T_Annotation ->
+                            T_Name ->
+                            T_ScalarExpr ->
+                            T_Statement
+_sem_Statement_Assignment ann_ target_ value_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _valueOexpectedCast :: Bool
+              _valueOexpectedType :: (Maybe TypeExtra)
+              _valueOodbcFunction :: Bool
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _targetOtpe :: (Either [TypeError] TypeExtra)
+              _valueOdownEnv :: Environment
+              _valueOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _targetOcat :: Catalog
+              _targetOflags :: TypeCheckFlags
+              _targetOimCast :: (Maybe TypeExtra)
+              _valueOcat :: Catalog
+              _valueOflags :: TypeCheckFlags
+              _valueOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _targetIannotatedTree :: Name
+              _targetIoriginalTree :: Name
+              _valueIannotatedTree :: ScalarExpr
+              _valueIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _valueIoriginalTree :: ScalarExpr
+              _valueIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 125, column 28)
+              _valueOexpectedCast =
+                  ({-# LINE 125 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 23651 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 126, column 28)
+              _valueOexpectedType =
+                  ({-# LINE 126 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 23657 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 127, column 28)
+              _valueOodbcFunction =
+                  ({-# LINE 127 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 23663 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 13, column 5)
+              _annOtpe =
+                  ({-# LINE 13 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag" #-}
+                   Left []
+                   {-# LINE 23669 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 26, column 5)
+              _targetOtpe =
+                  ({-# LINE 26 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag" #-}
+                   Left []
+                   {-# LINE 23675 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 27, column 5)
+              _valueOdownEnv =
+                  ({-# LINE 27 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 23681 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 825, column 28)
+              _valueOassignmentCastContext =
+                  ({-# LINE 825 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 23687 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Assignment _annIannotatedTree _targetIannotatedTree _valueIannotatedTree
+                   {-# LINE 23693 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Assignment _annIoriginalTree _targetIoriginalTree _valueIoriginalTree
+                   {-# LINE 23699 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 23705 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 23711 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23717 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23723 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23729 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _targetOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23735 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _targetOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23741 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _targetOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23747 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _valueOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23753 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _valueOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23759 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _valueOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23765 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _targetIannotatedTree,_targetIoriginalTree) =
+                  target_ _targetOcat _targetOflags _targetOimCast _targetOtpe
+              ( _valueIannotatedTree,_valueIcolExprs,_valueIoriginalTree,_valueIupType) =
+                  value_ _valueOassignmentCastContext _valueOcat _valueOdownEnv _valueOexpectedCast _valueOexpectedType _valueOflags _valueOimCast _valueOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_Return :: T_Annotation ->
+                        T_MaybeScalarExpr ->
+                        T_Statement
+_sem_Statement_Return ann_ value_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _valueOdownEnv :: Environment
+              _valueOexpectedCast :: Bool
+              _valueOexpectedType :: (Maybe TypeExtra)
+              _valueOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _valueOcat :: Catalog
+              _valueOflags :: TypeCheckFlags
+              _valueOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _valueIannotatedTree :: MaybeScalarExpr
+              _valueIoriginalTree :: MaybeScalarExpr
+              _valueIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 207, column 24)
+              _annOtpe =
+                  ({-# LINE 207 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 23803 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 208, column 24)
+              _valueOdownEnv =
+                  ({-# LINE 208 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 23809 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 209, column 24)
+              _valueOexpectedCast =
+                  ({-# LINE 209 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 23815 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 210, column 24)
+              _valueOexpectedType =
+                  ({-# LINE 210 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 23821 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 839, column 24)
+              _valueOassignmentCastContext =
+                  ({-# LINE 839 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 23827 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Return _annIannotatedTree _valueIannotatedTree
+                   {-# LINE 23833 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Return _annIoriginalTree _valueIoriginalTree
+                   {-# LINE 23839 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 23845 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 23851 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23857 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23863 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23869 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _valueOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23875 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _valueOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23881 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _valueOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23887 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _valueIannotatedTree,_valueIoriginalTree,_valueIupType) =
+                  value_ _valueOassignmentCastContext _valueOcat _valueOdownEnv _valueOexpectedCast _valueOexpectedType _valueOflags _valueOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_ReturnNext :: T_Annotation ->
+                            T_ScalarExpr ->
+                            T_Statement
+_sem_Statement_ReturnNext ann_ expr_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _exprOdownEnv :: Environment
+              _exprOexpectedCast :: Bool
+              _exprOexpectedType :: (Maybe TypeExtra)
+              _exprOodbcFunction :: Bool
+              _exprOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _exprOcat :: Catalog
+              _exprOflags :: TypeCheckFlags
+              _exprOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exprIannotatedTree :: ScalarExpr
+              _exprIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exprIoriginalTree :: ScalarExpr
+              _exprIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 211, column 28)
+              _annOtpe =
+                  ({-# LINE 211 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 23925 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 212, column 28)
+              _exprOdownEnv =
+                  ({-# LINE 212 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 23931 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 213, column 28)
+              _exprOexpectedCast =
+                  ({-# LINE 213 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 23937 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 214, column 28)
+              _exprOexpectedType =
+                  ({-# LINE 214 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 23943 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 215, column 28)
+              _exprOodbcFunction =
+                  ({-# LINE 215 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 23949 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 840, column 28)
+              _exprOassignmentCastContext =
+                  ({-# LINE 840 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 23955 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ReturnNext _annIannotatedTree _exprIannotatedTree
+                   {-# LINE 23961 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ReturnNext _annIoriginalTree _exprIoriginalTree
+                   {-# LINE 23967 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 23973 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 23979 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 23985 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 23991 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 23997 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24003 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24009 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24015 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exprIannotatedTree,_exprIcolExprs,_exprIoriginalTree,_exprIupType) =
+                  expr_ _exprOassignmentCastContext _exprOcat _exprOdownEnv _exprOexpectedCast _exprOexpectedType _exprOflags _exprOimCast _exprOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_ReturnQuery :: T_Annotation ->
+                             T_QueryExpr ->
+                             T_Statement
+_sem_Statement_ReturnQuery ann_ sel_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _selOouterDownEnv :: (Maybe Environment)
+              _selOexpectedType :: (Maybe [TypeExtra])
+              _selOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _selOcat :: Catalog
+              _selOflags :: TypeCheckFlags
+              _selOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _selIannotatedTree :: QueryExpr
+              _selIoriginalTree :: QueryExpr
+              _selIupType :: (Maybe [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 216, column 29)
+              _annOtpe =
+                  ({-# LINE 216 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 24050 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 217, column 29)
+              _selOouterDownEnv =
+                  ({-# LINE 217 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 24056 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 22, column 5)
+              _selOexpectedType =
+                  ({-# LINE 22 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag" #-}
+                   liftM (map snd) _selIupType
+                   {-# LINE 24062 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 841, column 29)
+              _selOassignmentCastContext =
+                  ({-# LINE 841 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 24068 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ReturnQuery _annIannotatedTree _selIannotatedTree
+                   {-# LINE 24074 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ReturnQuery _annIoriginalTree _selIoriginalTree
+                   {-# LINE 24080 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 24086 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 24092 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24098 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24104 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24110 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24116 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24122 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24128 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _selIannotatedTree,_selIoriginalTree,_selIupType) =
+                  sel_ _selOassignmentCastContext _selOcat _selOexpectedType _selOflags _selOimCast _selOouterDownEnv
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_Raise :: T_Annotation ->
+                       RaiseType ->
+                       String ->
+                       T_ScalarExprList ->
+                       T_Statement
+_sem_Statement_Raise ann_ level_ message_ args_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _argsOdownEnv :: Environment
+              _argsOexpectedCast :: Bool
+              _argsOexpectedTypes :: ([TypeExtra])
+              _argsOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _argsOcat :: Catalog
+              _argsOflags :: TypeCheckFlags
+              _argsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _argsIannotatedTree :: ScalarExprList
+              _argsIoriginalTree :: ScalarExprList
+              _argsIupTypes :: ([Maybe TypeExtra])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 203, column 23)
+              _annOtpe =
+                  ({-# LINE 203 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 24166 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 204, column 23)
+              _argsOdownEnv =
+                  ({-# LINE 204 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 24172 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 205, column 23)
+              _argsOexpectedCast =
+                  ({-# LINE 205 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 24178 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 206, column 23)
+              _argsOexpectedTypes =
+                  ({-# LINE 206 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   []
+                   {-# LINE 24184 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 838, column 23)
+              _argsOassignmentCastContext =
+                  ({-# LINE 838 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 24190 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Raise _annIannotatedTree level_ message_ _argsIannotatedTree
+                   {-# LINE 24196 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Raise _annIoriginalTree level_ message_ _argsIoriginalTree
+                   {-# LINE 24202 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 24208 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 24214 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24220 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24226 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24232 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24238 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24244 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24250 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _argsIannotatedTree,_argsIoriginalTree,_argsIupTypes) =
+                  args_ _argsOassignmentCastContext _argsOcat _argsOdownEnv _argsOexpectedCast _argsOexpectedTypes _argsOflags _argsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_NullStatement :: T_Annotation ->
+                               T_Statement
+_sem_Statement_NullStatement ann_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 197, column 31)
+              _annOtpe =
+                  ({-# LINE 197 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 24275 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   NullStatement _annIannotatedTree
+                   {-# LINE 24281 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   NullStatement _annIoriginalTree
+                   {-# LINE 24287 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 24293 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 24299 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24305 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24311 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24317 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_Perform :: T_Annotation ->
+                         T_ScalarExpr ->
+                         T_Statement
+_sem_Statement_Perform ann_ expr_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _exprOdownEnv :: Environment
+              _exprOexpectedCast :: Bool
+              _exprOexpectedType :: (Maybe TypeExtra)
+              _exprOodbcFunction :: Bool
+              _exprOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _exprOcat :: Catalog
+              _exprOflags :: TypeCheckFlags
+              _exprOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exprIannotatedTree :: ScalarExpr
+              _exprIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exprIoriginalTree :: ScalarExpr
+              _exprIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 198, column 25)
+              _annOtpe =
+                  ({-# LINE 198 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 24353 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 199, column 25)
+              _exprOdownEnv =
+                  ({-# LINE 199 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 24359 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 200, column 25)
+              _exprOexpectedCast =
+                  ({-# LINE 200 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 24365 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 201, column 25)
+              _exprOexpectedType =
+                  ({-# LINE 201 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 24371 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 202, column 25)
+              _exprOodbcFunction =
+                  ({-# LINE 202 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 24377 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 836, column 25)
+              _exprOassignmentCastContext =
+                  ({-# LINE 836 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 24383 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Perform _annIannotatedTree _exprIannotatedTree
+                   {-# LINE 24389 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Perform _annIoriginalTree _exprIoriginalTree
+                   {-# LINE 24395 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 24401 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 24407 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24413 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24419 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24425 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24431 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24437 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24443 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exprIannotatedTree,_exprIcolExprs,_exprIoriginalTree,_exprIupType) =
+                  expr_ _exprOassignmentCastContext _exprOcat _exprOdownEnv _exprOexpectedCast _exprOexpectedType _exprOflags _exprOimCast _exprOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_Execute :: T_Annotation ->
+                         T_ScalarExpr ->
+                         T_Statement
+_sem_Statement_Execute ann_ expr_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _exprOdownEnv :: Environment
+              _exprOexpectedCast :: Bool
+              _exprOexpectedType :: (Maybe TypeExtra)
+              _exprOodbcFunction :: Bool
+              _exprOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _exprOcat :: Catalog
+              _exprOflags :: TypeCheckFlags
+              _exprOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exprIannotatedTree :: ScalarExpr
+              _exprIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exprIoriginalTree :: ScalarExpr
+              _exprIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 178, column 25)
+              _annOtpe =
+                  ({-# LINE 178 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 24481 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 179, column 25)
+              _exprOdownEnv =
+                  ({-# LINE 179 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 24487 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 180, column 25)
+              _exprOexpectedCast =
+                  ({-# LINE 180 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 24493 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 181, column 25)
+              _exprOexpectedType =
+                  ({-# LINE 181 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 24499 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 182, column 25)
+              _exprOodbcFunction =
+                  ({-# LINE 182 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 24505 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 831, column 25)
+              _exprOassignmentCastContext =
+                  ({-# LINE 831 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 24511 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Execute _annIannotatedTree _exprIannotatedTree
+                   {-# LINE 24517 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Execute _annIoriginalTree _exprIoriginalTree
+                   {-# LINE 24523 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 24529 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 24535 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24541 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24547 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24553 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24559 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24565 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24571 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exprIannotatedTree,_exprIcolExprs,_exprIoriginalTree,_exprIupType) =
+                  expr_ _exprOassignmentCastContext _exprOcat _exprOdownEnv _exprOexpectedCast _exprOexpectedType _exprOflags _exprOimCast _exprOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_ForQueryStatement :: T_Annotation ->
+                                   (Maybe String) ->
+                                   NameComponent ->
+                                   T_QueryExpr ->
+                                   T_StatementList ->
+                                   T_Statement
+_sem_Statement_ForQueryStatement ann_ lb_ var_ sel_ sts_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _selOouterDownEnv :: (Maybe Environment)
+              _selOexpectedType :: (Maybe [TypeExtra])
+              _selOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _selOcat :: Catalog
+              _selOflags :: TypeCheckFlags
+              _selOimCast :: (Maybe TypeExtra)
+              _stsOcat :: Catalog
+              _stsOflags :: TypeCheckFlags
+              _stsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _selIannotatedTree :: QueryExpr
+              _selIoriginalTree :: QueryExpr
+              _selIupType :: (Maybe [(Text,TypeExtra)])
+              _stsIannotatedTree :: StatementList
+              _stsIoriginalTree :: StatementList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 193, column 35)
+              _annOtpe =
+                  ({-# LINE 193 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 24614 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 194, column 35)
+              _selOouterDownEnv =
+                  ({-# LINE 194 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 24620 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 22, column 5)
+              _selOexpectedType =
+                  ({-# LINE 22 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag" #-}
+                   liftM (map snd) _selIupType
+                   {-# LINE 24626 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 834, column 35)
+              _selOassignmentCastContext =
+                  ({-# LINE 834 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 24632 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ForQueryStatement _annIannotatedTree lb_ var_ _selIannotatedTree _stsIannotatedTree
+                   {-# LINE 24638 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ForQueryStatement _annIoriginalTree lb_ var_ _selIoriginalTree _stsIoriginalTree
+                   {-# LINE 24644 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 24650 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 24656 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24662 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24668 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24674 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24680 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24686 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24692 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24698 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24704 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24710 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _selIannotatedTree,_selIoriginalTree,_selIupType) =
+                  sel_ _selOassignmentCastContext _selOcat _selOexpectedType _selOflags _selOimCast _selOouterDownEnv
+              ( _stsIannotatedTree,_stsIoriginalTree) =
+                  sts_ _stsOcat _stsOflags _stsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_ForIntegerStatement :: T_Annotation ->
+                                     (Maybe String) ->
+                                     NameComponent ->
+                                     T_ScalarExpr ->
+                                     T_ScalarExpr ->
+                                     T_StatementList ->
+                                     T_Statement
+_sem_Statement_ForIntegerStatement ann_ lb_ var_ from_ to_ sts_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _fromOdownEnv :: Environment
+              _fromOexpectedCast :: Bool
+              _fromOexpectedType :: (Maybe TypeExtra)
+              _fromOodbcFunction :: Bool
+              _toOdownEnv :: Environment
+              _toOexpectedCast :: Bool
+              _toOexpectedType :: (Maybe TypeExtra)
+              _toOodbcFunction :: Bool
+              _fromOassignmentCastContext :: Bool
+              _toOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _fromOcat :: Catalog
+              _fromOflags :: TypeCheckFlags
+              _fromOimCast :: (Maybe TypeExtra)
+              _toOcat :: Catalog
+              _toOflags :: TypeCheckFlags
+              _toOimCast :: (Maybe TypeExtra)
+              _stsOcat :: Catalog
+              _stsOflags :: TypeCheckFlags
+              _stsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _fromIannotatedTree :: ScalarExpr
+              _fromIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _fromIoriginalTree :: ScalarExpr
+              _fromIupType :: (Maybe TypeExtra)
+              _toIannotatedTree :: ScalarExpr
+              _toIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _toIoriginalTree :: ScalarExpr
+              _toIupType :: (Maybe TypeExtra)
+              _stsIannotatedTree :: StatementList
+              _stsIoriginalTree :: StatementList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 184, column 37)
+              _annOtpe =
+                  ({-# LINE 184 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 24771 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 185, column 37)
+              _fromOdownEnv =
+                  ({-# LINE 185 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 24777 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 186, column 37)
+              _fromOexpectedCast =
+                  ({-# LINE 186 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 24783 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 187, column 37)
+              _fromOexpectedType =
+                  ({-# LINE 187 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 24789 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 188, column 37)
+              _fromOodbcFunction =
+                  ({-# LINE 188 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 24795 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 189, column 37)
+              _toOdownEnv =
+                  ({-# LINE 189 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 24801 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 190, column 37)
+              _toOexpectedCast =
+                  ({-# LINE 190 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 24807 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 191, column 37)
+              _toOexpectedType =
+                  ({-# LINE 191 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 24813 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 192, column 37)
+              _toOodbcFunction =
+                  ({-# LINE 192 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 24819 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 832, column 37)
+              _fromOassignmentCastContext =
+                  ({-# LINE 832 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 24825 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 833, column 37)
+              _toOassignmentCastContext =
+                  ({-# LINE 833 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 24831 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ForIntegerStatement _annIannotatedTree lb_ var_ _fromIannotatedTree _toIannotatedTree _stsIannotatedTree
+                   {-# LINE 24837 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ForIntegerStatement _annIoriginalTree lb_ var_ _fromIoriginalTree _toIoriginalTree _stsIoriginalTree
+                   {-# LINE 24843 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 24849 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 24855 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24861 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24867 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24873 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fromOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24879 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fromOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24885 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fromOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24891 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _toOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24897 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _toOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24903 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _toOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24909 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24915 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24921 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 24927 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _fromIannotatedTree,_fromIcolExprs,_fromIoriginalTree,_fromIupType) =
+                  from_ _fromOassignmentCastContext _fromOcat _fromOdownEnv _fromOexpectedCast _fromOexpectedType _fromOflags _fromOimCast _fromOodbcFunction
+              ( _toIannotatedTree,_toIcolExprs,_toIoriginalTree,_toIupType) =
+                  to_ _toOassignmentCastContext _toOcat _toOdownEnv _toOexpectedCast _toOexpectedType _toOflags _toOimCast _toOodbcFunction
+              ( _stsIannotatedTree,_stsIoriginalTree) =
+                  sts_ _stsOcat _stsOflags _stsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_LoopStatement :: T_Annotation ->
+                               (Maybe String) ->
+                               T_StatementList ->
+                               T_Statement
+_sem_Statement_LoopStatement ann_ lb_ sts_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _stsOcat :: Catalog
+              _stsOflags :: TypeCheckFlags
+              _stsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _stsIannotatedTree :: StatementList
+              _stsIoriginalTree :: StatementList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 195, column 31)
+              _annOtpe =
+                  ({-# LINE 195 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 24963 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   LoopStatement _annIannotatedTree lb_ _stsIannotatedTree
+                   {-# LINE 24969 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   LoopStatement _annIoriginalTree lb_ _stsIoriginalTree
+                   {-# LINE 24975 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 24981 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 24987 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 24993 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 24999 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25005 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25011 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25017 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25023 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _stsIannotatedTree,_stsIoriginalTree) =
+                  sts_ _stsOcat _stsOflags _stsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_WhileStatement :: T_Annotation ->
+                                (Maybe String) ->
+                                T_ScalarExpr ->
+                                T_StatementList ->
+                                T_Statement
+_sem_Statement_WhileStatement ann_ lb_ expr_ sts_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _exprOdownEnv :: Environment
+              _exprOexpectedCast :: Bool
+              _exprOexpectedType :: (Maybe TypeExtra)
+              _exprOodbcFunction :: Bool
+              _exprOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _exprOcat :: Catalog
+              _exprOflags :: TypeCheckFlags
+              _exprOimCast :: (Maybe TypeExtra)
+              _stsOcat :: Catalog
+              _stsOflags :: TypeCheckFlags
+              _stsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exprIannotatedTree :: ScalarExpr
+              _exprIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _exprIoriginalTree :: ScalarExpr
+              _exprIupType :: (Maybe TypeExtra)
+              _stsIannotatedTree :: StatementList
+              _stsIoriginalTree :: StatementList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 221, column 32)
+              _annOtpe =
+                  ({-# LINE 221 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 25068 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 222, column 32)
+              _exprOdownEnv =
+                  ({-# LINE 222 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 25074 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 223, column 32)
+              _exprOexpectedCast =
+                  ({-# LINE 223 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 25080 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 224, column 32)
+              _exprOexpectedType =
+                  ({-# LINE 224 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 25086 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 225, column 32)
+              _exprOodbcFunction =
+                  ({-# LINE 225 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 25092 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 842, column 32)
+              _exprOassignmentCastContext =
+                  ({-# LINE 842 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 25098 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   WhileStatement _annIannotatedTree lb_ _exprIannotatedTree _stsIannotatedTree
+                   {-# LINE 25104 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   WhileStatement _annIoriginalTree lb_ _exprIoriginalTree _stsIoriginalTree
+                   {-# LINE 25110 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 25116 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 25122 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25128 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25134 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25140 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25146 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25152 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exprOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25158 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25164 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25170 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25176 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exprIannotatedTree,_exprIcolExprs,_exprIoriginalTree,_exprIupType) =
+                  expr_ _exprOassignmentCastContext _exprOcat _exprOdownEnv _exprOexpectedCast _exprOexpectedType _exprOflags _exprOimCast _exprOodbcFunction
+              ( _stsIannotatedTree,_stsIoriginalTree) =
+                  sts_ _stsOcat _stsOflags _stsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_ContinueStatement :: T_Annotation ->
+                                   (Maybe String) ->
+                                   T_Statement
+_sem_Statement_ContinueStatement ann_ lb_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 135, column 35)
+              _annOtpe =
+                  ({-# LINE 135 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 25204 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ContinueStatement _annIannotatedTree lb_
+                   {-# LINE 25210 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ContinueStatement _annIoriginalTree lb_
+                   {-# LINE 25216 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 25222 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 25228 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25234 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25240 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25246 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_ExitStatement :: T_Annotation ->
+                               (Maybe String) ->
+                               T_Statement
+_sem_Statement_ExitStatement ann_ lb_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 183, column 31)
+              _annOtpe =
+                  ({-# LINE 183 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 25270 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ExitStatement _annIannotatedTree lb_
+                   {-# LINE 25276 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ExitStatement _annIoriginalTree lb_
+                   {-# LINE 25282 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 25288 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 25294 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25300 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25306 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25312 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CaseStatementSimple :: T_Annotation ->
+                                     T_ScalarExpr ->
+                                     T_ScalarExprListStatementListTripleList ->
+                                     T_StatementList ->
+                                     T_Statement
+_sem_Statement_CaseStatementSimple ann_ val_ cases_ els_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _valOdownEnv :: Environment
+              _valOexpectedCast :: Bool
+              _valOexpectedType :: (Maybe TypeExtra)
+              _valOodbcFunction :: Bool
+              _valOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _valOcat :: Catalog
+              _valOflags :: TypeCheckFlags
+              _valOimCast :: (Maybe TypeExtra)
+              _casesOcat :: Catalog
+              _casesOflags :: TypeCheckFlags
+              _casesOimCast :: (Maybe TypeExtra)
+              _elsOcat :: Catalog
+              _elsOflags :: TypeCheckFlags
+              _elsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _valIannotatedTree :: ScalarExpr
+              _valIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _valIoriginalTree :: ScalarExpr
+              _valIupType :: (Maybe TypeExtra)
+              _casesIannotatedTree :: ScalarExprListStatementListTripleList
+              _casesIoriginalTree :: ScalarExprListStatementListTripleList
+              _elsIannotatedTree :: StatementList
+              _elsIoriginalTree :: StatementList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 130, column 37)
+              _annOtpe =
+                  ({-# LINE 130 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 25360 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 131, column 37)
+              _valOdownEnv =
+                  ({-# LINE 131 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 25366 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 132, column 37)
+              _valOexpectedCast =
+                  ({-# LINE 132 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 25372 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 133, column 37)
+              _valOexpectedType =
+                  ({-# LINE 133 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 25378 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 134, column 37)
+              _valOodbcFunction =
+                  ({-# LINE 134 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 25384 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 826, column 37)
+              _valOassignmentCastContext =
+                  ({-# LINE 826 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 25390 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CaseStatementSimple _annIannotatedTree _valIannotatedTree _casesIannotatedTree _elsIannotatedTree
+                   {-# LINE 25396 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CaseStatementSimple _annIoriginalTree _valIoriginalTree _casesIoriginalTree _elsIoriginalTree
+                   {-# LINE 25402 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 25408 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 25414 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25420 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25426 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25432 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _valOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25438 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _valOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25444 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _valOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25450 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25456 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25462 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25468 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25474 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25480 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25486 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _valIannotatedTree,_valIcolExprs,_valIoriginalTree,_valIupType) =
+                  val_ _valOassignmentCastContext _valOcat _valOdownEnv _valOexpectedCast _valOexpectedType _valOflags _valOimCast _valOodbcFunction
+              ( _casesIannotatedTree,_casesIoriginalTree) =
+                  cases_ _casesOcat _casesOflags _casesOimCast
+              ( _elsIannotatedTree,_elsIoriginalTree) =
+                  els_ _elsOcat _elsOflags _elsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CaseStatement :: T_Annotation ->
+                               T_ScalarExprListStatementListTripleList ->
+                               T_StatementList ->
+                               T_Statement
+_sem_Statement_CaseStatement ann_ cases_ els_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _casesOcat :: Catalog
+              _casesOflags :: TypeCheckFlags
+              _casesOimCast :: (Maybe TypeExtra)
+              _elsOcat :: Catalog
+              _elsOflags :: TypeCheckFlags
+              _elsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _casesIannotatedTree :: ScalarExprListStatementListTripleList
+              _casesIoriginalTree :: ScalarExprListStatementListTripleList
+              _elsIannotatedTree :: StatementList
+              _elsIoriginalTree :: StatementList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 129, column 31)
+              _annOtpe =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 25527 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CaseStatement _annIannotatedTree _casesIannotatedTree _elsIannotatedTree
+                   {-# LINE 25533 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CaseStatement _annIoriginalTree _casesIoriginalTree _elsIoriginalTree
+                   {-# LINE 25539 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 25545 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 25551 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25557 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25563 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25569 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25575 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25581 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25587 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25593 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25599 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25605 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _casesIannotatedTree,_casesIoriginalTree) =
+                  cases_ _casesOcat _casesOflags _casesOimCast
+              ( _elsIannotatedTree,_elsIoriginalTree) =
+                  els_ _elsOcat _elsOflags _elsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_If :: T_Annotation ->
+                    T_ScalarExprStatementListPairList ->
+                    T_StatementList ->
+                    T_Statement
+_sem_Statement_If ann_ cases_ els_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _casesOcat :: Catalog
+              _casesOflags :: TypeCheckFlags
+              _casesOimCast :: (Maybe TypeExtra)
+              _elsOcat :: Catalog
+              _elsOflags :: TypeCheckFlags
+              _elsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _casesIannotatedTree :: ScalarExprStatementListPairList
+              _casesIoriginalTree :: ScalarExprStatementListPairList
+              _elsIannotatedTree :: StatementList
+              _elsIoriginalTree :: StatementList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 13, column 5)
+              _annOtpe =
+                  ({-# LINE 13 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag" #-}
+                   Left []
+                   {-# LINE 25644 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   If _annIannotatedTree _casesIannotatedTree _elsIannotatedTree
+                   {-# LINE 25650 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   If _annIoriginalTree _casesIoriginalTree _elsIoriginalTree
+                   {-# LINE 25656 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 25662 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 25668 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25674 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25680 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25686 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25692 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25698 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _casesOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25704 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25710 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25716 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _elsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25722 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _casesIannotatedTree,_casesIoriginalTree) =
+                  cases_ _casesOcat _casesOflags _casesOimCast
+              ( _elsIannotatedTree,_elsIoriginalTree) =
+                  els_ _elsOcat _elsOflags _elsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_Block :: T_Annotation ->
+                       (Maybe String) ->
+                       T_VarDefList ->
+                       T_StatementList ->
+                       T_Statement
+_sem_Statement_Block ann_ lb_ vars_ sts_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _varsOcat :: Catalog
+              _varsOflags :: TypeCheckFlags
+              _varsOimCast :: (Maybe TypeExtra)
+              _stsOcat :: Catalog
+              _stsOflags :: TypeCheckFlags
+              _stsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _varsIannotatedTree :: VarDefList
+              _varsIoriginalTree :: VarDefList
+              _stsIannotatedTree :: StatementList
+              _stsIoriginalTree :: StatementList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 128, column 23)
+              _annOtpe =
+                  ({-# LINE 128 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 25762 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Block _annIannotatedTree lb_ _varsIannotatedTree _stsIannotatedTree
+                   {-# LINE 25768 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Block _annIoriginalTree lb_ _varsIoriginalTree _stsIoriginalTree
+                   {-# LINE 25774 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 25780 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 25786 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25792 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25798 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25804 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _varsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25810 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _varsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25816 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _varsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25822 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25828 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25834 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _stsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25840 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _varsIannotatedTree,_varsIoriginalTree) =
+                  vars_ _varsOcat _varsOflags _varsOimCast
+              ( _stsIannotatedTree,_stsIoriginalTree) =
+                  sts_ _stsOcat _stsOflags _stsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_AntiStatement :: String ->
+                               T_Statement
+_sem_Statement_AntiStatement string_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AntiStatement string_
+                   {-# LINE 25861 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   AntiStatement string_
+                   {-# LINE 25867 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 25873 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 25879 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_DeclareStatement :: T_Annotation ->
+                                  ([(String,TypeName,Maybe ScalarExpr)]) ->
+                                  T_Statement
+_sem_Statement_DeclareStatement ann_ ds_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 13, column 5)
+              _annOtpe =
+                  ({-# LINE 13 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag" #-}
+                   Left []
+                   {-# LINE 25901 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   DeclareStatement _annIannotatedTree ds_
+                   {-# LINE 25907 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   DeclareStatement _annIoriginalTree ds_
+                   {-# LINE 25913 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 25919 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 25925 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 25931 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 25937 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 25943 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_ExecStatement :: T_Annotation ->
+                               T_Name ->
+                               T_ScalarExprList ->
+                               T_Statement
+_sem_Statement_ExecStatement ann_ spName_ args_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _argsOdownEnv :: Environment
+              _argsOexpectedCast :: Bool
+              _argsOexpectedTypes :: ([TypeExtra])
+              _spNameOtpe :: (Either [TypeError] TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _argsOassignmentCastContext :: Bool
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _spNameOcat :: Catalog
+              _spNameOflags :: TypeCheckFlags
+              _spNameOimCast :: (Maybe TypeExtra)
+              _argsOcat :: Catalog
+              _argsOflags :: TypeCheckFlags
+              _argsOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _spNameIannotatedTree :: Name
+              _spNameIoriginalTree :: Name
+              _argsIannotatedTree :: ScalarExprList
+              _argsIoriginalTree :: ScalarExprList
+              _argsIupTypes :: ([Maybe TypeExtra])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 174, column 31)
+              _argsOdownEnv =
+                  ({-# LINE 174 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 25984 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 175, column 31)
+              _argsOexpectedCast =
+                  ({-# LINE 175 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 25990 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 176, column 31)
+              _argsOexpectedTypes =
+                  ({-# LINE 176 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   []
+                   {-# LINE 25996 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 177, column 31)
+              _spNameOtpe =
+                  ({-# LINE 177 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 26002 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 13, column 5)
+              _annOtpe =
+                  ({-# LINE 13 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag" #-}
+                   Left []
+                   {-# LINE 26008 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 830, column 31)
+              _argsOassignmentCastContext =
+                  ({-# LINE 830 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 26014 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ExecStatement _annIannotatedTree _spNameIannotatedTree _argsIannotatedTree
+                   {-# LINE 26020 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ExecStatement _annIoriginalTree _spNameIoriginalTree _argsIoriginalTree
+                   {-# LINE 26026 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 26032 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 26038 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 26044 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 26050 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 26056 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _spNameOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 26062 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _spNameOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 26068 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _spNameOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 26074 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 26080 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 26086 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _argsOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 26092 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _spNameIannotatedTree,_spNameIoriginalTree) =
+                  spName_ _spNameOcat _spNameOflags _spNameOimCast _spNameOtpe
+              ( _argsIannotatedTree,_argsIoriginalTree,_argsIupTypes) =
+                  args_ _argsOassignmentCastContext _argsOcat _argsOdownEnv _argsOexpectedCast _argsOexpectedTypes _argsOflags _argsOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_Statement_CreateIndexTSQL :: T_Annotation ->
+                                 NameComponent ->
+                                 T_Name ->
+                                 ([NameComponent]) ->
+                                 T_Statement
+_sem_Statement_CreateIndexTSQL ann_ nm_ obj_ cols_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _objOtpe :: (Either [TypeError] TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: Statement
+              _lhsOoriginalTree :: Statement
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _objOcat :: Catalog
+              _objOflags :: TypeCheckFlags
+              _objOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _objIannotatedTree :: Name
+              _objIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 145, column 33)
+              _objOtpe =
+                  ({-# LINE 145 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 26128 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag"(line 13, column 5)
+              _annOtpe =
+                  ({-# LINE 13 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Statements.ag" #-}
+                   Left []
+                   {-# LINE 26134 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateIndexTSQL _annIannotatedTree nm_ _objIannotatedTree cols_
+                   {-# LINE 26140 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   CreateIndexTSQL _annIoriginalTree nm_ _objIoriginalTree cols_
+                   {-# LINE 26146 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 26152 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 26158 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 26164 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 26170 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 26176 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _objOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 26182 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _objOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 26188 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _objOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 26194 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _objIannotatedTree,_objIoriginalTree) =
+                  obj_ _objOcat _objOflags _objOimCast _objOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- StatementList -----------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : StatementList 
+         originalTree         : StatementList 
+   alternatives:
+      alternative Cons:
+         child hd             : Statement 
+         child tl             : StatementList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type StatementList = [Statement]
+-- cata
+_sem_StatementList :: StatementList ->
+                     T_StatementList
+_sem_StatementList list =
+    (Prelude.foldr _sem_StatementList_Cons _sem_StatementList_Nil (Prelude.map _sem_Statement list))
+-- semantic domain
+type T_StatementList = Catalog ->
+                       TypeCheckFlags ->
+                       (Maybe TypeExtra) ->
+                       ( StatementList,StatementList)
+data Inh_StatementList = Inh_StatementList {_cat_Inh_StatementList :: Catalog,_flags_Inh_StatementList :: TypeCheckFlags,_imCast_Inh_StatementList :: (Maybe TypeExtra)}
+data Syn_StatementList = Syn_StatementList {_annotatedTree_Syn_StatementList :: StatementList,_originalTree_Syn_StatementList :: StatementList}
+_wrap_StatementList :: T_StatementList ->
+                      Inh_StatementList ->
+                      Syn_StatementList
+_wrap_StatementList sem (Inh_StatementList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_StatementList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_StatementList_Cons :: T_Statement ->
+                          T_StatementList ->
+                          T_StatementList
+_sem_StatementList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: StatementList
+              _lhsOoriginalTree :: StatementList
+              _hdOcat :: Catalog
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: Statement
+              _hdIoriginalTree :: Statement
+              _tlIannotatedTree :: StatementList
+              _tlIoriginalTree :: StatementList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 26265 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 26271 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 26277 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 26283 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 26289 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 26295 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 26301 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 26307 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 26313 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 26319 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree) =
+                  hd_ _hdOcat _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_StatementList_Nil :: T_StatementList
+_sem_StatementList_Nil =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: StatementList
+              _lhsOoriginalTree :: StatementList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 26337 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 26343 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 26349 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 26355 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- TablePartitionDef -------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : TablePartitionDef 
+         originalTree         : TablePartitionDef 
+   alternatives:
+      alternative TablePartitionDef:
+         child ann            : Annotation 
+         child colname        : {NameComponent}
+         child interval       : {Integer}
+         child timeframe      : {TablePartitionDateTimeInterval}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data TablePartitionDef = TablePartitionDef (Annotation) (NameComponent) (Integer) (TablePartitionDateTimeInterval)
+                       deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_TablePartitionDef :: TablePartitionDef ->
+                         T_TablePartitionDef
+_sem_TablePartitionDef (TablePartitionDef _ann _colname _interval _timeframe) =
+    (_sem_TablePartitionDef_TablePartitionDef (_sem_Annotation _ann) _colname _interval _timeframe)
+-- semantic domain
+type T_TablePartitionDef = Catalog ->
+                           TypeCheckFlags ->
+                           (Maybe TypeExtra) ->
+                           ( TablePartitionDef,TablePartitionDef)
+data Inh_TablePartitionDef = Inh_TablePartitionDef {_cat_Inh_TablePartitionDef :: Catalog,_flags_Inh_TablePartitionDef :: TypeCheckFlags,_imCast_Inh_TablePartitionDef :: (Maybe TypeExtra)}
+data Syn_TablePartitionDef = Syn_TablePartitionDef {_annotatedTree_Syn_TablePartitionDef :: TablePartitionDef,_originalTree_Syn_TablePartitionDef :: TablePartitionDef}
+_wrap_TablePartitionDef :: T_TablePartitionDef ->
+                          Inh_TablePartitionDef ->
+                          Syn_TablePartitionDef
+_wrap_TablePartitionDef sem (Inh_TablePartitionDef _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_TablePartitionDef _lhsOannotatedTree _lhsOoriginalTree))
+_sem_TablePartitionDef_TablePartitionDef :: T_Annotation ->
+                                           NameComponent ->
+                                           Integer ->
+                                           TablePartitionDateTimeInterval ->
+                                           T_TablePartitionDef
+_sem_TablePartitionDef_TablePartitionDef ann_ colname_ interval_ timeframe_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: TablePartitionDef
+              _lhsOoriginalTree :: TablePartitionDef
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 226, column 43)
+              _annOtpe =
+                  ({-# LINE 226 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 26419 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   TablePartitionDef _annIannotatedTree colname_ interval_ timeframe_
+                   {-# LINE 26425 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   TablePartitionDef _annIoriginalTree colname_ interval_ timeframe_
+                   {-# LINE 26431 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 26437 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 26443 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 26449 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 26455 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 26461 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- TableRef ----------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : TableRef 
+         originalTree         : TableRef 
+         upEnv                : Environment
+   alternatives:
+      alternative Tref:
+         child ann            : Annotation 
+         child tbl            : Name 
+         visit 0:
+            local eEnv        : {Either [TypeError] Environment}
+            local newAlias    : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative FunTref:
+         child ann            : Annotation 
+         child fn             : ScalarExpr 
+         visit 0:
+            local eEnv        : {Either [TypeError] Environment}
+            local newAlias    : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative SubTref:
+         child ann            : Annotation 
+         child sel            : QueryExpr 
+         visit 0:
+            local eEnv        : {Either [TypeError] Environment}
+            local newAlias    : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative JoinTref:
+         child ann            : Annotation 
+         child tref0          : TableRef 
+         child nat            : {Natural}
+         child joinType       : {JoinType}
+         child joinHint       : {Maybe JoinHint}
+         child tref1          : TableRef 
+         child onExpr         : OnExpr 
+         visit 0:
+            local eEnv        : {Either [TypeError] Environment}
+            local newAlias    : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative TableAlias:
+         child ann            : Annotation 
+         child tb             : {NameComponent}
+         child tref           : TableRef 
+         visit 0:
+            local eEnv        : {Either [TypeError] Environment}
+            local annotatedTree : _
+            local originalTree : _
+      alternative FullAlias:
+         child ann            : Annotation 
+         child tb             : {NameComponent}
+         child cols           : {[NameComponent]}
+         child tref           : TableRef 
+         visit 0:
+            local eEnv        : {Either [TypeError] Environment}
+            local annotatedTree : _
+            local originalTree : _
+      alternative TableRefParens:
+         child ann            : Annotation 
+         child tref           : TableRef 
+         visit 0:
+            local eEnv        : {Either [TypeError] Environment}
+            local newAlias    : _
+            local annotatedTree : _
+            local originalTree : _
+      alternative OdbcTableRef:
+         child ann            : Annotation 
+         child tref           : TableRef 
+         visit 0:
+            local eEnv        : {Either [TypeError] Environment}
+            local newAlias    : _
+            local annotatedTree : _
+            local originalTree : _
+-}
+data TableRef = Tref (Annotation) (Name)
+              | FunTref (Annotation) (ScalarExpr)
+              | SubTref (Annotation) (QueryExpr)
+              | JoinTref (Annotation) (TableRef) (Natural) (JoinType) ((Maybe JoinHint)) (TableRef) (OnExpr)
+              | TableAlias (Annotation) (NameComponent) (TableRef)
+              | FullAlias (Annotation) (NameComponent) (([NameComponent])) (TableRef)
+              | TableRefParens (Annotation) (TableRef)
+              | OdbcTableRef (Annotation) (TableRef)
+              deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_TableRef :: TableRef ->
+                T_TableRef
+_sem_TableRef (Tref _ann _tbl) =
+    (_sem_TableRef_Tref (_sem_Annotation _ann) (_sem_Name _tbl))
+_sem_TableRef (FunTref _ann _fn) =
+    (_sem_TableRef_FunTref (_sem_Annotation _ann) (_sem_ScalarExpr _fn))
+_sem_TableRef (SubTref _ann _sel) =
+    (_sem_TableRef_SubTref (_sem_Annotation _ann) (_sem_QueryExpr _sel))
+_sem_TableRef (JoinTref _ann _tref0 _nat _joinType _joinHint _tref1 _onExpr) =
+    (_sem_TableRef_JoinTref (_sem_Annotation _ann) (_sem_TableRef _tref0) _nat _joinType _joinHint (_sem_TableRef _tref1) (_sem_OnExpr _onExpr))
+_sem_TableRef (TableAlias _ann _tb _tref) =
+    (_sem_TableRef_TableAlias (_sem_Annotation _ann) _tb (_sem_TableRef _tref))
+_sem_TableRef (FullAlias _ann _tb _cols _tref) =
+    (_sem_TableRef_FullAlias (_sem_Annotation _ann) _tb _cols (_sem_TableRef _tref))
+_sem_TableRef (TableRefParens _ann _tref) =
+    (_sem_TableRef_TableRefParens (_sem_Annotation _ann) (_sem_TableRef _tref))
+_sem_TableRef (OdbcTableRef _ann _tref) =
+    (_sem_TableRef_OdbcTableRef (_sem_Annotation _ann) (_sem_TableRef _tref))
+-- semantic domain
+type T_TableRef = Catalog ->
+                  TypeCheckFlags ->
+                  (Maybe TypeExtra) ->
+                  ( TableRef,TableRef,Environment)
+data Inh_TableRef = Inh_TableRef {_cat_Inh_TableRef :: Catalog,_flags_Inh_TableRef :: TypeCheckFlags,_imCast_Inh_TableRef :: (Maybe TypeExtra)}
+data Syn_TableRef = Syn_TableRef {_annotatedTree_Syn_TableRef :: TableRef,_originalTree_Syn_TableRef :: TableRef,_upEnv_Syn_TableRef :: Environment}
+_wrap_TableRef :: T_TableRef ->
+                 Inh_TableRef ->
+                 Syn_TableRef
+_wrap_TableRef sem (Inh_TableRef _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupEnv) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_TableRef _lhsOannotatedTree _lhsOoriginalTree _lhsOupEnv))
+_sem_TableRef_Tref :: T_Annotation ->
+                     T_Name ->
+                     T_TableRef
+_sem_TableRef_Tref ann_ tbl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupEnv :: Environment
+              _eEnv :: (Either [TypeError] Environment)
+              _tblOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: TableRef
+              _lhsOoriginalTree :: TableRef
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _tblOcat :: Catalog
+              _tblOflags :: TypeCheckFlags
+              _tblOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _tblIannotatedTree :: Name
+              _tblIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 33, column 7)
+              _annOtpe =
+                  ({-# LINE 33 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either Left (Right . mkTypeExtraNN . TrefType)
+                   (_eEnv     >>= E.envExpandStar Nothing)
+                   {-# LINE 26618 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 36, column 7)
+              _lhsOupEnv =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either (const E.brokeEnvironment) id _eEnv
+                   {-# LINE 26624 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 42, column 7)
+              _eEnv =
+                  ({-# LINE 42 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   E.envCreateTrefEnvironment _lhsIcat (nameComponents _tblIoriginalTree)
+                   {-# LINE 26630 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 43, column 7)
+              _tblOtpe =
+                  ({-# LINE 43 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   Left []
+                   {-# LINE 26636 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 75, column 7)
+              _lhsOannotatedTree =
+                  ({-# LINE 75 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   let mk (q,is) = FullAlias emptyAnnotation
+                                            (Nmc q)
+                                            (map Nmc is)
+                                            $ wrapIfJoin _annotatedTree
+                       wrapIfJoin tr = case tr of
+                                          JoinTref {} -> TableRefParens emptyAnnotation tr
+                                          _ -> tr
+                   in maybe _annotatedTree     mk _newAlias
+                   {-# LINE 26649 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 150, column 7)
+              _newAlias =
+                  ({-# LINE 150 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   if tcfAddFullTablerefAliases _lhsIflags
+                   then do
+                     ((_,n),cs,_) <- either (const Nothing) Just
+                                   $ catLookupTableAndAttrs _lhsIcat
+                                   (nameComponents _tblIoriginalTree)
+                     return (T.unpack n, (map (T.unpack . fst) cs))
+                   else Nothing
+                   {-# LINE 26661 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Tref _annIannotatedTree _tblIannotatedTree
+                   {-# LINE 26667 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Tref _annIoriginalTree _tblIoriginalTree
+                   {-# LINE 26673 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 26679 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 26685 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 26691 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 26697 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tblOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 26703 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tblOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 26709 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tblOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 26715 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _tblIannotatedTree,_tblIoriginalTree) =
+                  tbl_ _tblOcat _tblOflags _tblOimCast _tblOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupEnv)))
+_sem_TableRef_FunTref :: T_Annotation ->
+                        T_ScalarExpr ->
+                        T_TableRef
+_sem_TableRef_FunTref ann_ fn_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _fnOdownEnv :: Environment
+              _fnOexpectedCast :: Bool
+              _fnOexpectedType :: (Maybe TypeExtra)
+              _fnOodbcFunction :: Bool
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupEnv :: Environment
+              _eEnv :: (Either [TypeError] Environment)
+              _lhsOannotatedTree :: TableRef
+              _fnOassignmentCastContext :: Bool
+              _lhsOoriginalTree :: TableRef
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _fnOcat :: Catalog
+              _fnOflags :: TypeCheckFlags
+              _fnOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _fnIannotatedTree :: ScalarExpr
+              _fnIcolExprs :: ([(NameComponent,Maybe TypeExtra,ScalarExpr)])
+              _fnIoriginalTree :: ScalarExpr
+              _fnIupType :: (Maybe TypeExtra)
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 227, column 24)
+              _fnOdownEnv =
+                  ({-# LINE 227 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 26755 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 228, column 24)
+              _fnOexpectedCast =
+                  ({-# LINE 228 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 26761 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 229, column 24)
+              _fnOexpectedType =
+                  ({-# LINE 229 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Nothing
+                   {-# LINE 26767 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 230, column 24)
+              _fnOodbcFunction =
+                  ({-# LINE 230 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   False
+                   {-# LINE 26773 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 33, column 7)
+              _annOtpe =
+                  ({-# LINE 33 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either Left (Right . mkTypeExtraNN . TrefType)
+                   (_eEnv     >>= E.envExpandStar Nothing)
+                   {-# LINE 26780 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 36, column 7)
+              _lhsOupEnv =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either (const E.brokeEnvironment) id _eEnv
+                   {-# LINE 26786 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 71, column 7)
+              _eEnv =
+                  ({-# LINE 71 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   Left []
+                   {-# LINE 26792 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 75, column 7)
+              _lhsOannotatedTree =
+                  ({-# LINE 75 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   let mk (q,is) = FullAlias emptyAnnotation
+                                            (Nmc q)
+                                            (map Nmc is)
+                                            $ wrapIfJoin _annotatedTree
+                       wrapIfJoin tr = case tr of
+                                          JoinTref {} -> TableRefParens emptyAnnotation tr
+                                          _ -> tr
+                   in maybe _annotatedTree     mk _newAlias
+                   {-# LINE 26805 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 135, column 7)
+              _newAlias =
+                  ({-# LINE 135 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   if tcfAddFullTablerefAliases _lhsIflags
+                   then do
+                     env <- either (const Nothing) Just _eEnv
+                     cs <- either (const Nothing) Just $ E.envExpandStar Nothing env
+                     let qs = map (fst . fst) cs
+                     if all (== head qs) qs
+                       then return (T.unpack $ head qs, map (T.unpack . snd . fst) cs)
+                       else
+                                                            Nothing
+                   else Nothing
+                   {-# LINE 26820 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 843, column 24)
+              _fnOassignmentCastContext =
+                  ({-# LINE 843 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 26826 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   FunTref _annIannotatedTree _fnIannotatedTree
+                   {-# LINE 26832 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   FunTref _annIoriginalTree _fnIoriginalTree
+                   {-# LINE 26838 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 26844 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 26850 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 26856 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 26862 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 26868 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 26874 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _fnOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 26880 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _fnIannotatedTree,_fnIcolExprs,_fnIoriginalTree,_fnIupType) =
+                  fn_ _fnOassignmentCastContext _fnOcat _fnOdownEnv _fnOexpectedCast _fnOexpectedType _fnOflags _fnOimCast _fnOodbcFunction
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupEnv)))
+_sem_TableRef_SubTref :: T_Annotation ->
+                        T_QueryExpr ->
+                        T_TableRef
+_sem_TableRef_SubTref ann_ sel_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupEnv :: Environment
+              _eEnv :: (Either [TypeError] Environment)
+              _selOexpectedType :: (Maybe [TypeExtra])
+              _lhsOannotatedTree :: TableRef
+              _selOouterDownEnv :: (Maybe Environment)
+              _selOassignmentCastContext :: Bool
+              _lhsOoriginalTree :: TableRef
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _selOcat :: Catalog
+              _selOflags :: TypeCheckFlags
+              _selOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _selIannotatedTree :: QueryExpr
+              _selIoriginalTree :: QueryExpr
+              _selIupType :: (Maybe [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 33, column 7)
+              _annOtpe =
+                  ({-# LINE 33 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either Left (Right . mkTypeExtraNN . TrefType)
+                   (_eEnv     >>= E.envExpandStar Nothing)
+                   {-# LINE 26918 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 36, column 7)
+              _lhsOupEnv =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either (const E.brokeEnvironment) id _eEnv
+                   {-# LINE 26924 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 58, column 7)
+              _eEnv =
+                  ({-# LINE 58 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   maybe (Left []) id
+                   $ fmap E.envSelectListEnvironment _selIupType
+                   {-# LINE 26931 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 60, column 7)
+              _selOexpectedType =
+                  ({-# LINE 60 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   liftM (map snd) _selIupType
+                   {-# LINE 26937 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 75, column 7)
+              _lhsOannotatedTree =
+                  ({-# LINE 75 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   let mk (q,is) = FullAlias emptyAnnotation
+                                            (Nmc q)
+                                            (map Nmc is)
+                                            $ wrapIfJoin _annotatedTree
+                       wrapIfJoin tr = case tr of
+                                          JoinTref {} -> TableRefParens emptyAnnotation tr
+                                          _ -> tr
+                   in maybe _annotatedTree     mk _newAlias
+                   {-# LINE 26950 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 135, column 7)
+              _newAlias =
+                  ({-# LINE 135 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   if tcfAddFullTablerefAliases _lhsIflags
+                   then do
+                     env <- either (const Nothing) Just _eEnv
+                     cs <- either (const Nothing) Just $ E.envExpandStar Nothing env
+                     let qs = map (fst . fst) cs
+                     if all (== head qs) qs
+                       then return (T.unpack $ head qs, map (T.unpack . snd . fst) cs)
+                       else
+                                                            Nothing
+                   else Nothing
+                   {-# LINE 26965 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 93, column 13)
+              _selOouterDownEnv =
+                  ({-# LINE 93 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   Nothing
+                   {-# LINE 26971 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 844, column 24)
+              _selOassignmentCastContext =
+                  ({-# LINE 844 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 26977 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SubTref _annIannotatedTree _selIannotatedTree
+                   {-# LINE 26983 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SubTref _annIoriginalTree _selIoriginalTree
+                   {-# LINE 26989 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 26995 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27001 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27007 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 27013 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27019 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27025 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _selOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 27031 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _selIannotatedTree,_selIoriginalTree,_selIupType) =
+                  sel_ _selOassignmentCastContext _selOcat _selOexpectedType _selOflags _selOimCast _selOouterDownEnv
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupEnv)))
+_sem_TableRef_JoinTref :: T_Annotation ->
+                         T_TableRef ->
+                         Natural ->
+                         JoinType ->
+                         (Maybe JoinHint) ->
+                         T_TableRef ->
+                         T_OnExpr ->
+                         T_TableRef
+_sem_TableRef_JoinTref ann_ tref0_ nat_ joinType_ joinHint_ tref1_ onExpr_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupEnv :: Environment
+              _eEnv :: (Either [TypeError] Environment)
+              _onExprOdownEnv :: Environment
+              _lhsOannotatedTree :: TableRef
+              _lhsOoriginalTree :: TableRef
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _tref0Ocat :: Catalog
+              _tref0Oflags :: TypeCheckFlags
+              _tref0OimCast :: (Maybe TypeExtra)
+              _tref1Ocat :: Catalog
+              _tref1Oflags :: TypeCheckFlags
+              _tref1OimCast :: (Maybe TypeExtra)
+              _onExprOcat :: Catalog
+              _onExprOflags :: TypeCheckFlags
+              _onExprOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _tref0IannotatedTree :: TableRef
+              _tref0IoriginalTree :: TableRef
+              _tref0IupEnv :: Environment
+              _tref1IannotatedTree :: TableRef
+              _tref1IoriginalTree :: TableRef
+              _tref1IupEnv :: Environment
+              _onExprIannotatedTree :: OnExpr
+              _onExprIoriginalTree :: OnExpr
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 33, column 7)
+              _annOtpe =
+                  ({-# LINE 33 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either Left (Right . mkTypeExtraNN . TrefType)
+                   (_eEnv     >>= E.envExpandStar Nothing)
+                   {-# LINE 27083 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 36, column 7)
+              _lhsOupEnv =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either (const E.brokeEnvironment) id _eEnv
+                   {-# LINE 27089 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 46, column 7)
+              _eEnv =
+                  ({-# LINE 46 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   E.createJoinTrefEnvironment _lhsIcat
+                     _tref0IupEnv _tref1IupEnv (convertJoinType joinType_)
+                     $ case (joinType_,_onExprIoriginalTree) of
+                        (x,Nothing) | x /= Cross -> Nothing
+                        (_,Just (JoinUsing _ nms)) -> Just nms
+                        _ -> Just []
+                   {-# LINE 27100 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 56, column 7)
+              _onExprOdownEnv =
+                  ({-# LINE 56 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either (const E.brokeEnvironment) id _eEnv
+                   {-# LINE 27106 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 75, column 7)
+              _lhsOannotatedTree =
+                  ({-# LINE 75 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   let mk (q,is) = FullAlias emptyAnnotation
+                                            (Nmc q)
+                                            (map Nmc is)
+                                            $ wrapIfJoin _annotatedTree
+                       wrapIfJoin tr = case tr of
+                                          JoinTref {} -> TableRefParens emptyAnnotation tr
+                                          _ -> tr
+                   in maybe _annotatedTree     mk _newAlias
+                   {-# LINE 27119 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 135, column 7)
+              _newAlias =
+                  ({-# LINE 135 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   if tcfAddFullTablerefAliases _lhsIflags
+                   then do
+                     env <- either (const Nothing) Just _eEnv
+                     cs <- either (const Nothing) Just $ E.envExpandStar Nothing env
+                     let qs = map (fst . fst) cs
+                     if all (== head qs) qs
+                       then return (T.unpack $ head qs, map (T.unpack . snd . fst) cs)
+                       else
+                                                            Nothing
+                   else Nothing
+                   {-# LINE 27134 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   JoinTref _annIannotatedTree _tref0IannotatedTree nat_ joinType_ joinHint_ _tref1IannotatedTree _onExprIannotatedTree
+                   {-# LINE 27140 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   JoinTref _annIoriginalTree _tref0IoriginalTree nat_ joinType_ joinHint_ _tref1IoriginalTree _onExprIoriginalTree
+                   {-# LINE 27146 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 27152 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27158 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27164 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 27170 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tref0Ocat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27176 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tref0Oflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27182 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tref0OimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 27188 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tref1Ocat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27194 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tref1Oflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27200 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tref1OimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 27206 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _onExprOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27212 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _onExprOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27218 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _onExprOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 27224 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _tref0IannotatedTree,_tref0IoriginalTree,_tref0IupEnv) =
+                  tref0_ _tref0Ocat _tref0Oflags _tref0OimCast
+              ( _tref1IannotatedTree,_tref1IoriginalTree,_tref1IupEnv) =
+                  tref1_ _tref1Ocat _tref1Oflags _tref1OimCast
+              ( _onExprIannotatedTree,_onExprIoriginalTree) =
+                  onExpr_ _onExprOcat _onExprOdownEnv _onExprOflags _onExprOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupEnv)))
+_sem_TableRef_TableAlias :: T_Annotation ->
+                           NameComponent ->
+                           T_TableRef ->
+                           T_TableRef
+_sem_TableRef_TableAlias ann_ tb_ tref_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupEnv :: Environment
+              _eEnv :: (Either [TypeError] Environment)
+              _lhsOannotatedTree :: TableRef
+              _lhsOoriginalTree :: TableRef
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _trefOcat :: Catalog
+              _trefOflags :: TypeCheckFlags
+              _trefOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _trefIannotatedTree :: TableRef
+              _trefIoriginalTree :: TableRef
+              _trefIupEnv :: Environment
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 33, column 7)
+              _annOtpe =
+                  ({-# LINE 33 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either Left (Right . mkTypeExtraNN . TrefType)
+                   (_eEnv     >>= E.envExpandStar Nothing)
+                   {-# LINE 27264 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 36, column 7)
+              _lhsOupEnv =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either (const E.brokeEnvironment) id _eEnv
+                   {-# LINE 27270 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 68, column 7)
+              _eEnv =
+                  ({-# LINE 68 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   Right $ E.createTrefAliasedEnvironment
+                           (ncStrT tb_) Nothing _trefIupEnv
+                   {-# LINE 27277 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 124, column 7)
+              _lhsOannotatedTree =
+                  ({-# LINE 124 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   case _trefIannotatedTree of
+                     FullAlias _ _ c tr -> FullAlias emptyAnnotation tb_ c tr
+                     TableAlias _ _ tr -> TableAlias emptyAnnotation tb_ tr
+                     _ -> _annotatedTree
+                   {-# LINE 27286 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   TableAlias _annIannotatedTree tb_ _trefIannotatedTree
+                   {-# LINE 27292 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   TableAlias _annIoriginalTree tb_ _trefIoriginalTree
+                   {-# LINE 27298 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 27304 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27310 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27316 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 27322 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _trefOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27328 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _trefOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27334 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _trefOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 27340 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _trefIannotatedTree,_trefIoriginalTree,_trefIupEnv) =
+                  tref_ _trefOcat _trefOflags _trefOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupEnv)))
+_sem_TableRef_FullAlias :: T_Annotation ->
+                          NameComponent ->
+                          ([NameComponent]) ->
+                          T_TableRef ->
+                          T_TableRef
+_sem_TableRef_FullAlias ann_ tb_ cols_ tref_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupEnv :: Environment
+              _eEnv :: (Either [TypeError] Environment)
+              _lhsOannotatedTree :: TableRef
+              _lhsOoriginalTree :: TableRef
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _trefOcat :: Catalog
+              _trefOflags :: TypeCheckFlags
+              _trefOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _trefIannotatedTree :: TableRef
+              _trefIoriginalTree :: TableRef
+              _trefIupEnv :: Environment
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 33, column 7)
+              _annOtpe =
+                  ({-# LINE 33 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either Left (Right . mkTypeExtraNN . TrefType)
+                   (_eEnv     >>= E.envExpandStar Nothing)
+                   {-# LINE 27377 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 36, column 7)
+              _lhsOupEnv =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either (const E.brokeEnvironment) id _eEnv
+                   {-# LINE 27383 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 65, column 7)
+              _eEnv =
+                  ({-# LINE 65 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   Right $ E.createTrefAliasedEnvironment
+                           (ncStrT tb_) (Just $ map ncStrT cols_) _trefIupEnv
+                   {-# LINE 27390 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 103, column 7)
+              _lhsOannotatedTree =
+                  ({-# LINE 103 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   case _trefIannotatedTree of
+                     FullAlias _ t _ tr -> FullAlias emptyAnnotation
+                                             (if tb_ == Nmc "" then t else tb_) cols_                       tr
+                     TableAlias _ _ tr -> FullAlias emptyAnnotation tb_ cols_                        tr
+                     _ -> _annotatedTree
+                   {-# LINE 27400 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   FullAlias _annIannotatedTree tb_ cols_ _trefIannotatedTree
+                   {-# LINE 27406 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   FullAlias _annIoriginalTree tb_ cols_ _trefIoriginalTree
+                   {-# LINE 27412 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 27418 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27424 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27430 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 27436 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _trefOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27442 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _trefOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27448 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _trefOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 27454 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _trefIannotatedTree,_trefIoriginalTree,_trefIupEnv) =
+                  tref_ _trefOcat _trefOflags _trefOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupEnv)))
+_sem_TableRef_TableRefParens :: T_Annotation ->
+                               T_TableRef ->
+                               T_TableRef
+_sem_TableRef_TableRefParens ann_ tref_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupEnv :: Environment
+              _eEnv :: (Either [TypeError] Environment)
+              _lhsOannotatedTree :: TableRef
+              _lhsOoriginalTree :: TableRef
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _trefOcat :: Catalog
+              _trefOflags :: TypeCheckFlags
+              _trefOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _trefIannotatedTree :: TableRef
+              _trefIoriginalTree :: TableRef
+              _trefIupEnv :: Environment
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 33, column 7)
+              _annOtpe =
+                  ({-# LINE 33 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either Left (Right . mkTypeExtraNN . TrefType)
+                   (_eEnv     >>= E.envExpandStar Nothing)
+                   {-# LINE 27489 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 36, column 7)
+              _lhsOupEnv =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either (const E.brokeEnvironment) id _eEnv
+                   {-# LINE 27495 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 63, column 7)
+              _eEnv =
+                  ({-# LINE 63 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   Right $ _trefIupEnv
+                   {-# LINE 27501 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 75, column 7)
+              _lhsOannotatedTree =
+                  ({-# LINE 75 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   let mk (q,is) = FullAlias emptyAnnotation
+                                            (Nmc q)
+                                            (map Nmc is)
+                                            $ wrapIfJoin _annotatedTree
+                       wrapIfJoin tr = case tr of
+                                          JoinTref {} -> TableRefParens emptyAnnotation tr
+                                          _ -> tr
+                   in maybe _annotatedTree     mk _newAlias
+                   {-# LINE 27514 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 135, column 7)
+              _newAlias =
+                  ({-# LINE 135 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   if tcfAddFullTablerefAliases _lhsIflags
+                   then do
+                     env <- either (const Nothing) Just _eEnv
+                     cs <- either (const Nothing) Just $ E.envExpandStar Nothing env
+                     let qs = map (fst . fst) cs
+                     if all (== head qs) qs
+                       then return (T.unpack $ head qs, map (T.unpack . snd . fst) cs)
+                       else
+                                                            Nothing
+                   else Nothing
+                   {-# LINE 27529 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   TableRefParens _annIannotatedTree _trefIannotatedTree
+                   {-# LINE 27535 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   TableRefParens _annIoriginalTree _trefIoriginalTree
+                   {-# LINE 27541 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 27547 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27553 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27559 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 27565 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _trefOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27571 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _trefOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27577 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _trefOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 27583 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _trefIannotatedTree,_trefIoriginalTree,_trefIupEnv) =
+                  tref_ _trefOcat _trefOflags _trefOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupEnv)))
+_sem_TableRef_OdbcTableRef :: T_Annotation ->
+                             T_TableRef ->
+                             T_TableRef
+_sem_TableRef_OdbcTableRef ann_ tref_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOupEnv :: Environment
+              _eEnv :: (Either [TypeError] Environment)
+              _lhsOannotatedTree :: TableRef
+              _lhsOoriginalTree :: TableRef
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _trefOcat :: Catalog
+              _trefOflags :: TypeCheckFlags
+              _trefOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _trefIannotatedTree :: TableRef
+              _trefIoriginalTree :: TableRef
+              _trefIupEnv :: Environment
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 33, column 7)
+              _annOtpe =
+                  ({-# LINE 33 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either Left (Right . mkTypeExtraNN . TrefType)
+                   (_eEnv     >>= E.envExpandStar Nothing)
+                   {-# LINE 27618 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 36, column 7)
+              _lhsOupEnv =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   either (const E.brokeEnvironment) id _eEnv
+                   {-# LINE 27624 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 63, column 7)
+              _eEnv =
+                  ({-# LINE 63 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   Right $ _trefIupEnv
+                   {-# LINE 27630 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 75, column 7)
+              _lhsOannotatedTree =
+                  ({-# LINE 75 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   let mk (q,is) = FullAlias emptyAnnotation
+                                            (Nmc q)
+                                            (map Nmc is)
+                                            $ wrapIfJoin _annotatedTree
+                       wrapIfJoin tr = case tr of
+                                          JoinTref {} -> TableRefParens emptyAnnotation tr
+                                          _ -> tr
+                   in maybe _annotatedTree     mk _newAlias
+                   {-# LINE 27643 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 135, column 7)
+              _newAlias =
+                  ({-# LINE 135 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   if tcfAddFullTablerefAliases _lhsIflags
+                   then do
+                     env <- either (const Nothing) Just _eEnv
+                     cs <- either (const Nothing) Just $ E.envExpandStar Nothing env
+                     let qs = map (fst . fst) cs
+                     if all (== head qs) qs
+                       then return (T.unpack $ head qs, map (T.unpack . snd . fst) cs)
+                       else
+                                                            Nothing
+                   else Nothing
+                   {-# LINE 27658 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   OdbcTableRef _annIannotatedTree _trefIannotatedTree
+                   {-# LINE 27664 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   OdbcTableRef _annIoriginalTree _trefIoriginalTree
+                   {-# LINE 27670 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 27676 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27682 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27688 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 27694 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _trefOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27700 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _trefOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27706 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _trefOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 27712 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _trefIannotatedTree,_trefIoriginalTree,_trefIupEnv) =
+                  tref_ _trefOcat _trefOflags _trefOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupEnv)))
+-- TableRefList ------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : TableRefList 
+         originalTree         : TableRefList 
+         upEnv                : Environment
+   alternatives:
+      alternative Cons:
+         child hd             : TableRef 
+         child tl             : TableRefList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type TableRefList = [TableRef]
+-- cata
+_sem_TableRefList :: TableRefList ->
+                    T_TableRefList
+_sem_TableRefList list =
+    (Prelude.foldr _sem_TableRefList_Cons _sem_TableRefList_Nil (Prelude.map _sem_TableRef list))
+-- semantic domain
+type T_TableRefList = Catalog ->
+                      TypeCheckFlags ->
+                      (Maybe TypeExtra) ->
+                      ( TableRefList,TableRefList,Environment)
+data Inh_TableRefList = Inh_TableRefList {_cat_Inh_TableRefList :: Catalog,_flags_Inh_TableRefList :: TypeCheckFlags,_imCast_Inh_TableRefList :: (Maybe TypeExtra)}
+data Syn_TableRefList = Syn_TableRefList {_annotatedTree_Syn_TableRefList :: TableRefList,_originalTree_Syn_TableRefList :: TableRefList,_upEnv_Syn_TableRefList :: Environment}
+_wrap_TableRefList :: T_TableRefList ->
+                     Inh_TableRefList ->
+                     Syn_TableRefList
+_wrap_TableRefList sem (Inh_TableRefList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupEnv) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_TableRefList _lhsOannotatedTree _lhsOoriginalTree _lhsOupEnv))
+_sem_TableRefList_Cons :: T_TableRef ->
+                         T_TableRefList ->
+                         T_TableRefList
+_sem_TableRefList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOupEnv :: Environment
+              _lhsOannotatedTree :: TableRefList
+              _lhsOoriginalTree :: TableRefList
+              _hdOcat :: Catalog
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: TableRef
+              _hdIoriginalTree :: TableRef
+              _hdIupEnv :: Environment
+              _tlIannotatedTree :: TableRefList
+              _tlIoriginalTree :: TableRefList
+              _tlIupEnv :: Environment
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 20, column 7)
+              _lhsOupEnv =
+                  ({-# LINE 20 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   if E.isEmptyEnv _tlIupEnv
+                   then _hdIupEnv
+                   else
+                          either (error . show) id $
+                          E.createJoinTrefEnvironment _lhsIcat _hdIupEnv _tlIupEnv E.Inner $ Just []
+                   {-# LINE 27791 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 27797 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 27803 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 27809 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 27815 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27821 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27827 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 27833 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27839 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27845 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 27851 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree,_hdIupEnv) =
+                  hd_ _hdOcat _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree,_tlIupEnv) =
+                  tl_ _tlOcat _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupEnv)))
+_sem_TableRefList_Nil :: T_TableRefList
+_sem_TableRefList_Nil =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOupEnv :: Environment
+              _lhsOannotatedTree :: TableRefList
+              _lhsOoriginalTree :: TableRefList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag"(line 18, column 9)
+              _lhsOupEnv =
+                  ({-# LINE 18 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/TableRefs.ag" #-}
+                   E.emptyEnvironment
+                   {-# LINE 27870 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 27876 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 27882 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 27888 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 27894 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree,_lhsOupEnv)))
+-- TypeAttributeDef --------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : TypeAttributeDef 
+         originalTree         : TypeAttributeDef 
+   alternatives:
+      alternative TypeAttDef:
+         child ann            : Annotation 
+         child name           : {NameComponent}
+         child typ            : TypeName 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data TypeAttributeDef = TypeAttDef (Annotation) (NameComponent) (TypeName)
+                      deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_TypeAttributeDef :: TypeAttributeDef ->
+                        T_TypeAttributeDef
+_sem_TypeAttributeDef (TypeAttDef _ann _name _typ) =
+    (_sem_TypeAttributeDef_TypeAttDef (_sem_Annotation _ann) _name (_sem_TypeName _typ))
+-- semantic domain
+type T_TypeAttributeDef = Catalog ->
+                          TypeCheckFlags ->
+                          (Maybe TypeExtra) ->
+                          ( TypeAttributeDef,TypeAttributeDef)
+data Inh_TypeAttributeDef = Inh_TypeAttributeDef {_cat_Inh_TypeAttributeDef :: Catalog,_flags_Inh_TypeAttributeDef :: TypeCheckFlags,_imCast_Inh_TypeAttributeDef :: (Maybe TypeExtra)}
+data Syn_TypeAttributeDef = Syn_TypeAttributeDef {_annotatedTree_Syn_TypeAttributeDef :: TypeAttributeDef,_originalTree_Syn_TypeAttributeDef :: TypeAttributeDef}
+_wrap_TypeAttributeDef :: T_TypeAttributeDef ->
+                         Inh_TypeAttributeDef ->
+                         Syn_TypeAttributeDef
+_wrap_TypeAttributeDef sem (Inh_TypeAttributeDef _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_TypeAttributeDef _lhsOannotatedTree _lhsOoriginalTree))
+_sem_TypeAttributeDef_TypeAttDef :: T_Annotation ->
+                                   NameComponent ->
+                                   T_TypeName ->
+                                   T_TypeAttributeDef
+_sem_TypeAttributeDef_TypeAttDef ann_ name_ typ_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: TypeAttributeDef
+              _lhsOoriginalTree :: TypeAttributeDef
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _typOcat :: Catalog
+              _typOflags :: TypeCheckFlags
+              _typOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _typIannotatedTree :: TypeName
+              _typInamedType :: (Maybe TypeExtra)
+              _typIoriginalTree :: TypeName
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 231, column 35)
+              _annOtpe =
+                  ({-# LINE 231 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 27962 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   TypeAttDef _annIannotatedTree name_ _typIannotatedTree
+                   {-# LINE 27968 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   TypeAttDef _annIoriginalTree name_ _typIoriginalTree
+                   {-# LINE 27974 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 27980 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 27986 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 27992 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 27998 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 28004 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 28010 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 28016 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 28022 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _typIannotatedTree,_typInamedType,_typIoriginalTree) =
+                  typ_ _typOcat _typOflags _typOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- TypeAttributeDefList ----------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : TypeAttributeDefList 
+         originalTree         : TypeAttributeDefList 
+   alternatives:
+      alternative Cons:
+         child hd             : TypeAttributeDef 
+         child tl             : TypeAttributeDefList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type TypeAttributeDefList = [TypeAttributeDef]
+-- cata
+_sem_TypeAttributeDefList :: TypeAttributeDefList ->
+                            T_TypeAttributeDefList
+_sem_TypeAttributeDefList list =
+    (Prelude.foldr _sem_TypeAttributeDefList_Cons _sem_TypeAttributeDefList_Nil (Prelude.map _sem_TypeAttributeDef list))
+-- semantic domain
+type T_TypeAttributeDefList = Catalog ->
+                              TypeCheckFlags ->
+                              (Maybe TypeExtra) ->
+                              ( TypeAttributeDefList,TypeAttributeDefList)
+data Inh_TypeAttributeDefList = Inh_TypeAttributeDefList {_cat_Inh_TypeAttributeDefList :: Catalog,_flags_Inh_TypeAttributeDefList :: TypeCheckFlags,_imCast_Inh_TypeAttributeDefList :: (Maybe TypeExtra)}
+data Syn_TypeAttributeDefList = Syn_TypeAttributeDefList {_annotatedTree_Syn_TypeAttributeDefList :: TypeAttributeDefList,_originalTree_Syn_TypeAttributeDefList :: TypeAttributeDefList}
+_wrap_TypeAttributeDefList :: T_TypeAttributeDefList ->
+                             Inh_TypeAttributeDefList ->
+                             Syn_TypeAttributeDefList
+_wrap_TypeAttributeDefList sem (Inh_TypeAttributeDefList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_TypeAttributeDefList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_TypeAttributeDefList_Cons :: T_TypeAttributeDef ->
+                                 T_TypeAttributeDefList ->
+                                 T_TypeAttributeDefList
+_sem_TypeAttributeDefList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: TypeAttributeDefList
+              _lhsOoriginalTree :: TypeAttributeDefList
+              _hdOcat :: Catalog
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: TypeAttributeDef
+              _hdIoriginalTree :: TypeAttributeDef
+              _tlIannotatedTree :: TypeAttributeDefList
+              _tlIoriginalTree :: TypeAttributeDefList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 28093 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 28099 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 28105 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 28111 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 28117 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 28123 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 28129 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 28135 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 28141 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 28147 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree) =
+                  hd_ _hdOcat _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_TypeAttributeDefList_Nil :: T_TypeAttributeDefList
+_sem_TypeAttributeDefList_Nil =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: TypeAttributeDefList
+              _lhsOoriginalTree :: TypeAttributeDefList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 28165 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 28171 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 28177 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 28183 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- TypeName ----------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : TypeName 
+         namedType            : Maybe TypeExtra
+         originalTree         : TypeName 
+   alternatives:
+      alternative SimpleTypeName:
+         child ann            : Annotation 
+         child tn             : Name 
+         visit 0:
+            local canType     : {[NameComponent] -> [NameComponent]}
+            local tpe         : {Either [TypeError] TypeExtra}
+            local annotatedTree : _
+            local originalTree : _
+      alternative PrecTypeName:
+         child ann            : Annotation 
+         child tn             : Name 
+         child prec           : {Integer}
+         visit 0:
+            local canType     : {[NameComponent] -> [NameComponent]}
+            local tpe         : {Either [TypeError] TypeExtra}
+            local annotatedTree : _
+            local originalTree : _
+      alternative Prec2TypeName:
+         child ann            : Annotation 
+         child tn             : Name 
+         child prec           : {Integer}
+         child prec1          : {Integer}
+         visit 0:
+            local canType     : {[NameComponent] -> [NameComponent]}
+            local tpe         : {Either [TypeError] TypeExtra}
+            local annotatedTree : _
+            local originalTree : _
+      alternative ArrayTypeName:
+         child ann            : Annotation 
+         child typ            : TypeName 
+         visit 0:
+            local canType     : {[NameComponent] -> [NameComponent]}
+            local tpe         : {Either [TypeError] TypeExtra}
+            local annotatedTree : _
+            local originalTree : _
+      alternative SetOfTypeName:
+         child ann            : Annotation 
+         child typ            : TypeName 
+         visit 0:
+            local canType     : {[NameComponent] -> [NameComponent]}
+            local tpe         : {Either [TypeError] TypeExtra}
+            local annotatedTree : _
+            local originalTree : _
+-}
+data TypeName = SimpleTypeName (Annotation) (Name)
+              | PrecTypeName (Annotation) (Name) (Integer)
+              | Prec2TypeName (Annotation) (Name) (Integer) (Integer)
+              | ArrayTypeName (Annotation) (TypeName)
+              | SetOfTypeName (Annotation) (TypeName)
+              deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_TypeName :: TypeName ->
+                T_TypeName
+_sem_TypeName (SimpleTypeName _ann _tn) =
+    (_sem_TypeName_SimpleTypeName (_sem_Annotation _ann) (_sem_Name _tn))
+_sem_TypeName (PrecTypeName _ann _tn _prec) =
+    (_sem_TypeName_PrecTypeName (_sem_Annotation _ann) (_sem_Name _tn) _prec)
+_sem_TypeName (Prec2TypeName _ann _tn _prec _prec1) =
+    (_sem_TypeName_Prec2TypeName (_sem_Annotation _ann) (_sem_Name _tn) _prec _prec1)
+_sem_TypeName (ArrayTypeName _ann _typ) =
+    (_sem_TypeName_ArrayTypeName (_sem_Annotation _ann) (_sem_TypeName _typ))
+_sem_TypeName (SetOfTypeName _ann _typ) =
+    (_sem_TypeName_SetOfTypeName (_sem_Annotation _ann) (_sem_TypeName _typ))
+-- semantic domain
+type T_TypeName = Catalog ->
+                  TypeCheckFlags ->
+                  (Maybe TypeExtra) ->
+                  ( TypeName,(Maybe TypeExtra),TypeName)
+data Inh_TypeName = Inh_TypeName {_cat_Inh_TypeName :: Catalog,_flags_Inh_TypeName :: TypeCheckFlags,_imCast_Inh_TypeName :: (Maybe TypeExtra)}
+data Syn_TypeName = Syn_TypeName {_annotatedTree_Syn_TypeName :: TypeName,_namedType_Syn_TypeName :: (Maybe TypeExtra),_originalTree_Syn_TypeName :: TypeName}
+_wrap_TypeName :: T_TypeName ->
+                 Inh_TypeName ->
+                 Syn_TypeName
+_wrap_TypeName sem (Inh_TypeName _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOnamedType,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_TypeName _lhsOannotatedTree _lhsOnamedType _lhsOoriginalTree))
+_sem_TypeName_SimpleTypeName :: T_Annotation ->
+                               T_Name ->
+                               T_TypeName
+_sem_TypeName_SimpleTypeName ann_ tn_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOnamedType :: (Maybe TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _tnOtpe :: (Either [TypeError] TypeExtra)
+              _canType :: ([NameComponent] -> [NameComponent])
+              _tpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: TypeName
+              _lhsOoriginalTree :: TypeName
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _tnOcat :: Catalog
+              _tnOflags :: TypeCheckFlags
+              _tnOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _tnIannotatedTree :: Name
+              _tnIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 36, column 10)
+              _lhsOnamedType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 28302 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 37, column 10)
+              _annOtpe =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   either Left (const $ Left []) _tpe
+                   {-# LINE 28308 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 39, column 10)
+              _tnOtpe =
+                  ({-# LINE 39 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   Left []
+                   {-# LINE 28314 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 51, column 10)
+              _canType =
+                  ({-# LINE 51 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   \x -> case x of
+                      [Nmc nc] -> [Nmc $ T.unpack $ canonicalizeTypeName (tcfDialect _lhsIflags) $ T.pack nc]
+                      _ -> x
+                   {-# LINE 28322 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 63, column 10)
+              _tpe =
+                  ({-# LINE 63 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   mkTypeExtraNN `liftM` catLookupType _lhsIcat (_canType     $ nameComponents _tnIoriginalTree)
+                   {-# LINE 28328 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SimpleTypeName _annIannotatedTree _tnIannotatedTree
+                   {-# LINE 28334 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SimpleTypeName _annIoriginalTree _tnIoriginalTree
+                   {-# LINE 28340 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 28346 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 28352 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 28358 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 28364 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 28370 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tnOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 28376 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tnOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 28382 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tnOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 28388 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _tnIannotatedTree,_tnIoriginalTree) =
+                  tn_ _tnOcat _tnOflags _tnOimCast _tnOtpe
+          in  ( _lhsOannotatedTree,_lhsOnamedType,_lhsOoriginalTree)))
+_sem_TypeName_PrecTypeName :: T_Annotation ->
+                             T_Name ->
+                             Integer ->
+                             T_TypeName
+_sem_TypeName_PrecTypeName ann_ tn_ prec_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOnamedType :: (Maybe TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _tnOtpe :: (Either [TypeError] TypeExtra)
+              _canType :: ([NameComponent] -> [NameComponent])
+              _tpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: TypeName
+              _lhsOoriginalTree :: TypeName
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _tnOcat :: Catalog
+              _tnOflags :: TypeCheckFlags
+              _tnOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _tnIannotatedTree :: Name
+              _tnIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 36, column 10)
+              _lhsOnamedType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 28424 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 37, column 10)
+              _annOtpe =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   either Left (const $ Left []) _tpe
+                   {-# LINE 28430 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 39, column 10)
+              _tnOtpe =
+                  ({-# LINE 39 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   Left []
+                   {-# LINE 28436 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 51, column 10)
+              _canType =
+                  ({-# LINE 51 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   \x -> case x of
+                      [Nmc nc] -> [Nmc $ T.unpack $ canonicalizeTypeName (tcfDialect _lhsIflags) $ T.pack nc]
+                      _ -> x
+                   {-# LINE 28444 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 77, column 9)
+              _tpe =
+                  ({-# LINE 77 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   ((\t -> t{tePrecision = Just $ fromIntegral prec_}) . mkTypeExtraNN)
+                   `liftM` catLookupType _lhsIcat (nameComponents _tnIoriginalTree)
+                   {-# LINE 28451 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   PrecTypeName _annIannotatedTree _tnIannotatedTree prec_
+                   {-# LINE 28457 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   PrecTypeName _annIoriginalTree _tnIoriginalTree prec_
+                   {-# LINE 28463 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 28469 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 28475 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 28481 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 28487 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 28493 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tnOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 28499 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tnOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 28505 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tnOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 28511 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _tnIannotatedTree,_tnIoriginalTree) =
+                  tn_ _tnOcat _tnOflags _tnOimCast _tnOtpe
+          in  ( _lhsOannotatedTree,_lhsOnamedType,_lhsOoriginalTree)))
+_sem_TypeName_Prec2TypeName :: T_Annotation ->
+                              T_Name ->
+                              Integer ->
+                              Integer ->
+                              T_TypeName
+_sem_TypeName_Prec2TypeName ann_ tn_ prec_ prec1_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOnamedType :: (Maybe TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _tnOtpe :: (Either [TypeError] TypeExtra)
+              _canType :: ([NameComponent] -> [NameComponent])
+              _tpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: TypeName
+              _lhsOoriginalTree :: TypeName
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _tnOcat :: Catalog
+              _tnOflags :: TypeCheckFlags
+              _tnOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _tnIannotatedTree :: Name
+              _tnIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 36, column 10)
+              _lhsOnamedType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 28548 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 37, column 10)
+              _annOtpe =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   either Left (const $ Left []) _tpe
+                   {-# LINE 28554 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 39, column 10)
+              _tnOtpe =
+                  ({-# LINE 39 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   Left []
+                   {-# LINE 28560 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 51, column 10)
+              _canType =
+                  ({-# LINE 51 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   \x -> case x of
+                      [Nmc nc] -> [Nmc $ T.unpack $ canonicalizeTypeName (tcfDialect _lhsIflags) $ T.pack nc]
+                      _ -> x
+                   {-# LINE 28568 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 80, column 9)
+              _tpe =
+                  ({-# LINE 80 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   ((\t -> t{tePrecision = Just $ fromIntegral prec_,
+                             teScale = Just $ fromIntegral prec1_})
+                         . mkTypeExtraNN)
+                   `liftM` catLookupType _lhsIcat (nameComponents _tnIoriginalTree)
+                   {-# LINE 28577 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Prec2TypeName _annIannotatedTree _tnIannotatedTree prec_ prec1_
+                   {-# LINE 28583 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   Prec2TypeName _annIoriginalTree _tnIoriginalTree prec_ prec1_
+                   {-# LINE 28589 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 28595 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 28601 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 28607 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 28613 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 28619 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tnOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 28625 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tnOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 28631 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tnOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 28637 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _tnIannotatedTree,_tnIoriginalTree) =
+                  tn_ _tnOcat _tnOflags _tnOimCast _tnOtpe
+          in  ( _lhsOannotatedTree,_lhsOnamedType,_lhsOoriginalTree)))
+_sem_TypeName_ArrayTypeName :: T_Annotation ->
+                              T_TypeName ->
+                              T_TypeName
+_sem_TypeName_ArrayTypeName ann_ typ_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOnamedType :: (Maybe TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _canType :: ([NameComponent] -> [NameComponent])
+              _tpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: TypeName
+              _lhsOoriginalTree :: TypeName
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _typOcat :: Catalog
+              _typOflags :: TypeCheckFlags
+              _typOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _typIannotatedTree :: TypeName
+              _typInamedType :: (Maybe TypeExtra)
+              _typIoriginalTree :: TypeName
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 36, column 10)
+              _lhsOnamedType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 28672 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 37, column 10)
+              _annOtpe =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   either Left (const $ Left []) _tpe
+                   {-# LINE 28678 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 51, column 10)
+              _canType =
+                  ({-# LINE 51 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   \x -> case x of
+                      [Nmc nc] -> [Nmc $ T.unpack $ canonicalizeTypeName (tcfDialect _lhsIflags) $ T.pack nc]
+                      _ -> x
+                   {-# LINE 28686 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 71, column 9)
+              _tpe =
+                  ({-# LINE 71 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   maybe (Left []) Right _typInamedType
+                   >>= Right . (\t -> t{teType = ArrayType $ teType t})
+                   {-# LINE 28693 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ArrayTypeName _annIannotatedTree _typIannotatedTree
+                   {-# LINE 28699 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ArrayTypeName _annIoriginalTree _typIoriginalTree
+                   {-# LINE 28705 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 28711 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 28717 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 28723 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 28729 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 28735 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 28741 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 28747 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 28753 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _typIannotatedTree,_typInamedType,_typIoriginalTree) =
+                  typ_ _typOcat _typOflags _typOimCast
+          in  ( _lhsOannotatedTree,_lhsOnamedType,_lhsOoriginalTree)))
+_sem_TypeName_SetOfTypeName :: T_Annotation ->
+                              T_TypeName ->
+                              T_TypeName
+_sem_TypeName_SetOfTypeName ann_ typ_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOnamedType :: (Maybe TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _canType :: ([NameComponent] -> [NameComponent])
+              _tpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: TypeName
+              _lhsOoriginalTree :: TypeName
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _typOcat :: Catalog
+              _typOflags :: TypeCheckFlags
+              _typOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _typIannotatedTree :: TypeName
+              _typInamedType :: (Maybe TypeExtra)
+              _typIoriginalTree :: TypeName
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 36, column 10)
+              _lhsOnamedType =
+                  ({-# LINE 36 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   either (const Nothing) Just _tpe
+                   {-# LINE 28788 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 37, column 10)
+              _annOtpe =
+                  ({-# LINE 37 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   either Left (const $ Left []) _tpe
+                   {-# LINE 28794 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 51, column 10)
+              _canType =
+                  ({-# LINE 51 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   \x -> case x of
+                      [Nmc nc] -> [Nmc $ T.unpack $ canonicalizeTypeName (tcfDialect _lhsIflags) $ T.pack nc]
+                      _ -> x
+                   {-# LINE 28802 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag"(line 74, column 9)
+              _tpe =
+                  ({-# LINE 74 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Misc.ag" #-}
+                   maybe (Left []) Right _typInamedType
+                   >>= Right . (\t -> t{teType = Pseudo $ SetOfType $ teType t})
+                   {-# LINE 28809 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SetOfTypeName _annIannotatedTree _typIannotatedTree
+                   {-# LINE 28815 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   SetOfTypeName _annIoriginalTree _typIoriginalTree
+                   {-# LINE 28821 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 28827 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 28833 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 28839 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 28845 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 28851 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 28857 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 28863 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 28869 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _typIannotatedTree,_typInamedType,_typIoriginalTree) =
+                  typ_ _typOcat _typOflags _typOimCast
+          in  ( _lhsOannotatedTree,_lhsOnamedType,_lhsOoriginalTree)))
+-- TypeNameList ------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : TypeNameList 
+         originalTree         : TypeNameList 
+   alternatives:
+      alternative Cons:
+         child hd             : TypeName 
+         child tl             : TypeNameList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type TypeNameList = [TypeName]
+-- cata
+_sem_TypeNameList :: TypeNameList ->
+                    T_TypeNameList
+_sem_TypeNameList list =
+    (Prelude.foldr _sem_TypeNameList_Cons _sem_TypeNameList_Nil (Prelude.map _sem_TypeName list))
+-- semantic domain
+type T_TypeNameList = Catalog ->
+                      TypeCheckFlags ->
+                      (Maybe TypeExtra) ->
+                      ( TypeNameList,TypeNameList)
+data Inh_TypeNameList = Inh_TypeNameList {_cat_Inh_TypeNameList :: Catalog,_flags_Inh_TypeNameList :: TypeCheckFlags,_imCast_Inh_TypeNameList :: (Maybe TypeExtra)}
+data Syn_TypeNameList = Syn_TypeNameList {_annotatedTree_Syn_TypeNameList :: TypeNameList,_originalTree_Syn_TypeNameList :: TypeNameList}
+_wrap_TypeNameList :: T_TypeNameList ->
+                     Inh_TypeNameList ->
+                     Syn_TypeNameList
+_wrap_TypeNameList sem (Inh_TypeNameList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_TypeNameList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_TypeNameList_Cons :: T_TypeName ->
+                         T_TypeNameList ->
+                         T_TypeNameList
+_sem_TypeNameList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: TypeNameList
+              _lhsOoriginalTree :: TypeNameList
+              _hdOcat :: Catalog
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: TypeName
+              _hdInamedType :: (Maybe TypeExtra)
+              _hdIoriginalTree :: TypeName
+              _tlIannotatedTree :: TypeNameList
+              _tlIoriginalTree :: TypeNameList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 28941 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 28947 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 28953 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 28959 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 28965 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 28971 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 28977 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 28983 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 28989 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 28995 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdInamedType,_hdIoriginalTree) =
+                  hd_ _hdOcat _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_TypeNameList_Nil :: T_TypeNameList
+_sem_TypeNameList_Nil =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: TypeNameList
+              _lhsOoriginalTree :: TypeNameList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 29013 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 29019 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 29025 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 29031 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- VarDef ------------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : VarDef 
+         originalTree         : VarDef 
+   alternatives:
+      alternative VarDef:
+         child ann            : Annotation 
+         child name           : {NameComponent}
+         child typ            : TypeName 
+         child value          : {Maybe ScalarExpr}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative ParamAlias:
+         child ann            : Annotation 
+         child name           : {NameComponent}
+         child i              : {Integer}
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative VarAlias:
+         child ann            : Annotation 
+         child name           : {NameComponent}
+         child aliased        : Name 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+data VarDef = VarDef (Annotation) (NameComponent) (TypeName) ((Maybe ScalarExpr))
+            | ParamAlias (Annotation) (NameComponent) (Integer)
+            | VarAlias (Annotation) (NameComponent) (Name)
+            deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_VarDef :: VarDef ->
+              T_VarDef
+_sem_VarDef (VarDef _ann _name _typ _value) =
+    (_sem_VarDef_VarDef (_sem_Annotation _ann) _name (_sem_TypeName _typ) _value)
+_sem_VarDef (ParamAlias _ann _name _i) =
+    (_sem_VarDef_ParamAlias (_sem_Annotation _ann) _name _i)
+_sem_VarDef (VarAlias _ann _name _aliased) =
+    (_sem_VarDef_VarAlias (_sem_Annotation _ann) _name (_sem_Name _aliased))
+-- semantic domain
+type T_VarDef = Catalog ->
+                TypeCheckFlags ->
+                (Maybe TypeExtra) ->
+                ( VarDef,VarDef)
+data Inh_VarDef = Inh_VarDef {_cat_Inh_VarDef :: Catalog,_flags_Inh_VarDef :: TypeCheckFlags,_imCast_Inh_VarDef :: (Maybe TypeExtra)}
+data Syn_VarDef = Syn_VarDef {_annotatedTree_Syn_VarDef :: VarDef,_originalTree_Syn_VarDef :: VarDef}
+_wrap_VarDef :: T_VarDef ->
+               Inh_VarDef ->
+               Syn_VarDef
+_wrap_VarDef sem (Inh_VarDef _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_VarDef _lhsOannotatedTree _lhsOoriginalTree))
+_sem_VarDef_VarDef :: T_Annotation ->
+                     NameComponent ->
+                     T_TypeName ->
+                     (Maybe ScalarExpr) ->
+                     T_VarDef
+_sem_VarDef_VarDef ann_ name_ typ_ value_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: VarDef
+              _lhsOoriginalTree :: VarDef
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _typOcat :: Catalog
+              _typOflags :: TypeCheckFlags
+              _typOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _typIannotatedTree :: TypeName
+              _typInamedType :: (Maybe TypeExtra)
+              _typIoriginalTree :: TypeName
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 235, column 21)
+              _annOtpe =
+                  ({-# LINE 235 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 29121 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   VarDef _annIannotatedTree name_ _typIannotatedTree value_
+                   {-# LINE 29127 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   VarDef _annIoriginalTree name_ _typIoriginalTree value_
+                   {-# LINE 29133 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 29139 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 29145 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 29151 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 29157 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 29163 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 29169 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 29175 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _typOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 29181 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _typIannotatedTree,_typInamedType,_typIoriginalTree) =
+                  typ_ _typOcat _typOflags _typOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_VarDef_ParamAlias :: T_Annotation ->
+                         NameComponent ->
+                         Integer ->
+                         T_VarDef
+_sem_VarDef_ParamAlias ann_ name_ i_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: VarDef
+              _lhsOoriginalTree :: VarDef
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 232, column 25)
+              _annOtpe =
+                  ({-# LINE 232 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 29208 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ParamAlias _annIannotatedTree name_ i_
+                   {-# LINE 29214 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   ParamAlias _annIoriginalTree name_ i_
+                   {-# LINE 29220 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 29226 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 29232 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 29238 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 29244 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 29250 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_VarDef_VarAlias :: T_Annotation ->
+                       NameComponent ->
+                       T_Name ->
+                       T_VarDef
+_sem_VarDef_VarAlias ann_ name_ aliased_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _aliasedOtpe :: (Either [TypeError] TypeExtra)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _lhsOannotatedTree :: VarDef
+              _lhsOoriginalTree :: VarDef
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _aliasedOcat :: Catalog
+              _aliasedOflags :: TypeCheckFlags
+              _aliasedOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _aliasedIannotatedTree :: Name
+              _aliasedIoriginalTree :: Name
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 233, column 23)
+              _aliasedOtpe =
+                  ({-# LINE 233 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 29281 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag"(line 234, column 23)
+              _annOtpe =
+                  ({-# LINE 234 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/Boilerplate.ag" #-}
+                   Left []
+                   {-# LINE 29287 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   VarAlias _annIannotatedTree name_ _aliasedIannotatedTree
+                   {-# LINE 29293 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   VarAlias _annIoriginalTree name_ _aliasedIoriginalTree
+                   {-# LINE 29299 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 29305 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 29311 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 29317 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 29323 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 29329 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _aliasedOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 29335 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _aliasedOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 29341 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _aliasedOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 29347 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _aliasedIannotatedTree,_aliasedIoriginalTree) =
+                  aliased_ _aliasedOcat _aliasedOflags _aliasedOimCast _aliasedOtpe
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- VarDefList --------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : VarDefList 
+         originalTree         : VarDefList 
+   alternatives:
+      alternative Cons:
+         child hd             : VarDef 
+         child tl             : VarDefList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type VarDefList = [VarDef]
+-- cata
+_sem_VarDefList :: VarDefList ->
+                  T_VarDefList
+_sem_VarDefList list =
+    (Prelude.foldr _sem_VarDefList_Cons _sem_VarDefList_Nil (Prelude.map _sem_VarDef list))
+-- semantic domain
+type T_VarDefList = Catalog ->
+                    TypeCheckFlags ->
+                    (Maybe TypeExtra) ->
+                    ( VarDefList,VarDefList)
+data Inh_VarDefList = Inh_VarDefList {_cat_Inh_VarDefList :: Catalog,_flags_Inh_VarDefList :: TypeCheckFlags,_imCast_Inh_VarDefList :: (Maybe TypeExtra)}
+data Syn_VarDefList = Syn_VarDefList {_annotatedTree_Syn_VarDefList :: VarDefList,_originalTree_Syn_VarDefList :: VarDefList}
+_wrap_VarDefList :: T_VarDefList ->
+                   Inh_VarDefList ->
+                   Syn_VarDefList
+_wrap_VarDefList sem (Inh_VarDefList _lhsIcat _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOoriginalTree) = sem _lhsIcat _lhsIflags _lhsIimCast
+     in  (Syn_VarDefList _lhsOannotatedTree _lhsOoriginalTree))
+_sem_VarDefList_Cons :: T_VarDef ->
+                       T_VarDefList ->
+                       T_VarDefList
+_sem_VarDefList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: VarDefList
+              _lhsOoriginalTree :: VarDefList
+              _hdOcat :: Catalog
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: VarDef
+              _hdIoriginalTree :: VarDef
+              _tlIannotatedTree :: VarDefList
+              _tlIoriginalTree :: VarDefList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 29418 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 29424 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 29430 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 29436 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 29442 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 29448 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 29454 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 29460 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 29466 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 29472 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIoriginalTree) =
+                  hd_ _hdOcat _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+_sem_VarDefList_Nil :: T_VarDefList
+_sem_VarDefList_Nil =
+    (\ _lhsIcat
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOannotatedTree :: VarDefList
+              _lhsOoriginalTree :: VarDefList
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 29490 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 29496 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 29502 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 29508 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOoriginalTree)))
+-- WithQuery ---------------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         catExtIncomp         : Either [TypeError] Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : WithQuery 
+         colAliases           : Maybe [NameComponent]
+         name                 : Text
+         originalTree         : WithQuery 
+         upType               : Maybe [(Text,TypeExtra)]
+   alternatives:
+      alternative WithQuery:
+         child ann            : Annotation 
+         child name           : {NameComponent}
+         child colAliases     : {Maybe [NameComponent]}
+         child ex             : QueryExpr 
+         visit 0:
+            local tpee        : {Either [TypeError] [(Text,TypeExtra)]}
+            local tpe         : {Either [TypeError] TypeExtra}
+            local annotatedTree : _
+            local originalTree : _
+-}
+data WithQuery = WithQuery (Annotation) (NameComponent) ((Maybe [NameComponent])) (QueryExpr)
+               deriving ( Data,Eq,Show,Typeable)
+-- cata
+_sem_WithQuery :: WithQuery ->
+                 T_WithQuery
+_sem_WithQuery (WithQuery _ann _name _colAliases _ex) =
+    (_sem_WithQuery_WithQuery (_sem_Annotation _ann) _name _colAliases (_sem_QueryExpr _ex))
+-- semantic domain
+type T_WithQuery = Catalog ->
+                   (Either [TypeError] Catalog) ->
+                   TypeCheckFlags ->
+                   (Maybe TypeExtra) ->
+                   ( WithQuery,(Maybe [NameComponent]),Text,WithQuery,(Maybe [(Text,TypeExtra)]))
+data Inh_WithQuery = Inh_WithQuery {_cat_Inh_WithQuery :: Catalog,_catExtIncomp_Inh_WithQuery :: (Either [TypeError] Catalog),_flags_Inh_WithQuery :: TypeCheckFlags,_imCast_Inh_WithQuery :: (Maybe TypeExtra)}
+data Syn_WithQuery = Syn_WithQuery {_annotatedTree_Syn_WithQuery :: WithQuery,_colAliases_Syn_WithQuery :: (Maybe [NameComponent]),_name_Syn_WithQuery :: Text,_originalTree_Syn_WithQuery :: WithQuery,_upType_Syn_WithQuery :: (Maybe [(Text,TypeExtra)])}
+_wrap_WithQuery :: T_WithQuery ->
+                  Inh_WithQuery ->
+                  Syn_WithQuery
+_wrap_WithQuery sem (Inh_WithQuery _lhsIcat _lhsIcatExtIncomp _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOcolAliases,_lhsOname,_lhsOoriginalTree,_lhsOupType) = sem _lhsIcat _lhsIcatExtIncomp _lhsIflags _lhsIimCast
+     in  (Syn_WithQuery _lhsOannotatedTree _lhsOcolAliases _lhsOname _lhsOoriginalTree _lhsOupType))
+_sem_WithQuery_WithQuery :: T_Annotation ->
+                           NameComponent ->
+                           (Maybe [NameComponent]) ->
+                           T_QueryExpr ->
+                           T_WithQuery
+_sem_WithQuery_WithQuery ann_ name_ colAliases_ ex_ =
+    (\ _lhsIcat
+       _lhsIcatExtIncomp
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOname :: Text
+              _lhsOannotatedTree :: WithQuery
+              _lhsOcolAliases :: (Maybe [NameComponent])
+              _tpee :: (Either [TypeError] [(Text,TypeExtra)])
+              _tpe :: (Either [TypeError] TypeExtra)
+              _lhsOupType :: (Maybe [(Text,TypeExtra)])
+              _exOouterDownEnv :: (Maybe Environment)
+              _annOtpe :: (Either [TypeError] TypeExtra)
+              _exOexpectedType :: (Maybe [TypeExtra])
+              _exOassignmentCastContext :: Bool
+              _lhsOoriginalTree :: WithQuery
+              _annOcat :: Catalog
+              _annOflags :: TypeCheckFlags
+              _annOimCast :: (Maybe TypeExtra)
+              _exOcat :: Catalog
+              _exOflags :: TypeCheckFlags
+              _exOimCast :: (Maybe TypeExtra)
+              _annIannotatedTree :: Annotation
+              _annIoriginalTree :: Annotation
+              _exIannotatedTree :: QueryExpr
+              _exIoriginalTree :: QueryExpr
+              _exIupType :: (Maybe [(Text,TypeExtra)])
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 56, column 9)
+              _lhsOname =
+                  ({-# LINE 56 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   ncStrT name_
+                   {-# LINE 29594 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 57, column 9)
+              _lhsOannotatedTree =
+                  ({-# LINE 57 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   WithQuery _annIannotatedTree name_ colAliases_ _exIannotatedTree
+                   {-# LINE 29600 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 58, column 9)
+              _lhsOcolAliases =
+                  ({-# LINE 58 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   colAliases_
+                   {-# LINE 29606 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 62, column 9)
+              _tpee =
+                  ({-# LINE 62 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   maybe (Left []) Right _exIupType
+                   {-# LINE 29612 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 64, column 9)
+              _tpe =
+                  ({-# LINE 64 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   liftM (mkTypeExtra . CompositeType) _tpee
+                   {-# LINE 29618 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 66, column 9)
+              _lhsOupType =
+                  ({-# LINE 66 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   either (const Nothing) Just _tpee
+                   {-# LINE 29624 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 95, column 15)
+              _exOouterDownEnv =
+                  ({-# LINE 95 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   Nothing
+                   {-# LINE 29630 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 101, column 9)
+              _annOtpe =
+                  ({-# LINE 101 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   Left []
+                   {-# LINE 29636 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 102, column 9)
+              _exOexpectedType =
+                  ({-# LINE 102 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   liftM (map snd) _exIupType
+                   {-# LINE 29642 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag"(line 845, column 27)
+              _exOassignmentCastContext =
+                  ({-# LINE 845 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/ScalarExprs.ag" #-}
+                   False
+                   {-# LINE 29648 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   WithQuery _annIannotatedTree name_ colAliases_ _exIannotatedTree
+                   {-# LINE 29654 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   WithQuery _annIoriginalTree name_ colAliases_ _exIoriginalTree
+                   {-# LINE 29660 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 29666 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 29672 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 29678 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _annOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 29684 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 29690 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 29696 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _exOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 29702 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _annIannotatedTree,_annIoriginalTree) =
+                  ann_ _annOcat _annOflags _annOimCast _annOtpe
+              ( _exIannotatedTree,_exIoriginalTree,_exIupType) =
+                  ex_ _exOassignmentCastContext _exOcat _exOexpectedType _exOflags _exOimCast _exOouterDownEnv
+          in  ( _lhsOannotatedTree,_lhsOcolAliases,_lhsOname,_lhsOoriginalTree,_lhsOupType)))
+-- WithQueryList -----------------------------------------------
+{-
+   visit 0:
+      inherited attributes:
+         cat                  : Catalog
+         catExtIncomp         : Either [TypeError] Catalog
+         flags                : TypeCheckFlags
+         imCast               : Maybe TypeExtra
+      synthesized attributes:
+         annotatedTree        : WithQueryList 
+         catExtComp           : Either [TypeError] Catalog
+         originalTree         : WithQueryList 
+   alternatives:
+      alternative Cons:
+         child hd             : WithQuery 
+         child tl             : WithQueryList 
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+      alternative Nil:
+         visit 0:
+            local annotatedTree : _
+            local originalTree : _
+-}
+type WithQueryList = [WithQuery]
+-- cata
+_sem_WithQueryList :: WithQueryList ->
+                     T_WithQueryList
+_sem_WithQueryList list =
+    (Prelude.foldr _sem_WithQueryList_Cons _sem_WithQueryList_Nil (Prelude.map _sem_WithQuery list))
+-- semantic domain
+type T_WithQueryList = Catalog ->
+                       (Either [TypeError] Catalog) ->
+                       TypeCheckFlags ->
+                       (Maybe TypeExtra) ->
+                       ( WithQueryList,(Either [TypeError] Catalog),WithQueryList)
+data Inh_WithQueryList = Inh_WithQueryList {_cat_Inh_WithQueryList :: Catalog,_catExtIncomp_Inh_WithQueryList :: (Either [TypeError] Catalog),_flags_Inh_WithQueryList :: TypeCheckFlags,_imCast_Inh_WithQueryList :: (Maybe TypeExtra)}
+data Syn_WithQueryList = Syn_WithQueryList {_annotatedTree_Syn_WithQueryList :: WithQueryList,_catExtComp_Syn_WithQueryList :: (Either [TypeError] Catalog),_originalTree_Syn_WithQueryList :: WithQueryList}
+_wrap_WithQueryList :: T_WithQueryList ->
+                      Inh_WithQueryList ->
+                      Syn_WithQueryList
+_wrap_WithQueryList sem (Inh_WithQueryList _lhsIcat _lhsIcatExtIncomp _lhsIflags _lhsIimCast) =
+    (let ( _lhsOannotatedTree,_lhsOcatExtComp,_lhsOoriginalTree) = sem _lhsIcat _lhsIcatExtIncomp _lhsIflags _lhsIimCast
+     in  (Syn_WithQueryList _lhsOannotatedTree _lhsOcatExtComp _lhsOoriginalTree))
+_sem_WithQueryList_Cons :: T_WithQuery ->
+                          T_WithQueryList ->
+                          T_WithQueryList
+_sem_WithQueryList_Cons hd_ tl_ =
+    (\ _lhsIcat
+       _lhsIcatExtIncomp
+       _lhsIflags
+       _lhsIimCast ->
+         (let _tlOcatExtIncomp :: (Either [TypeError] Catalog)
+              _hdOcat :: Catalog
+              _lhsOannotatedTree :: WithQueryList
+              _lhsOoriginalTree :: WithQueryList
+              _lhsOcatExtComp :: (Either [TypeError] Catalog)
+              _hdOcatExtIncomp :: (Either [TypeError] Catalog)
+              _hdOflags :: TypeCheckFlags
+              _hdOimCast :: (Maybe TypeExtra)
+              _tlOcat :: Catalog
+              _tlOflags :: TypeCheckFlags
+              _tlOimCast :: (Maybe TypeExtra)
+              _hdIannotatedTree :: WithQuery
+              _hdIcolAliases :: (Maybe [NameComponent])
+              _hdIname :: Text
+              _hdIoriginalTree :: WithQuery
+              _hdIupType :: (Maybe [(Text,TypeExtra)])
+              _tlIannotatedTree :: WithQueryList
+              _tlIcatExtComp :: (Either [TypeError] Catalog)
+              _tlIoriginalTree :: WithQueryList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 34, column 9)
+              _tlOcatExtIncomp =
+                  ({-# LINE 34 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   do
+                   let getWithEx (WithQuery _ _ _ ex) = ex
+                   upType' <- maybe (Left . anErrs . ann . getWithEx $ _hdIannotatedTree) Right
+                     _hdIupType
+                   colTyPairs <- mapM (secondM typeToCatName) upType'
+                   colTyPairs' <- case _hdIcolAliases of
+                     Just alsNms -> do
+                       unless (length alsNms == length colTyPairs) $
+                         Left [BadCatalogUpdate "number of aliases differs from number of expressions in the select"]
+                       return $ zip (map ncStrT alsNms) $ map snd colTyPairs
+                     Nothing -> return colTyPairs
+                   updateCatalog [CatCreateTable ("public", _hdIname ) colTyPairs'] =<< _lhsIcatExtIncomp
+                   {-# LINE 29795 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 47, column 9)
+              _hdOcat =
+                  ({-# LINE 47 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   case _lhsIcatExtIncomp of
+                     Right catExtIncomp -> catExtIncomp
+                     Left _ -> _lhsIcat
+                   {-# LINE 29803 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIannotatedTree _tlIannotatedTree
+                   {-# LINE 29809 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   (:) _hdIoriginalTree _tlIoriginalTree
+                   {-# LINE 29815 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 29821 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 29827 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (up)
+              _lhsOcatExtComp =
+                  ({-# LINE 29 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _tlIcatExtComp
+                   {-# LINE 29833 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOcatExtIncomp =
+                  ({-# LINE 24 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIcatExtIncomp
+                   {-# LINE 29839 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 29845 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _hdOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 29851 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOcat =
+                  ({-# LINE 116 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIcat
+                   {-# LINE 29857 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOflags =
+                  ({-# LINE 117 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIflags
+                   {-# LINE 29863 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- copy rule (down)
+              _tlOimCast =
+                  ({-# LINE 129 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _lhsIimCast
+                   {-# LINE 29869 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              ( _hdIannotatedTree,_hdIcolAliases,_hdIname,_hdIoriginalTree,_hdIupType) =
+                  hd_ _hdOcat _hdOcatExtIncomp _hdOflags _hdOimCast
+              ( _tlIannotatedTree,_tlIcatExtComp,_tlIoriginalTree) =
+                  tl_ _tlOcat _tlOcatExtIncomp _tlOflags _tlOimCast
+          in  ( _lhsOannotatedTree,_lhsOcatExtComp,_lhsOoriginalTree)))
+_sem_WithQueryList_Nil :: T_WithQueryList
+_sem_WithQueryList_Nil =
+    (\ _lhsIcat
+       _lhsIcatExtIncomp
+       _lhsIflags
+       _lhsIimCast ->
+         (let _lhsOcatExtComp :: (Either [TypeError] Catalog)
+              _lhsOannotatedTree :: WithQueryList
+              _lhsOoriginalTree :: WithQueryList
+              -- "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag"(line 52, column 9)
+              _lhsOcatExtComp =
+                  ({-# LINE 52 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/QueryExprs/QueryExprs.ag" #-}
+                   _lhsIcatExtIncomp
+                   {-# LINE 29889 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _annotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 29895 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _originalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   []
+                   {-# LINE 29901 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOannotatedTree =
+                  ({-# LINE 118 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _annotatedTree
+                   {-# LINE 29907 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+              -- self rule
+              _lhsOoriginalTree =
+                  ({-# LINE 119 "hssqlppp/src/Database/HsSqlPpp/Internals/TypeChecking/TypeChecking.ag" #-}
+                   _originalTree
+                   {-# LINE 29913 "hssqlppp/src/Database/HsSqlPpp/Internals/AstInternal.hs" #-}
+                   )
+          in  ( _lhsOannotatedTree,_lhsOcatExtComp,_lhsOoriginalTree)))
diff --git a/src/Database/HsSqlPpp/Internals/Catalog/CatalogBuilder.lhs b/src/Database/HsSqlPpp/Internals/Catalog/CatalogBuilder.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/Catalog/CatalogBuilder.lhs
@@ -0,0 +1,151 @@
+
+> {-# LANGUAGE DeriveDataTypeable,OverloadedStrings #-}
+>
+> module Database.HsSqlPpp.Internals.Catalog.CatalogBuilder
+>     (updateCatalog
+>     ,deconstructCatalog
+>      -- todo: temporary export before the basecatalog is fixed not to use
+>      -- the catalog internals
+>     ,insertOperators
+>     ) where
+
+>
+> import Control.Monad
+> --import Data.List
+> --import Data.Data
+> --import Data.Char
+> --import Data.Maybe
+
+> import qualified Data.Map as M
+> import qualified Data.Set as S
+> import Database.HsSqlPpp.Internals.TypesInternal
+> --import Database.HsSqlPpp.Utils.Utils
+> --import Data.Text (Text)
+> import qualified Data.Text as T
+> --import qualified Data.Text.Lazy as LT
+
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+> --import Database.HsSqlPpp.Dialects.BaseCatalog
+> import Database.HsSqlPpp.Internals.Catalog.CatalogUtils
+
+> -- | Applies a list of 'CatalogUpdate's to an 'Catalog' value
+> -- to produce a new Catalog value. TODO: there will be a split
+> -- between the individual low level updates which just update
+> -- one 'row' in the catalog type, and the high level updates
+> -- which correspond to ddl (e.g. create type will also add the
+> -- array type, create table will add a table, supply the
+> -- private columns automatically, and add the composite type)
+> -- highlevel not implemented yet. You must use the correct case and
+> -- the canonical names for identifiers/types
+
+> updateCatalog :: [CatalogUpdate]
+>               -> Catalog
+>               -> Either [TypeError] Catalog
+> updateCatalog eus cat' =
+>   foldM updateCat' (cat' {catUpdates = catUpdates cat' ++ eus}) eus
+>   where
+>     updateCat' cat u = case u of
+>       CatCreateSchema n ->
+>         if S.member n (catSchemas cat)
+>         then Left [SchemaAlreadyExists n]
+>         else Right $ cat {catSchemas = S.insert n (catSchemas cat)}
+>       CatCreateScalarType n ->
+>         if S.member n (catScalarTypeNames cat)
+>         -- todo: need to check all the type lists
+>         -- and maybe need to check the name doesn't conflict with pseudo names or something?
+>         -- this should happen with other cases as well
+>         -- also: needs to take into account alias, so int and int4 are
+>         -- both disallowed for new types, and lookup of either finds int4
+>         then Left [InternalError $ "type already exists: " ++ show n]
+>         else Right $ cat {catScalarTypeNames = S.insert n (catScalarTypeNames cat)}
+>       CatCreateDomainType n b ->
+>         Right $ cat {catDomainTypes = M.insert n b (catDomainTypes cat)}
+>       CatCreateArrayType n b ->
+>         Right $ cat {catArrayTypes = M.insert n b (catArrayTypes cat)}
+>       -- todo: check the uniqueness of operator names (can overload by type)
+>       -- also check the name of the operator is a valid operator name
+>       -- and that the op has the correct number of args (1 or 2 resp.)
+>       CatCreatePrefixOp n lt ret -> do
+>         ltt <- catLookupType cat [QNmc $ T.unpack lt]
+>         rett <- catLookupType cat [QNmc $ T.unpack ret]
+>         Right $ cat {catPrefixOps = insertOperators
+>                                     [(n,(n,[ltt],rett,False))]
+>                                     (catPrefixOps cat)}
+>       CatCreatePostfixOp n rt ret -> do
+>         rtt <- catLookupType cat [QNmc $ T.unpack rt]
+>         rett <- catLookupType cat [QNmc $ T.unpack ret]
+>         Right $ cat {catPostfixOps = insertOperators
+>                                      [(n,(n,[rtt],rett,False))]
+>                                      (catPostfixOps cat)}
+>       CatCreateBinaryOp n lt rt ret -> do
+>         ltt <- catLookupType cat [QNmc $ T.unpack lt]
+>         rtt <- catLookupType cat [QNmc $ T.unpack rt]
+>         rett <- catLookupType cat [QNmc $ T.unpack ret]
+>         Right $ cat {catBinaryOps = insertOperators
+>                                     [(n,(n,[ltt,rtt],rett,False))]
+>                                     (catBinaryOps cat)}
+
+>       CatCreateSpecialOp n ps rs ret -> do
+>         pst <- mapM (\nc -> catLookupType cat [QNmc $ T.unpack nc]) ps
+>         rett <- catLookupType cat [QNmc $ T.unpack ret]
+>         let rett' = if rs
+>                     then Pseudo $ SetOfType rett
+>                     else rett
+>         -- thrown into the binary ops atm, todo: add a new namespace
+>         Right $ cat {catBinaryOps = insertOperators
+>                                     [(n,(n,pst,rett',False))]
+>                                     (catBinaryOps cat)}
+>       CatCreateFunction n ps rs ret -> do
+>         pst <- mapM (\nc -> catLookupType cat [QNmc $ T.unpack nc]) ps
+>         rett <- catLookupType cat [QNmc $ T.unpack ret]
+>         let rett' = if rs
+>                     then Pseudo $ SetOfType rett
+>                     else rett
+>         Right $ cat {catFunctions = insertOperators
+>                                     [(n,(n,pst,rett',False))]
+>                                     (catFunctions cat)}
+>       -- this wraps the last parameter in the array type for now
+>       CatCreateVariadicFunction n ps rs ret -> do
+>         let promoteLastType [] = []
+>             promoteLastType [a] = [ArrayType a]
+>             promoteLastType (a:as) = a : promoteLastType as
+>         pst <- promoteLastType `fmap` mapM (\nc -> catLookupType cat [QNmc $ T.unpack nc]) ps
+>         rett <- catLookupType cat [QNmc $ T.unpack ret]
+>         let rett' = if rs
+>                     then Pseudo $ SetOfType rett
+>                     else rett
+>         Right $ cat {catFunctions = insertOperators
+>                                     [(n,(n,pst,rett',True))]
+>                                     (catFunctions cat)}
+>       CatCreateAggregate n ps ret -> do
+>         pst <- mapM (\nc -> catLookupType cat [QNmc $ T.unpack nc]) ps
+>         rett <- catLookupType cat [QNmc $ T.unpack ret]
+>         Right $ cat {catAggregateFunctions = insertOperators
+>                                     [(n,(n,pst,rett,False))]
+>                                     (catAggregateFunctions cat)}
+>       CatCreateTable n cs -> do
+>         cts <- mapM (\(cn,te) -> do
+>                        t' <- catLookupType cat [QNmc $ T.unpack $ catName te]
+>                        -- for composite types, the information added here (about precision
+>                        --   and nullability) is redundant
+>                        let te' = TypeExtra t' (catPrecision te) (catScale te) (catNullable te)
+>                        return (cn,te')) cs
+>         Right $ cat {catTables = M.insert n (cts,[]) (catTables cat)}
+>       CatCreateCast n0 n1 ctx -> do
+>         t0 <- catLookupType cat [QNmc $ T.unpack n0]
+>         t1 <- catLookupType cat [QNmc $ T.unpack n1]
+>         Right $ cat {catCasts = S.insert (t0,t1,ctx) (catCasts cat)}
+>       CatCreateTypeCategoryEntry n (c,p) -> do
+>         t <- catLookupType cat [QNmc $ T.unpack n]
+>         Right $ cat {catTypeCategories = M.insert t (c,p) $ catTypeCategories cat}
+
+> deconstructCatalog :: Catalog -> [CatalogUpdate]
+> deconstructCatalog = catUpdates
+
+> insertOperators :: [(CatName,OperatorPrototype)]
+>                 -> M.Map CatName [OperatorPrototype]
+>                 -> M.Map CatName [OperatorPrototype]
+> insertOperators vs m =
+>   foldr i m vs
+>   where
+>     i (k,v) = M.insertWith (++) k [v]
diff --git a/src/Database/HsSqlPpp/Internals/Catalog/CatalogInternal.lhs b/src/Database/HsSqlPpp/Internals/Catalog/CatalogInternal.lhs
--- a/src/Database/HsSqlPpp/Internals/Catalog/CatalogInternal.lhs
+++ b/src/Database/HsSqlPpp/Internals/Catalog/CatalogInternal.lhs
@@ -3,529 +3,246 @@
 and functions, and provides the api for the other type checking
 modules.
 
-> {-# LANGUAGE DeriveDataTypeable #-}
+NEW CATALOG!
+
+create new types from scratch
+1st version only supports checking type names
+fix the read catalog code
+continue to ignore schemas
+start handling case sensitivity properly
+ignore modifiers
+
+= Catalog overview
+
+The main purpose of the catalog is to support typechecking. A
+secondary purpose is to be able to support documentation generation.
+
+== What information does the catalog contain?
+
+types:
+
+base types
+names of all types
+domains
+casts
+type categories (what is this?)
+
+tables, views, composite types
+
+operators:
+  prefix ops
+  postfix ops
+  binary ops
+  regular fns
+  aggregate fns
+  window fns
+
+
+triggers
+
+indexes
+
+sequences
+
+
+> {-# LANGUAGE DeriveDataTypeable,OverloadedStrings #-}
 >
 > module Database.HsSqlPpp.Internals.Catalog.CatalogInternal
->     (
->      Catalog
->     ,CastContext(..)
->     ,CompositeFlavour(..)
->     ,relationComposites
->     ,CompositeDef
->     ,FunctionPrototype
->     ,DomainDefinition
->     ,FunFlav(..)
->     ,emptyCatalog
->     ,defaultCatalog
->     ,CatalogUpdate(..)
->     ,ppCatUpdate
->     ,updateCatalog
->     ,deconstructCatalog
->     -- type checker stuff
->     ,catCompositeDef
->     ,catCompositeAttrsPair
->     ,catCompositeAttrs
->     ,catCompositePublicAttrs
->     ,catTypeCategory
+>     (catLookupType
+>     ,catLookupTableAndAttrs
+>     ,catGetOpsMatchingName
+>      -- temp stuff for old typeconversion
+>     ,catLookupFns
 >     ,catPreferredType
+>     ,isOperatorName
+>     ,catTypeCategory
 >     ,catCast
+>     ,catCompositePublicAttrs
 >     ,catDomainBaseType
->     ,catLookupFns
->     ,catTypeExists
->     ,catLookupType
->     ,OperatorType(..)
->     ,getOperatorType
->     ,isOperatorName
->     -- comparing catalogs
->     ,CatalogDiff(..)
->     ,compareCatalogs
->     ,ppCatDiff
+>     ,typeToCatName
 >     ) where
->
-> import Control.Monad
-> import Data.List
-> import Data.Data
-> -- import Debug.Trace
-> import Data.Char
->
-> import Database.HsSqlPpp.Internals.TypeType
-> import Database.HsSqlPpp.Utils.Utils
->
-> -- | The main datatype, this holds the catalog and context
-> -- information to type check against.
-> data Catalog = Catalog
->                    {catTypeNames :: [(String, Type)]
->                    ,catDomainDefs :: [DomainDefinition]
->                    ,catCasts :: [(Type,Type,CastContext)]
->                    ,catTypeCategories :: [(Type,String,Bool)]
->                    ,catPrefixOperators :: [FunctionPrototype]
->                    ,catPostfixOperators :: [FunctionPrototype]
->                    ,catBinaryOperators :: [FunctionPrototype]
->                    ,catFunctions :: [FunctionPrototype]
->                    ,catAggregates :: [FunctionPrototype]
->                    ,catWindowFunctions :: [FunctionPrototype]
->                    ,catAttrDefs :: [CompositeDef]
->                    ,catUpdates :: [CatalogUpdate]}
->                    deriving Show
->
-> -- | Represents an empty catalog. This doesn't contain things
-> -- like the \'and\' operator, 'defaultCatalog' contains these.
-> emptyCatalog :: Catalog
-> emptyCatalog = Catalog [] [] [] [] [] [] [] [] [] [] [] []
->
-> -- | Represents what you probably want to use as a starting point if
-> -- you are building an catalog from scratch. It contains
-> -- information on built in function like things that aren't in the
-> -- PostgreSQL catalog, such as greatest, coalesce, keyword operators
-> -- like \'and\', etc..
-> defaultCatalog :: Catalog
-> defaultCatalog =
->   emptyCatalog {catTypeNames = pseudoTypes
->                ,catBinaryOperators = pe : keywordOperatorTypes
->                ,catFunctions = specialFunctionTypes}
->   where
->     pe = ("=", [Pseudo AnyElement, Pseudo AnyElement], typeBool, False)
->
-> -- | Use to note what the flavour of a cast is, i.e. if/when it can
-> -- be used implicitly.
-> data CastContext = ImplicitCastContext
->                  | AssignmentCastContext
->                  | ExplicitCastContext
->                    deriving (Eq,Show,Ord,Typeable,Data)
->
-> -- | Used to distinguish between standalone composite types, and
-> -- automatically generated ones, generated from a table or view
-> -- respectively.
-> data CompositeFlavour = Composite | TableComposite | ViewComposite
->                         deriving (Eq,Ord,Show)
->
-> relationComposites :: [CompositeFlavour]
-> relationComposites = [TableComposite,ViewComposite]
->
-> -- | Provides the definition of a composite type. The components are
-> -- composite (or table or view) name, the flavour of the composite,
-> -- the types of the composite attributes, and the types of the
-> -- system columns iff the composite represents a table type (the
-> -- third and fourth components are always 'CompositeType's).
-> type CompositeDef = (String, CompositeFlavour, Type, Type)
->
-> -- | The components are: function (or operator) name, argument
-> -- types, return type and is variadic.
-> type FunctionPrototype = (String, [Type], Type, Bool)
->
-> -- | The components are domain type, base type (todo: add check
-> -- constraint).
-> type DomainDefinition = (Type,Type)
->
-> data CatalogUpdate =
->     -- | add a new scalar type with the name given, also creates
->     -- an array type automatically
->     CatCreateScalar Type String Bool
->     -- | add a new domain to the catalog
->   | CatCreateDomain Type Type
->     -- | add a new composite type to the catalog
->   | CatCreateComposite String [(String,Type)]
->     -- | add a new cast to the catalog
->   | CatCreateCast Type Type CastContext
->     -- | add a new table to the catalog with the given public and private columns
->     -- also creates the composite type to go with this table
->   | CatCreateTable String [(String,Type)] [(String,Type)]
->     -- | add the view to the catalog, using the column names and types supplied
->   | CatCreateView String [(String,Type)]
->     -- | add a new function to the catalog
->   | CatCreateFunction FunFlav String [Type] Type Bool
->     -- | drop a function from the catalog
->   | CatDropFunction Bool String [Type]
->     deriving (Eq,Ord,Typeable,Data,Show)
->
-> -- | attempt to show a readable representation of a 'CatalogUpdate' value
-> ppCatUpdate :: CatalogUpdate -> String
-> ppCatUpdate (CatCreateScalar t c p) =
->   "CatCreateScalar " ++ show t ++ "(" ++ c ++ "," ++ show p ++ ")"
-> ppCatUpdate (CatCreateDomain t b) =
->   "CatCreateDomain " ++ show t ++ " as " ++ show b
-> ppCatUpdate (CatCreateComposite nm flds) =
->   "CatCreateComposite " ++ nm ++ showFlds flds
-> ppCatUpdate (CatCreateCast s t ctx) =
->   "CatCreateCast " ++ show s ++ "->" ++ show t ++ " " ++ show ctx
-> ppCatUpdate (CatCreateTable nm flds1 flds2) =
->   "CatCreateTable " ++ nm ++ showFlds flds1 ++ showFlds flds2
-> ppCatUpdate (CatCreateView nm flds) =
->   "CatCreateView " ++ nm ++ showFlds flds
-> ppCatUpdate (CatCreateFunction flav nm args ret vdc) =
->   "CatCreateFunction " ++ show flav ++ " " ++ nm
->   ++ " returns " ++ show ret
->   ++ "(" ++ intercalate "," (map show args) ++ ")"
->   ++ if vdc then " variadic" else ""
-> ppCatUpdate (CatDropFunction _ nm args) =
->   "CatDropFunction " ++ nm ++ "(" ++ show args ++ ")"
->
-> showFlds :: [(String,Type)] -> String
-> showFlds flds = "(\n" ++ sfs flds ++ ")"
->                 where
->                   sfs ((nm,t):fs) = "    " ++ show nm
->                                     ++ " " ++ show t ++ "\n" ++ sfs fs
->                   sfs [] = ""
->
-> data FunFlav = FunPrefix | FunPostfix | FunBinary
->              | FunName | FunAgg | FunWindow
->                deriving (Eq,Show,Ord,Typeable,Data)
->
-> -- | Applies a list of 'CatalogUpdate's to an 'Catalog' value
-> -- to produce a new Catalog value.
-> updateCatalog :: Catalog
->                   -> [CatalogUpdate]
->                   -> Either [TypeError] Catalog
-> updateCatalog cat' eus =
->   foldM updateCat' (cat' {catUpdates = catUpdates cat' ++ eus}) eus
->   where
->     updateCat' cat (CatCreateScalar ty catl pref) = do
->       errorWhen (not allowed)
->         [BadCatalogUpdate $ "can only add scalar types\
->                             \this way, got " ++ show ty]
->       let ScalarType nm = ty
->       return $ addTypeWithArray cat nm ty catl pref
->       where
->         allowed = case ty of
->                           ScalarType _ -> True
->                           _ -> False
->
->     updateCat' cat (CatCreateDomain ty baseTy) = do
->       errorWhen (not allowed)
->         [BadCatalogUpdate $ "can only add domain types\
->                             \this way, got " ++ show ty]
->       errorWhen (not baseAllowed)
->         [BadCatalogUpdate $ "can only add domain types\
->                                 \based on scalars, got "
->                                 ++ show baseTy]
->       let DomainType nm = ty
->       catl <- catTypeCategory cat baseTy
->       return (addTypeWithArray cat nm ty catl False) {
->                              catDomainDefs =
->                                (ty,baseTy):catDomainDefs cat
->                              ,catCasts =
->                                (ty,baseTy,ImplicitCastContext):catCasts cat}
->       where
->         allowed = case ty of
->                           DomainType _ -> True
->                           _ -> False
->         baseAllowed = case baseTy of
->                                   ScalarType _ -> True
->                                   _ -> False
->     updateCat' cat (CatCreateComposite nm flds) =
->       return $ (addTypeWithArray cat nm (NamedCompositeType nm) "C" False) {
->                   catAttrDefs =
->                     (nm,Composite,CompositeType flds, CompositeType [])
->                     : catAttrDefs cat}
->
->     updateCat' cat (CatCreateCast src tgt ctx) =
->       return $ cat {catCasts = (src,tgt,ctx):catCasts cat}
->
->     updateCat' cat (CatCreateTable nm attrs sysAttrs) = do
->       checkTypeDoesntExist cat nm (NamedCompositeType nm)
->       return $ (addTypeWithArray cat nm
->                   (NamedCompositeType nm) "C" False) {
->                   catAttrDefs =
->                     (nm,TableComposite
->                     ,CompositeType attrs
->                     , CompositeType sysAttrs)
->                     : catAttrDefs cat}
->
->     updateCat' cat (CatCreateView nm attrs) = do
->       checkTypeDoesntExist cat nm (NamedCompositeType nm)
->       return $ (addTypeWithArray cat nm
->                   (NamedCompositeType nm) "C" False) {
->                   catAttrDefs =
->                     (nm,ViewComposite,CompositeType attrs, CompositeType [])
->                     : catAttrDefs cat}
->
->     updateCat' cat (CatCreateFunction f nm args ret vdc) =
->         return $ case f of
->           FunPrefix -> cat {catPrefixOperators =
->                               fp : catPrefixOperators cat}
->           FunPostfix -> cat {catPostfixOperators =
->                                fp : catPostfixOperators cat}
->           FunBinary -> cat {catBinaryOperators =
->                               fp : catBinaryOperators cat}
->           FunAgg -> cat {catAggregates =
->                            fp : catAggregates cat}
->           FunWindow -> cat {catWindowFunctions =
->                               fp : catWindowFunctions cat}
->           FunName -> cat {catFunctions =
->                             fp : catFunctions cat}
->         where fp = (nm,args,ret,vdc)
+
 >
->     updateCat' cat (CatDropFunction _ifexists nm args) = do
->         let matches =  filter matchingFn (catFunctions cat)
->         errorWhen (null matches)
->                   [BadCatalogUpdate
->                    $ "couldn't find function to drop "
->                      ++ show nm ++ "(" ++ show args++")"]
->         errorWhen (length matches > 1)
->                   [BadCatalogUpdate
->                    $ "multiple matching functions to drop "
->                      ++ show nm ++ "(" ++ show args++")"]
->         return cat {catFunctions = filter (not . matchingFn)
->                                           (catFunctions cat)
->                    ,catUpdates = filter (not.matchingUpdate)
->                                         (catUpdates cat)}
->         where
->           matchingFn (nm1,a1,_,_) =
->             map toLower nm == map toLower nm1 && args == a1
->           matchingUpdate (CatDropFunction _ nm2 a2)
->                          | map toLower nm2 == map toLower nm
->                            && a2 == args = True
->           matchingUpdate (CatCreateFunction _ nm2 a2 _ _)
->                          | map toLower nm2 == map toLower nm
->                            && a2 == args = True
->           matchingUpdate _ = False
+> --import Control.Monad
+> --import Data.List
+> --import Data.Data
+> --import Data.Char
+> import Data.Maybe
 
-todo:
-look for matching function in list, if not found then error
-remove from list, and remove from update list
+> import qualified Data.Map as M
+> import qualified Data.Set as S
+> import Database.HsSqlPpp.Internals.TypesInternal
+> --import Database.HsSqlPpp.Utils.Utils
+> import Data.Text (Text)
+> import qualified Data.Text as T
+> --import qualified Data.Text.Lazy as LT
 
->     addTypeWithArray cat nm ty catl pref =
->       cat {catTypeNames =
->                ('_':nm,ArrayType ty)
->                : (nm,ty)
->                : catTypeNames cat
->           ,catTypeCategories =
->                (ArrayType ty,"A",False)
->                : (ty,catl,pref)
->                : catTypeCategories cat}
->     checkTypeDoesntExist cat nm ty = do
->         errorWhen (any (==nm) $ map fst $ catTypeNames cat)
->             [TypeAlreadyExists ty]
->         errorWhen (any (==ty) $ map snd $ catTypeNames cat)
->             [TypeAlreadyExists ty]
->         return ()
-> {-
->  | Takes part an 'Catalog' value to produce a list of 'CatalogUpdate's.
->  You can use this to look inside the Catalog data type e.g. if you want to
->  examine a catalog. It should be the case that:
->  @
->   updateCatalog emptyCatalog (deconstructCatalog cat) = cat
->  @ -}
-> deconstructCatalog :: Catalog -> [CatalogUpdate]
-> deconstructCatalog = catUpdates
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+> --import Database.HsSqlPpp.Internals.Catalog.BaseCatalog
+> import Database.HsSqlPpp.Internals.Catalog.CatalogUtils
 
---------------------------------------------------------------------------------
+-----------------------------------
 
-= type checking stuff
+types:
 
-> catCompositeDef :: Catalog -> [CompositeFlavour] -> String
->                 -> Either [TypeError] CompositeDef
-> catCompositeDef cat flvs nm = do
->   let c = filter m $ catAttrDefs cat
->   errorWhen (null c)
->             [UnrecognisedRelation nm]
->   case c of
->     (_,fl1,r,s):[] -> return (nm,fl1,r,s)
->     _ -> Left [InternalError $ "problem getting attributes for: "
->                                ++ show nm ++ ", " ++ show c]
->   where
->     m (n,t,_,_) = n == nm && (null flvs || t `elem` flvs)
->
-> catCompositeAttrsPair :: Catalog -> [CompositeFlavour] -> String
->                       -> Either [TypeError] ([(String,Type)],[(String,Type)])
-> catCompositeAttrsPair cat flvs ty = do
->    (_,_,CompositeType a,CompositeType b) <- catCompositeDef cat flvs ty
->    return (a,b)
->
-> catCompositeAttrs :: Catalog -> [CompositeFlavour] -> String
->                   -> Either [TypeError] [(String,Type)]
-> catCompositeAttrs cat flvs ty = do
->   (a,b) <- catCompositeAttrsPair cat flvs ty
->   return $ a ++ b
->
-> catCompositePublicAttrs :: Catalog -> [CompositeFlavour] -> String
->                   -> Either [TypeError] [(String,Type)]
-> catCompositePublicAttrs cat flvs ty = do
->   (a,_) <- catCompositeAttrsPair cat flvs ty
->   return a
->
-> catTypeCategory :: Catalog -> Type -> Either [TypeError] String
-> catTypeCategory cat ty =
->   fmap fst $ catGetCategoryInfo cat ty
->
+What information does the catalog store and use on types?
+
+The basic set of types recorded here are:
+
+scalar types - the base types implemented outside of plpgsql
+
+domain types - this is a base type with a constraint (can composite
+types be used in a domain?)
+
+enum types - the usual. The values are strings and are case
+sensitive. I think you can overload the values so they can be members
+of more than one enum type
+
+named composite types - these are structs, created using 'create type
+x as', and also a composite type is implicitly created for each table
+and view definition with the same name as the table or view
+
+array types - not sure exactly how to handle this, generally, postgres
+automatically creates an array type for each scalar, domain, composite
+and enum type (any others?), and you can't use arrays of something if
+the type of the array isn't in the catalog. So lots of other types
+can't be made into arrays (what about arrays of arrays? don't
+know). Hssqlppp simply assumes that the array type of any type is
+available
+
+
+None of the types apart from these exist in the same way in postgres -
+so unnamed compositetypes, anonymous record type, unknown and pseudo
+type are used in less contexts. Maybe one way of looking at them is to
+consider them more like type generators which exist simply when they
+are used, and don't have to be declared up front. Only the above
+privileged types can be used for the types of columns in tables and
+views (I think?).
+
+for scalar types, no information is used apart from the fact that a
+type with the given name exists and can be referred to.
+
+for domain types, there is also the base type name, and the check
+constraint
+
+for enum types, name and the list of labels
+
+for named composite types, you need the name of the type, and the
+names and types of the fields
+
+for array types, you only need the base type name, array types don't
+have their own separate name
+
+todo: where should this utility live? Probably should be connected 
+to the dialects
+
+> typeToCatName :: TypeExtra -> Either [TypeError] CatNameExtra
+> typeToCatName te = case teType te of
+>   ScalarType t -> return
+>       $ CatNameExtra t (tePrecision te) (teScale te) (teNullable te)
+>   _ -> Left [InternalError "typeToCatName on a non scalar type"]
+
+-----------------------------------------------------------
+
+queries
+
+
+gets a schema qualified catname, puts in the default 'public' if there
+is only one name component. This will be altered when schema search
+paths are implemented.
+
+> getCatName2 :: [NameComponent] -> (CatName,CatName)
+> getCatName2 [] = error "empty name component in catalog code"
+> getCatName2 [a] = ("public",ncStrT a)
+> getCatName2 [a,b] = (ncStrT a, ncStrT b)
+> getCatName2 (_:xs) = getCatName2 xs
+
+
+TODO: add inverse of this operation, give a type, returns a typename
+
+
+> -- | takes a table name, and returns the exact table name (to deal
+> -- with quoting), and the public and private attr names
+> catLookupTableAndAttrs :: Catalog
+>                        -> [NameComponent]
+>                        -> Either [TypeError] ((Text,Text),[(Text,TypeExtra)], [(Text,Type)])
+> catLookupTableAndAttrs cat nmcs = do
+>   let n = getCatName2 nmcs
+>   (pu,pv) <- maybe (Left [UnrecognisedRelation n]) Right
+>              $ M.lookup n (catTables cat)
+>   return (n,pu,pv)
+
+
+
+> catGetOpsMatchingName :: Catalog -> [NameComponent] -> [OperatorPrototype]
+> catGetOpsMatchingName cat nmcs =
+>   let nm = getCatName nmcs
+>   in concatMap (\f -> fromMaybe [] $ M.lookup nm $ f cat)
+>        [catPrefixOps
+>        ,catPostfixOps
+>        ,catBinaryOps
+>        ,catFunctions
+>        ,catAggregateFunctions
+>        ,catWindowFunctions]
+
+the TypeConversion module handles checking assignment compatibility,
+'resolving result set types', and finding function call matches since
+this relies on some heavy algorithms to match postgress really complex
+overloading and implicit cast system.
+
+
+--------------------------------------------------------
+
+old stuff chucked in to support the old typeconversion, to be promoted
+to new code or deleted as typeconversion is rewritten
+
+
+
+> catCompositePublicAttrs :: Catalog -> [CompositeFlavour] -> Text
+>                   -> Either [TypeError] [(Text,TypeExtra)]
+> catCompositePublicAttrs cat _flvs ty = do
+>    (_,a,_) <- catLookupTableAndAttrs cat [Nmc $ T.unpack ty]
+>    return a
+
 > catPreferredType :: Catalog -> Type -> Either [TypeError] Bool
 > catPreferredType cat ty =
 >   fmap snd $ catGetCategoryInfo cat ty
 >
 > catCast :: Catalog -> CastContext -> Type -> Type -> Either [TypeError] Bool
-> catCast cat ctx from to = {-trace ("check cast " ++ show from ++ show to) $-}
+> catCast cat ctx from to =
 >     case from of
 >       t@(DomainType _) -> do
 >                 baseType <- catDomainBaseType cat t
 >                 cc <- catCast cat ctx baseType to
 >                 return $ (baseType == to) ||
->                                (cc ||
->                                   any (== (from, to, ctx)) (catCasts cat))
->       _ -> Right $ any (==(from,to,ctx)) (catCasts cat)
+>                                (cc || S.member (from, to, ctx) (catCasts cat))
+>       _ -> Right $ S.member (from, to, ctx) (catCasts cat)
 >
 > catDomainBaseType :: Catalog -> Type -> Either [TypeError] Type
-> catDomainBaseType cat ty =
->   --check type is domain, check it exists in main list
->   case lookup ty (catDomainDefs cat) of
->       Nothing -> Left [DomainDefNotFound ty]
->       Just t -> Right t
+> catDomainBaseType cat (ScalarType ty) =
+>   case M.lookup ty $ catDomainTypes cat of
+>     Just n -> Right $ ScalarType n
+>     Nothing -> Left [DomainDefNotFound $ ScalarType ty]
+> catDomainBaseType _cat ty = Left [DomainDefNotFound ty]
 >
-> catLookupFns :: Catalog -> String -> [FunctionPrototype]
+> catLookupFns :: Catalog -> Text -> [OperatorPrototype]
 > catLookupFns cat name =
->     filter (\(nm,_,_,_) -> map toLower nm == map toLower name) catGetAllFns
->     where
->     catGetAllFns =
->         concat [catPrefixOperators cat
->                ,catPostfixOperators cat
->                ,catBinaryOperators cat
->                ,catFunctions cat
->                ,catAggregates cat
->                ,catWindowFunctions cat]
+>    catGetOpsMatchingName cat [Nmc $ T.unpack name]
 
-== internal support for type checker fns above
+> catTypeCategory :: Catalog -> Type -> Either [TypeError] Text
+> catTypeCategory cat ty =
+>   fmap fst $ catGetCategoryInfo cat ty
 
-> catGetCategoryInfo :: Catalog -> Type -> Either [TypeError] (String, Bool)
+> isOperatorName :: Text -> Bool
+> isOperatorName = T.any (`elem` ("+-*/<>=~!@#%^&|`?."::String))
+
+> catGetCategoryInfo :: Catalog -> Type -> Either [TypeError] (Text, Bool)
 > catGetCategoryInfo cat ty =
 >   case ty of
->     SetOfType _ -> Right ("", False)
->     AnonymousRecordType _ -> Right ("", False)
+>     Pseudo (SetOfType _) -> Right ("", False)
+>     AnonymousCompositeType _ -> Right ("", False)
 >     ArrayType (Pseudo _) -> Right ("A",False)
 >     Pseudo _ -> Right ("P",False)
->     _ -> let l = filter (\(t,_,_) -> ty == t) $ catTypeCategories cat
->          in if null l
->               then Left [InternalError $ "no type category for " ++ show ty]
->               else let (_,c,p):_ =l
->                    in Right (c,p)
->
-> catTypeExists :: Catalog -> Type -> Either [TypeError] Type
-> catTypeExists cat t =
->     errorWhen (t `notElem` map snd (catTypeNames cat))
->               [UnknownTypeError t] >>
->     Right t
->
-> catLookupType :: Catalog -> String -> Either [TypeError] Type
-> catLookupType cat name =
->     liftME [UnknownTypeName name] $
->       lookup name (catTypeNames cat)
->
-
-================================================================================
-
-= built in stuff
-
-keyword operators, all of these are built in and don't appear in any
-postgresql catalog
-
-This is wrong, these need to be separated into prefix, postfix, binary
-
-> keywordOperatorTypes :: [FunctionPrototype]
-> keywordOperatorTypes = [
->   ("!and", [typeBool, typeBool], typeBool, False)
->  ,("!or", [typeBool, typeBool], typeBool, False)
->  ,("!like", [ScalarType "text", ScalarType "text"], typeBool, False)
->  ,("!like", [ScalarType "char", ScalarType "char"], typeBool, False)
->  ,("!like", [ScalarType "varchar", ScalarType "varchar"], typeBool, False)
->  ,("!notlike", [ScalarType "text", ScalarType "text"], typeBool, False)
->  ,("!notlike", [ScalarType "char", ScalarType "char"], typeBool, False)
->  ,("!notlike", [ScalarType "varchar", ScalarType "varchar"], typeBool, False)
->  ,("!not", [typeBool], typeBool, False)
->  ,("!isnull", [Pseudo AnyElement], typeBool, False)
->  ,("!isnotnull", [Pseudo AnyElement], typeBool, False)
->  ,("!arrayctor", [ArrayType $ Pseudo AnyElement], Pseudo AnyArray, True)
->  ,("!between", [Pseudo AnyElement
->                ,Pseudo AnyElement
->                ,Pseudo AnyElement], typeBool, False)
->  ,("!substring",[ScalarType "text",typeInt,typeInt],ScalarType "text",False)
->  ,("!substring",[ScalarType "varchar",typeInt,typeInt],ScalarType "varchar",False)
->  ,("!substring",[ScalarType "char",typeInt,typeInt],ScalarType "char",False)
->  ,("!arraysub", [Pseudo AnyArray,typeInt], Pseudo AnyElement, False)
->  ]
->
-> -- these look like functions, but don't appear in the postgresql catalog.
->
-> specialFunctionTypes :: [FunctionPrototype]
-> specialFunctionTypes = [
->   ("coalesce", [ArrayType $ Pseudo AnyElement], Pseudo AnyElement, True)
->  ,("nullif", [Pseudo AnyElement, Pseudo AnyElement], Pseudo AnyElement,False)
->  ,("greatest", [ArrayType $ Pseudo AnyElement], Pseudo AnyElement,True)
->  ,("least", [ArrayType $ Pseudo AnyElement], Pseudo AnyElement,True)
->  ]
->
-> pseudoTypes :: [(String, Type)]
-> pseudoTypes =
->     [("any",Pseudo Any)
->     ,("anyarray",Pseudo AnyArray)
->     ,("anyelement",Pseudo AnyElement)
->     ,("anyenum",Pseudo AnyEnum)
->     ,("anynonarray",Pseudo AnyNonArray)
->     ,("cstring",Pseudo Cstring)
->     ,("record",Pseudo Record)
->     ,("trigger",Pseudo Trigger)
->     ,("void",Pseudo Void)
->     ,("_cstring",ArrayType $ Pseudo Cstring)
->     ,("_record",ArrayType $ Pseudo Record)
->     --,Pseudo Internal
->     --,Pseudo LanguageHandler
->     --,Pseudo Opaque
->     ]
-
-================================================================================
-
-= getOperatorType
-
-used by the pretty printer, not sure this is a very good design
-
-for now, assume that all the overloaded operators that have the
-same name are all either binary, prefix or postfix, otherwise the
-getoperatortype would need the types of the arguments to determine
-the operator type, and the parser would have to be a lot cleverer
-although, parsec handles - being unary and binary without breaking
-a sweat, so maybe this isn't too difficult?
-
-this is why binary @ operator isn't currently supported
-
-> data OperatorType = BinaryOp | PrefixOp | PostfixOp
->                   deriving (Eq,Show)
->
-> getOperatorType :: Catalog -> String -> Either [TypeError] OperatorType
-> getOperatorType cat s =
->   case () of
->           _ | s `elem` ["!and", "!or","!like","!notlike","."] -> Right BinaryOp
->             | s `elem` ["!not"] -> Right PrefixOp
->             | s `elem` ["!isnull", "!isnotnull"] -> Right PostfixOp
->             | any (\(x,_,_,_) -> x == s) (catBinaryOperators cat) ->
->                       Right BinaryOp
->             | any (\(x,_,_,_) -> x == s || (x=="-" && s=="u-"))
->                   (catPrefixOperators cat) ->
->                       Right PrefixOp
->             | any (\(x,_,_,_) -> x == s) (catPostfixOperators cat) ->
->                       Right PostfixOp
->             | otherwise ->
->                 Left [InternalError $ "don't know flavour of operator " ++ s]
->
-> isOperatorName :: String -> Bool
-> isOperatorName = any (`elem` "+-*/<>=~!@#%^&|`?.")
-
-================================================================================
-
-> -- | items in first catalog and not second, items in second and not first.
-> data CatalogDiff = CatalogDiff [CatalogUpdate] [CatalogUpdate]
->                deriving Show
->
-> -- | find differences between two catalogs
-> compareCatalogs :: Catalog -> Catalog -> Catalog -> CatalogDiff
-> compareCatalogs base start end =
->         let baseCatBits = deconstructCatalog base
->             startCatBits = deconstructCatalog start \\ baseCatBits
->             endCatBits = deconstructCatalog end \\ baseCatBits
->             missing = sort $ endCatBits \\ startCatBits
->             extras = sort $ startCatBits \\ endCatBits
->         in CatalogDiff missing extras
->
-> -- | print a catdiff in a more human readable way than show.
-> ppCatDiff :: CatalogDiff -> String
-> ppCatDiff (CatalogDiff missing extr) =
->     "\nmissing:\n"
->     ++ intercalate "\n" (map ppCatUpdate missing)
->     ++ "\nextra:\n"
->     ++ intercalate "\n" (map ppCatUpdate extr)
+>     _ -> case M.lookup ty $ catTypeCategories cat of
+>            Nothing -> Left [InternalError $ "no type category for " ++ show ty]
+>            Just x -> Right x
diff --git a/src/Database/HsSqlPpp/Internals/Catalog/CatalogNew.lhs b/src/Database/HsSqlPpp/Internals/Catalog/CatalogNew.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/Catalog/CatalogNew.lhs
@@ -0,0 +1,978 @@
+
+This catalog code:
+
+1. is used by the typechecker internally to hssqlppp
+2. does most of the validation on ddl updates and provides nice
+error message when an update is not valid. It also tracks ownership,
+dependencies and models cascade and restrict on drop
+
+The CatalogUpdate's model alter and drop, as well as create. The
+CatalogUpdate's are supposed to represent updates after they have been
+desugared, so they don't correspond 1-1 with dml statements.
+
+The catalog information is only to model enough for these features,
+and e.g. doesn't have enough information for a complete catalog in a
+sql dbms, for instance it doesn't track the current value for a
+sequence.
+
+The catalog code api follows these principles:
+unquoted identifiers must be folded to the correct case for the dialect
+  select * from t -> use 't' in postgres, and 'T' in sql server
+  for instance
+names of built in types must use the canonical names in the current
+  dialect for those types
+  integer -> int4 in postgres, int in ansi
+escapes should already be applied for identifiers and strings
+e.g. select * from "my "" table"
+  this code should get: some_table_function "my \" table" (using
+  haskell escaping)
+names must always be schema qualified
+
+This code does no validation on the identifier syntax.
+
+There are separate helper functions to do the case transform,
+canonicalize type names and to find the correct schema for a name
+given the schema search path.
+
+= supported objects
+
+schemas
+scalar types/ externally implemented types/built in types
+domain types
+composite types
+enums
+type catagories (used in implicit cast/matching resolution)
+prefix,postfix,binary operators
+special syntax operations (e.g. between, extract, position)
+casts
+functions
+aggregates
+windows
+tables
+constraints (used for row, table, domain constraints and assertions)
+defaults (column defaults)
+  constraints and defaults are considered separate objects to tables
+  so that they can be dropped as part of a cascade without dropping
+  the table with a more straightforward implementation
+views
+sequences
+character sets
+collations
+roles (for ownership tracking only, permissions todo)
+
+= TODO
+
+understand routines, etc. in ansi
+  + variadic, keyword args, function metadata/annotation-like stuff
+  polymorphic functions
+and types
+and these in the main dialects
+understand aggregate and windows options
+summarize missing objects from sql server, oracle and db2
+do the example syntax for all supported operations
+detail all the dependency stuff
+understand some of the questions like this:
+  identifier, schema qualified identifier or string for e.g. character
+    set
+  do/can roles be in a schema
+  
+describe the helper apis (apply escapes, fold case, find schema, etc.)
+make a list of all the query apis wanted, do the typeid
+understand composite types, anonymous, tuples, arrays, multisets
+understand what schema various built in objects should be in in
+  different dialects
+make a detailed spec and start working on it
+write a catalog value consistency check function
+multiple updates? - can avoid hardcoding the public schema, etc. with
+  this
+
+= not currently supported objects
+
+== ansi
+
+routines/procedures (where they differ from functions, I think the
+  main thing missing is the function bodies and analysis based on
+  these)
+transliteration (conversion between character sets?)
+trigger
+  could use the dependency and some basic checking quite easily
+user defined ordering (is this to order composite types?)
+transform (conversion between sql representations and host language
+  representations of values)
+grant (this is on the todo)
+
+missing from postgres:
+  conversion
+  database
+  event trigger
+  extensions
+  foreign data wrapper
+  foreign table
+  index
+  language
+  materialized view
+  operator stuff (for indexes?)
+  policy (row level permissions)
+  rule
+  server
+  tablespace
+  text search stuff
+  transform
+  trigger
+  user mapping
+
+sql server full list:
+aggregate
+application role
+assembly
+asymmetric key
+availabiltiy group
+broker priority
+certificate
+column encryption key
+column master key definition
+columnstore index
+contract
+credential
+cryptographic provider
+database (azure sql database)
+database (sql server)
+database audit specification
+database encryption key
+default
+endpoint
+event notification
+event session
+external data source
+external file format
+external table
+federation
+fulltext catalog
+fulltext index
+fulltext stoplist
+function
+index
+login
+master key
+message type
+partition function
+partition scheme
+procedure
+queue
+remote service binding
+resource pool
+role
+route
+rule
+schema
+search property list
+security policy
+selective xml index
+sequence
+server audit
+server audit specification
+server role
+service
+spatial index
+statistics
+symmetric key
+synonym
+table
+table (azure sql database)
+trigger
+type
+user
+view
+workload group
+xml index
+xml schema collection
+
+db2 full list:
+alias
+audit policy
+bufferpool
+database partition group
+event monitor
+event monitor (activities)
+event monitor (change history)
+event monitor (locking)
+event monitor (package cache) statement
+event monitor (statistics)
+event monitor (threshold violations)
+event monitor (unit of work)
+event monitor dbactivities
+function
+function (external scalar)
+function (external table)
+function (ole db external table)
+function (sourced or template)
+function (sql scalar, table, or row)
+function mapping
+global temporary table
+histogram template
+index
+index extension
+mask
+method
+module
+nickname
+permission
+permission csr_row_access on customer
+permission teller_row_access on customer
+procedure
+procedure (external)
+procedure (sourced)
+procedure (sql)
+role
+schema
+security label
+security label component
+security policy
+sequence
+sequence org_seq
+server
+service class
+stogroup
+synonym
+table
+tablespace
+threshold
+transform
+trigger
+trusted context
+type
+type (array)
+type (cursor)
+type (distinct)
+type (row)
+type (structurxxxxxxxxxxxxxxxxxxxxxxed)
+type mapping
+usage list
+user mapping
+variable
+view
+work action set
+work class set
+workload
+wrapper
+
+oracle full list:
+audit policy (unified auditing)
+cluster
+context
+controlfile
+database
+database link
+dimension
+directory
+diskgroup
+edition
+flashback archive
+function
+index
+indextype
+java
+library
+materialized view
+materialized view log
+materialized zonemap
+operator
+outline
+package
+package body
+pfile
+pluggable database
+procedure
+profile
+restore point
+role
+rollback segment
+schema
+sequence
+spfile
+synonym
+table
+tablespace
+trigger
+type
+type body
+user
+view
+
+
+what would be nice to add:
+triggers are pretty common
+indexes are pretty common
+synonyms: do a review of these in different dbmss
+  what can we support synonyms for:
+    not special syntax ops?
+    not casts
+    what about operator synonyms for functions and vice versa?
+    defaults, constraints: doesn't make sense (even though constraints
+      do have a name)
+    everything else seems like fair game, including synonyms themselves
+partition stuff??
+global temporary tables?
+distinct type: this is like a domain, but cannot be implicitly cast to
+  the base type. Does this catalog need to know the difference between
+  this and an external type?
+
+= implementation progress notes
+
+
+New catalog lower level goals:
+
+updates to the catalog are high level not low level
+error checking
+supports schemas and search paths properly
+object dependencies with cascade and restrict
+this catalog will be clear if an object is based on another object in
+  the catalog (possibly with a bit of tweaking)
+  (for instance, an alias to a type)
+  or if the object is 'externally implemented' and its relationship
+    with any possible base type is opaque
+
+How should the catalog support syntax? This is needed in:
+domain constraints
+table constraints
+view definitions
+also: function/routine bodies
+
+option 1: save them as strings
+option 2: parameterize on the scalarexpr and queryexpr?
+option 3: hardcode the scalarexp and queryexpr types
+
+the possible benefits to parameterized versions are:
+1. don't have to reparse
+2. this module doesn't depend on the syntax module
+3. this module cannot do anything with the syntax internals
+
+later: add fuzzy matching to all relevant error messages
+
+TODO docs:
+how to use this catalog code:
+if you have no schemas
+if you don't have roles or permissions
+if you don't want to use the bootstrap items (public schema, ascii
+  charset, binary collation)
+
+> {-# LANGUAGE DeriveDataTypeable #-}
+> module Database.HsSqlPpp.Internals.Catalog.CatalogNew
+>    (CatalogUpdate(..)
+>    ,Catalog(..)
+>    ,Cascade(..)
+>    ,CatError(..)
+>    ,updateCatalog
+>    ,emptyCatalog
+>    ) where
+
+> import qualified Data.Map as M
+> import qualified Data.Set as S
+> import Data.Data
+
+
+> --data TypeId = ...
+
+a TypeId is one of:
+astraction of the syntax for type names (probably just cut and paste
+  the syntax)
+one of these type names with nullablility information
+a special type (some are internal):
+  polymorphic function parameters
+  unknown type used to type check literals (and a few other things) in
+    some dialects
+  void, used to represent the return type of functions which don't
+    return a value
+  setof, used to represent the return type of table returning functions
+    ... not sure about this
+  tref type used in typechecking joins and a few other places (kind of
+    an anonymous composite type)
+
+composite types:
+  with names and order
+  without names
+  either single row or 0 or 1 rows, or 0-many rows
+what about tuple types?
+what about arrays and multisets?
+
+question: should the catalog manage the following:
+  if a scale/precision and what kind is allowable/mandatory for a
+    type?
+  if a type can be used in various operations
+    (e.g. does == exist for it, ordering?, can it be used in an array
+    or multiset?)
+
+> -- | Represents an error from an invalid catalog update or query
+> data CatError = RoleAlreadyExists String
+>               | RoleNotRecognised String
+>                 deriving (Eq,Show)
+
+
+> -- | A schema qualified name. These should also have the
+> -- canonicalization, case folding and escaping fixed
+> data SchemadName = SN String String
+>                    deriving (Eq,Show)
+
+> -- | The model of a catalog use in hsqlppp for validating ddl
+> -- updates and for typechecking sql.
+> data Catalog = Catalog
+>     {cRoles :: S.Set String
+>     ,cSchemas :: M.Map String CatSchema
+>     ,cCharacterSets :: M.Map SchemadName CatCharacterSet
+>     ,cCollations :: M.Map SchemadName CatCollation
+>     ,cSequences :: M.Map SchemadName CatSequence
+>     ,cTypeCategories :: S.Set String -- this is internal, used in the
+>     -- implicit cast/function resolution
+>     ,cExternalTypes :: S.Set SchemadName -- externally implemented/built in types
+>     ,cCasts :: S.Set (SchemadName,SchemadName,CastContext)
+>     ,cFunctions :: M.Map SchemadName [CatFunSig]
+>     ,cPrefixOps :: M.Map SchemadName [CatFunSig]
+>     ,cPostfixOps :: M.Map SchemadName [CatFunSig]
+>     ,cBinaryOps :: M.Map SchemadName [CatFunSig]
+>     ,cSpecialOps :: M.Map SchemadName [CatFunSig]
+>     ,cWindows :: Int
+>     ,cAggregates :: Int
+>     ,cTables :: M.Map SchemadName [(String,SchemadName)]
+>     ,cConstraints :: Int
+>     ,cDefaults :: Int
+>     ,cViews :: M.Map SchemadName [(String,SchemadName)]
+>     ,cDomainTypes :: M.Map SchemadName SchemadName
+>     ,cCompositeTypes :: M.Map SchemadName [(String,SchemadName)]
+>     ,cEnums :: Int
+>     -- dependencies?
+>     }
+>     deriving (Eq,Show)
+
+> data CastContext = ImplicitCastContext
+>                  | AssignmentCastContext
+>                  | ExplicitCastContext
+>                    deriving (Eq,Show,Ord,Typeable,Data)
+
+> -- | owner, default char set, default collation (if it
+> -- is nothing, it is the global collation for the charset
+> type CatSchema = (RoleName, String, Maybe String)
+
+> -- | Character set: name, owner, default collation
+> type CatCharacterSet = (RoleName, String)
+
+> -- | Collation: owner, character set
+> type CatCollation = (RoleName,String)
+
+> -- | sequence info: data type
+> -- this is used e.g. if we need to use an implicit
+> -- cast around a call to 'next value for'.
+> type CatSequence = SchemadName
+
+> type CatFunSig = (SchemadName,[SchemadName],SchemadName{-,Options-})
+> --type FunOptions = 
+
+> -- | A catalog value containing nothing
+> emptyCatalog :: Catalog
+> emptyCatalog = Catalog {cRoles = S.empty
+>                        ,cSchemas = M.empty
+>                        ,cCharacterSets = M.empty
+>                        ,cCollations = M.empty
+>                        ,cSequences = M.empty
+>                        ,cTypeCategories = S.empty
+>                        ,cExternalTypes = S.empty
+>                        ,cCasts = S.empty
+>                        ,cFunctions = M.empty
+>                        ,cPrefixOps = M.empty
+>                        ,cPostfixOps = M.empty
+>                        ,cBinaryOps = M.empty
+>                        ,cSpecialOps = M.empty
+>                        ,cWindows = 0
+>                        ,cAggregates = 0
+>                        ,cTables = M.empty
+>                        ,cConstraints = 0
+>                        ,cDefaults = 0
+>                        ,cViews = M.empty
+>                        ,cDomainTypes = M.empty
+>                        ,cCompositeTypes = M.empty
+>                        ,cEnums = 0
+>                        }
+
+> updateCatalog :: CatalogUpdate -> Catalog -> Either CatError Catalog
+> updateCatalog (CreateRole r) c@(Catalog {cRoles = rs})
+>     | r `S.member` rs = Left $ RoleAlreadyExists r
+>     | otherwise = Right $ c {cRoles = S.insert r rs}
+
+> updateCatalog (DropRole r _) c@(Catalog {cRoles = rs})
+>     | not (r `S.member` rs) = Left $ RoleNotRecognised r
+>     | otherwise = Right $ c {cRoles = S.delete r rs}
+
+todo: cascade the rename
+
+> updateCatalog (RenameRole r rn) c@(Catalog {cRoles = rs})
+>     | not (r `S.member` rs) = Left $ RoleNotRecognised r
+>     | rn `S.member` rs = Left $ RoleAlreadyExists rn
+>     | otherwise = Right $ c {cRoles = S.insert rn $ S.delete r rs}
+
+> updateCatalog _ _ = error "update catalog not completed yet"
+
+
+> type RoleName = String
+
+
+used for dependencies:
+
+> --data ObjectType = ...
+
+now the dependencies can be tracked in one table
+
+> data CatalogUpdate =
+
+create schema _name_ [authorization _role_]
+  [DEFAULT CHARACTER SET 'character set' [collate c]]
+
+character sets are strings and not identifiers atm
+roles are identifiers but don't exist in a schema or database (since
+this catalog only covers a single database at a time, they look like
+they exist in a database)
+
+not going to support path for schema right now (I think this is
+supposed to be for the bodies of routines in that schema, maybe it
+could also be for all lookups for schema elements (such as views)
+
+question: should there be a database default search path? one that can
+contain variables (e.g. a schema with the same name as the current
+user?) This would be the default for sessions. You cannot enter a
+schema, so the schema default search path works differently.
+
+question: I think in some dialects, character set names are
+identifiers or schema-d identifiers (and collations also), and in
+others they are strings. How should this be handled?
+
+todo: add object dependencies to the updates (from dependent to
+depended-upon in the dependent). Try to make these automatic as much
+as possible.
+
+list schemas
+create schema: schema already exists
+  character set invalid
+  collation not valid
+  auth not valid
+later: more schema-based queries
+
+question: how does a minimal catalog start out?
+1. has a schema called public
+2. has a global default character set called ascii
+3. has a collation called binary for that character set
+4. has a role called public which owns the above
+
+In the tests, show an example of creating a catalog from this default
+   without the public schema or role still existing
+   and without the character set and collation
+
+>       CreateSchema String (Maybe (SchemadName,SchemadName)) RoleName
+
+schema name, (default char set, default collation for that character set in
+that schema), owner
+
+>     | RenameSchema String String
+>     | SetSchemaOwner String RoleName
+>     | SetSchemaDefaultCharacterSet (Maybe (SchemadName,SchemadName))
+
+what happens when you change this default: existing columns are not
+changed (there could be some utility to change them all for
+consistency. This would mean storing a uses default flag on each
+relevent place also).
+
+>     | DropSchema String Cascade
+
+= Roles
+
+roles are used for ownership tracking only at the moment
+
+create role my_role;
+drop role my_role;
+alter role my_role rename to my_new_role;
+
+dependencies: todo
+
+anomalies: role already exist
+           role doesn't exist
+
+queries: list roles
+
+>     | CreateRole RoleName
+>     | DropRole RoleName Cascade
+>     | RenameRole RoleName RoleName -- from, to
+
+= Collations and character sets
+
+This code doesn't track character set and collation aliases
+
+collations appear in separate namespaces according to their character
+set, so you can have different collations for different character sets
+with the same name
+
+this catalog code will create a collation called 'binary' for each new
+character set. If you don't want this collation, you can delete it
+after creating another collation for the new character set, or rename
+the collation. This is one way to avoid the catch-22 which can also
+work for sql users.
+
+create character set my_character_set
+create character set my_character_set as get another_character_set
+create character set my_character_set as 'some external source'
+create character set my_character_set as 'some external source' collate 'some other external source'
+create collation my_collation for my_character_set from some external source [set as default?]
+alter character set set default collation 'collation_name'
+
+drop character set
+drop collation
+
+alter character set my_set set schema my_schema
+alter collation my_coll set schema my_schema
+rename for both
+set owner for both
+
+question: does a character set have to have a collation?
+
+dependencies: todo
+
+queries:
+list character sets (returns owner also)
+list collations (returns the owner and character sets also)
+lookup collation/ is collation valid for character set
+get character set default collation
+
+anomalies:
+role no exist
+already exist
+doesn't exist
+maybe nice message when schema is ambiguous, when collation is in another schema?
+      as well as fuzzy name matching
+
+>     | CreateCharacterSet SchemadName RoleName
+>     | CreateCollation SchemadName SchemadName RoleName --second is the character set this collation is for
+>
+>     | DropCollation SchemadName SchemadName Cascade -- the first is the character set this collation is for
+>                                                     -- the front end can make this optional in the concrete
+>                                                     -- syntax iff
+>                                                     -- there is only
+>                                                     -- one collation
+>                                                     -- with this
+>                                                     -- name for
+>                                                     -- instance
+>     | DropCharacterSet SchemadName Cascade
+>     | RenameCharacterSet SchemadName SchemadName -- covers schema changes and name changes
+>     | RenameCollation SchemadName SchemadName SchemadName -- char set name, collation name, new collation name
+>     | SetCharacterSetOwner SchemadName RoleName
+>     | SetCollationOwner SchemadName SchemadName RoleName -- char set name, collation name
+>     | SetCharacterSetDefaultCollation SchemadName SchemadName
+
+= basic types
+
+TODO: understand basic syntax and semantics of types in ansi sql
+
+-- external type represents a type whose implementation is outside the
+-- system completely, either it is built in or implemented in C for
+-- instance
+
+-- external types can also be modelled using the other types such as
+-- domain, compose, enum if this matches their behaviour
+
+>     {-  | CreateExternalType SchemadName
+
+>     | CreateDomainType SchemadName SchemadName -- name, base name
+
+>     | CreateCompositeType
+
+>     | CreateEnum
+
++ a type category for each of the above
++ a bool to say whether it is the preferred type for that category
+todo: how can these be changed? is there a reason to change them
+what about the ability to wipe the prefered type for a category only,
+then other operations can be sugar on this
+what about altering a type to set it as prefered or not preferred or
+to change its type category
+
+>     | CreateTypeCategory
+>     | AlterTypeCategory?
+>     | DropTypeCategory
+
+
+
+>     | DropType
+>     | AlterType - rename
+>     | AlterCompositeType - add, reorder or remove columns
+>     | AlterEnum - add, reorder or remove enum values
+
+= scalar operations
+
+by convention, it supports keyword operations as prefix,postfix or
+binary if they match these, and if the operator is more than one
+keyword separated by space then the name in the catalog is the
+keywords separated by exactly one space each in lower case. Operators
+which don't fit this set of options (such as mixfix or ternary
+operators go in the SpecialOperators and are handled as special cases)
+
+prefix, postfix, binary operators
+
+>     | CreatePrefixOp String String String String -- op schema, op name,
+>         --  input type schema, input type name, output type schema,name
+
+>     | CreatePostfixOp String String String String -- op schema, op name,
+>         --  input type schema, input type name, output type schema,name
+
+>     | CreateBinaryOp
+>     | DropPrefixOp, PostfixOp, BinaryOp
+
+>     | CreateSpecialOp -- should the list of names be a enum?
+>                       -- if it is freeform, then the catalog doesn't need to know as much
+>                       --  about the syntax, which is a good thing
+
+>     | CreateCast
+>     | DropCast
+>     | AlterCast? - doesn't seem like there is a real point
+
+>     | CreateFunction
+>     | AlterFunction - rename, change some metadata?
+
+>     -}
+>     deriving (Eq,Show)
+
+aggregates
+windows
+tables
+views
+sequences
+character sets
+collations
+roles
+
+
+> data Cascade = Cascade | Restrict
+>                deriving (Eq,Show)
+
+
+this e.g. is the return value when you want to get all the information
+on a type. some of this information is contained in the typeid syntax,
+and some is stored in the catalog or environment
+
+> --data TypeInfo = ...
+
+is scalar
+precision, scale, nullability
+char set, collation
+isdomain, domain base, domain constraint
+is composite, fields in the composite
+
+
+
+= dependencies, cascade, restrict
+
+roles
+schema
+character set
+collation
+sequence
+type category
+external types
+cast
+functions, operators, windows, aggregates
+tables
+  constraints
+  defaults
+views
+domain types
+composite types
+enums
+
+question: what about ownership of dependencies, and does changing
+owner ever cascade? (Maybe these are separate helper fns?)
+
+rough set of cascade flavours:
+1. remove connection, leave depender existing
+2. update connection to point to new value (for alter)
+3. drop the depender object (recursively to its dependents)
+
+for alter, can use 1 or 2
+for drop can use 2 or 3
+policy it: make each version options on the updates, then a dialect or
+some other code can decide which behavior to use
+
+in order to track dependencies:
+
+create separate concept of constraints so we can handle table and
+domain constraints the same (plus assertions?)
+
+maybe have a concept of a sql body or something to model constraints,
+as well as view definitions and function bodies referencing things via
+sql statements syntax + column defaults
+
+things to add to this catalog:
+constraints
+defaults
+character set conversions? - if we want to type check string
+  operations a bit better
+
+== schemas
+
+alter and drop schema can restrict or cascade to schema objects:
+all other catalog supported objects appear in a schema apart from
+  roles
+rename schema just cascades automatically, there is no restrict option
+  there can be a generic has dependencies or list dependencies
+  function to implement a restrict like this
+set default character set will affect the character set of new:
+    table columns, domains, views (in some obscure cases), composite
+    types
+    no existing objects will be changed to match the new characterset/collation
+      they must be altered separately
+set schema owner will not cascade to objects in the schema, or will??
+  not sure, maybe just objects which are owned by a role with the same
+  name as the schema? add this as an option?
+drop schema will not work if any objects owned by the schema on restrict
+  it will drop them also if on cascade
+
+== role
+
+rename role cascades automatically, no options
+drop role will restrict if there are any objects owned
+cascade drop role will drop all owned items
+there can be a util to show all owned items
+and to reown them to another role easily
+
+later will have role membership in other roles to do shared ownership
+and group permissions, this will work slightly differently for drop:
+
+a dropped role will simply be removed from any roles it is in without
+affecting them: only option
+
+a dropped role will other roles in it: those roles will just be
+removed from this role. Restrict can be used to not allow dropping the
+role
+
+permissions for a being dropped role will always be dropped also
+
+== character set
+
+dependencies:
+table column
+domain
+schema - default char set
+database - default char set
+collations - belong to a single character set
+types: each character type can have a whitelist or blacklist of
+  allowed character sets
+views will depend only indirectly
+composite types
+
+rename:
+always cascades
+
+alter default collation:
+doesn't affect the collation on any existing dependencies
+
+drop restrict:
+if character set is used anywhere above, restrict will stop the drop
+  (apart from types blacklist or whitelist, this char set will be
+  removed from these lists and the drop will succeed (if it has no
+  other dependencies)
+drop cascade:
+will delete:
+tables(!)
+domains
+schema will always block??
+database will definitely always block: you must set another default
+  char set to drop the current default one
+collations
+types: same as restrict, types are not dropped
+composite types are dropped (could be very destructive!)
+
+== collation
+
+dependencies:
+character set default collation
+table and domain collation on char type, composite type also
+collation on default char set for database and schemas
+
+drop restrict:
+any use of collation will stop the drop
+
+drop cascade:
+will drop the character set (!)
+will drop tables, domains, and composites (!)
+will drop schema (!) - maybe these behaviours should be same as character sets?
+cannot drop database, so must restrict this
+
+== sequence
+
+dependencies:
+tables
+functions
+views
+domains? - could reference the sequence in the constraint?
+
+drop restrict:
+if the sequence is reference in any of the above, the drop is stopped
+
+drop cascade:
+views, functions dropped
+option table can be dropped (!) or the defaults/constraints dropped
+same with domain
+
+== type category
+
+dependencies:
+types
+
+a type can have the default category which means no category
+
+drop restrict:
+if used in any types, cannot drop
+
+drop cascade:
+option 1: types categories changed to default
+option 2: types are dropped
+
+== external types
+
+dependencies:
+domains
+functions
+tables
+views
+composite types
+
+restrict: if used anywhere, drop prevented
+cascade: all dependents dropped
+
+== cast
+
+dependencies:
+can be used in constraints or views
+
+restrict: drop stopped
+cascade, drops constraint and views also
+
+== functions, operators, windows, aggregates
+
+each function can have a set of dependencies supplied by the calling
+code this represents e.g. the tables, functions, etc. referenced in
+the body of the function. This is to help with cascade/restrict
+behaviour.
+
+what can a function depend on? what can't a function directly depend
+on:
+itself
+type category
+
+that's it. Potentially anything else. Unusual (direct) dependencies
+would be: schema, roles, constraints, defaults.
+
+
+== tables
+
+== constraints
+
+== defaults
+== views
+== domain types
+== composite types
+== enums
+
diff --git a/src/Database/HsSqlPpp/Internals/Catalog/CatalogTypes.lhs b/src/Database/HsSqlPpp/Internals/Catalog/CatalogTypes.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/Catalog/CatalogTypes.lhs
@@ -0,0 +1,192 @@
+
+> {-# LANGUAGE DeriveDataTypeable,OverloadedStrings #-}
+>
+> module Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+>     (
+>      -- catalog type plus values
+>      Catalog(..)
+>     ,emptyCatalog
+>     ,NameComponent(..)
+>     ,ncStr
+>     ,ncStrT
+>     ,CompositeFlavour(..)
+>     ,CatName
+>     ,CatNameExtra(..)
+>     ,mkCatNameExtra
+>     ,mkCatNameExtraNN
+>      -- catalog updates
+>     ,CatalogUpdate(..)
+>      -- temp stuff for old typeconversion
+>     ,OperatorPrototype
+
+>     ,CastContext(..)
+>     ) where
+
+> --import Control.Monad
+> --import Data.List
+> import Data.Data
+> import Data.Char
+> --import Data.Maybe
+
+> import qualified Data.Map as M
+> import qualified Data.Set as S
+> import Database.HsSqlPpp.Internals.TypesInternal
+> --import Database.HsSqlPpp.Utils.Utils
+> import Data.Text (Text)
+> import qualified Data.Text as T
+> --import qualified Data.Text.Lazy as LT
+
+> -- | represents the name of something in the catalog, when schema
+> -- support is added then this will change to (String,String)
+> type CatName = Text
+> -- | type name and precision and nullability
+> data CatNameExtra = CatNameExtra {
+>   catName:: CatName,
+>   catPrecision:: Maybe Int,
+>   catScale:: Maybe Int,
+>   catNullable:: Bool
+> } deriving (Eq,Ord,Show,Typeable,Data)
+> mkCatNameExtra:: CatName -> CatNameExtra
+> mkCatNameExtra cn = CatNameExtra cn Nothing Nothing True
+> mkCatNameExtraNN:: CatName -> CatNameExtra
+> mkCatNameExtraNN cn = CatNameExtra cn Nothing Nothing False
+
+> data CompositeFlavour = Composite | TableComposite | ViewComposite
+>                         deriving (Eq,Show,Ord,Data,Typeable)
+
+
+---------------------------------------------------------------
+
+operators
+
+operators is used as the generic term for all sorts of function things:
+prefix, postfix, binary operators, functions, aggregate functions and
+window functions
+
+The information currently stored is:
+name, parameter types, return type and variadic flag
+
+> -- | name, inparams, outtype, is variadic?
+> type OperatorPrototype = (CatName, [Type], Type, Bool)
+
+> -- | The main datatype, this holds the catalog and context
+> -- information to type check against.
+> data Catalog = Catalog
+>     {catSchemas :: S.Set CatName
+>     ,catScalarTypeNames :: S.Set CatName -- one name component per type
+>     ,catDomainTypes :: M.Map CatName CatName -- stores the base type name
+>                                              -- constraint is stored separately
+>      --,catEnumTypes :: {[(String,[String])]}
+>     ,catCompositeTypes :: M.Map CatName
+>                                 (CompositeFlavour
+>                                 ,[(Text,CatNameExtra)] -- public attrs
+>                                 ,[(Text,CatName)])-- system columns
+>     ,catArrayTypes :: M.Map CatName CatName --pg array type name, base type name
+>     ,catPrefixOps :: M.Map CatName [OperatorPrototype]
+>     ,catPostfixOps :: M.Map CatName [OperatorPrototype]
+>     ,catBinaryOps :: M.Map CatName [OperatorPrototype]
+>     ,catFunctions :: M.Map CatName [OperatorPrototype]
+>     ,catAggregateFunctions :: M.Map CatName [OperatorPrototype]
+>     ,catWindowFunctions :: M.Map CatName [OperatorPrototype]
+>     ,catTables :: M.Map (CatName,CatName)
+>                   ([(Text,TypeExtra)] -- public attrs
+>                   ,[(Text,Type)]) -- system columns
+>     -- needs more work:
+>     ,catCasts :: S.Set (Type,Type,CastContext)
+>     ,catTypeCategories :: M.Map Type (Text,Bool)
+>      -- save the updates
+>     ,catUpdates :: [CatalogUpdate]
+>     }
+>                deriving (Eq,Show,Data,Typeable)
+
+
+> -- | Use to note what the flavour of a cast is, i.e. if/when it can
+> -- be used implicitly.
+> data CastContext = ImplicitCastContext
+>                  | AssignmentCastContext
+>                  | ExplicitCastContext
+>                    deriving (Eq,Show,Ord,Typeable,Data)
+
+
+> -- | Represents an empty catalog.
+> emptyCatalog :: Catalog
+> emptyCatalog = Catalog S.empty S.empty M.empty M.empty M.empty
+>                        M.empty M.empty
+>                        M.empty M.empty M.empty M.empty M.empty
+>                        S.empty M.empty
+>                        []
+
+
+--------------------------------------------------
+
+
+name component - this represents quoted and unquoted
+possibly-qualified names (so names of things are lists of
+namecomponents). Perhaps should be a syntactic namecomponent which is
+in AstInternal, and a semantic namecomponent which is used here, but I
+am lazy so the same type is shared.
+
+The name components are only used here so that the logic for ignoring
+or respecting case is in one place, these are only used in the query
+functions and not in catalog values themselves.
+
+> data NameComponent = Nmc String
+>                    | QNmc String -- quoted
+>                    | AntiNameComponent String
+>                      deriving (Data,Eq,Show,Typeable,Ord)
+> -- this is a transition function
+> -- it should be removed when ready, since all the code
+> -- should be working with NameComponents directly
+> ncStr :: NameComponent -> String
+> ncStr (Nmc n) = map toLower n
+> ncStr (QNmc n) = n
+> ncStr (AntiNameComponent _n) =
+>   error "tried to get the name component string of an anti name component"
+
+> ncStrT :: NameComponent -> Text
+> ncStrT (Nmc n) = T.pack $ map toLower n
+> ncStrT (QNmc n) = T.pack n
+> ncStrT (AntiNameComponent _n) =
+>   error "tried to get the name component string of an anti name component"
+
+
+todo: use left or something instead of error
+
+------------------------------------------------------
+
+ updates
+
+> data CatalogUpdate =
+>     -- | register a schema with the given name
+>     CatCreateSchema CatName
+>     -- | register a base scalar type with the given name
+>   | CatCreateScalarType CatName
+>     -- | register a domain type with name and base type
+>   | CatCreateDomainType CatName CatName
+>     -- | register an array type with name and base type
+>   | CatCreateArrayType CatName CatName
+>     -- | register a prefix op, opname, param type, return type
+>   | CatCreatePrefixOp CatName CatName CatName
+>     -- | register a postfix op, opname, param type, return type
+>   | CatCreatePostfixOp CatName CatName CatName
+>     -- | register a binary op, opname, the two param types, return type
+>   | CatCreateBinaryOp CatName CatName CatName CatName
+>     -- | register a function: name, param types, retsetof, return type
+>   | CatCreateFunction CatName [CatName] Bool CatName
+>     -- | register a variadic function: name, param types, retsetof, return type
+>     -- the last parameter will be wrapped in an array type
+>   | CatCreateVariadicFunction CatName [CatName] Bool CatName
+>     -- | special ops include between, substring, position, basically
+>     -- all operators/functions which use mixfix or extra syntax
+>     -- (not including non scalar functions like aggregates)
+>   | CatCreateSpecialOp CatName [CatName] Bool CatName
+
+>     -- | register a aggregate: name, param types, return type
+>   | CatCreateAggregate CatName [CatName] CatName
+>     -- | register a table only: name, (colname,typename) pairs
+>   | CatCreateTable (CatName,CatName) [(CatName,CatNameExtra)]
+>     -- | register a cast in the catalog
+>   | CatCreateCast CatName CatName CastContext
+>     -- | register a type category for a type (used in the implicit cast resolution)
+>   | CatCreateTypeCategoryEntry CatName (Text,Bool)
+>     deriving (Eq,Ord,Typeable,Data,Show)
diff --git a/src/Database/HsSqlPpp/Internals/Catalog/CatalogUtils.lhs b/src/Database/HsSqlPpp/Internals/Catalog/CatalogUtils.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/Catalog/CatalogUtils.lhs
@@ -0,0 +1,71 @@
+
+some utilities which are used by catalog builder and by catalog
+internals
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Internals.Catalog.CatalogUtils
+>        (catLookupType, getCatName) where
+
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+> --import Control.Monad
+> --import Data.List
+> --import Data.Data
+> --import Data.Char
+> --import Data.Maybe
+
+> import qualified Data.Map as M
+> import qualified Data.Set as S
+> import Database.HsSqlPpp.Internals.TypesInternal
+> --import Database.HsSqlPpp.Utils.Utils
+> --import Data.Text (Text)
+> --import qualified Data.Text as T
+> --import qualified Data.Text.Lazy as LT
+> --import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+> --import Database.HsSqlPpp.Dialects.BaseCatalog
+
+names to refer to the pseudo types. This is very postgresql
+specific. Some of these should be deleted since hssqlppp has nothing
+to do with them. Some of them will become postgresql dialect specific
+and not appear here, and some we will repurpose to implement features
+for non-postgresql dialects as well.
+
+> pseudoTypes :: M.Map CatName Type
+> pseudoTypes = M.fromList
+>     [("any",Pseudo Any)
+>     ,("anyarray",Pseudo AnyArray)
+>     ,("anyelement",Pseudo AnyElement)
+>     ,("anyenum",Pseudo AnyEnum)
+>     ,("anyrange",Pseudo AnyRange)
+>     ,("anynonarray",Pseudo AnyNonArray)
+>     --,("cstring",Pseudo Cstring)
+>     ,("record",Pseudo (Record Nothing))
+>     --,("trigger",Pseudo Trigger)
+>      -- todo: fix this?
+>     --,("event_trigger",Pseudo Trigger)
+>     ,("void",Pseudo Void)
+>     --("_cstring",ArrayType $ Pseudo Cstring)
+>     ,("_record",ArrayType $ Pseudo (Record Nothing))
+>     --,("internal",Pseudo Internal)
+>     --,("language_handler", Pseudo LanguageHandler)
+>     --,("opaque", Pseudo Opaque)
+>     --,("fdw_handler", Pseudo FdwHandler)
+>     ]
+
+> -- | takes a [NameComponent] and returns the type for that name
+> -- will return a type not recognised if the type isn't in the catalog
+> catLookupType :: Catalog -> [NameComponent] -> Either [TypeError] Type
+> catLookupType cat ncs =
+>   case getCatName ncs of
+>     -- check if is a pseudo type
+>     cn | Just p <- M.lookup cn pseudoTypes -> Right p
+>     -- check for base, domain, enum or composite, and array
+>        | S.member cn (catScalarTypeNames cat) -> Right $ ScalarType cn
+>        | M.member cn (catDomainTypes cat) -> Right $ DomainType cn
+>        | M.member cn (catCompositeTypes cat) -> Right $ NamedCompositeType cn
+>        | Just t <- M.lookup cn (catArrayTypes cat) -> Right $ ArrayType $ ScalarType t
+>        | otherwise -> Left [UnknownTypeName cn]
+
+> getCatName :: [NameComponent] -> CatName
+> getCatName [] = error "empty name component in catalog code"
+> getCatName [x] = ncStrT x
+> getCatName (_:xs) = getCatName xs
diff --git a/src/Database/HsSqlPpp/Internals/Catalog/DefaultTemplate1Catalog.lhs b/src/Database/HsSqlPpp/Internals/Catalog/DefaultTemplate1Catalog.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Internals/Catalog/DefaultTemplate1Catalog.lhs
+++ /dev/null
@@ -1,13739 +0,0 @@
-
-
-
-This file is auto generated, to regenerate use the
-regenDefaultTemplate1catalog.sh script. You will need postgresql
-installed to do this.
-
-> module Database.HsSqlPpp.Internals.Catalog.DefaultTemplate1Catalog
->      (defaultTemplate1Catalog) where
->
-> import Database.HsSqlPpp.Internals.Catalog.CatalogInternal
-> import Database.HsSqlPpp.Internals.TypeType
->
-> defaultTemplate1Catalog :: Catalog
-> defaultTemplate1Catalog =
->     (\l -> case l of
->              Left x -> error $ show x
->              Right e -> e) $
->      updateCatalog defaultCatalog
-
-    
->        [CatCreateScalar (ScalarType "bool") "B" True,
->         CatCreateScalar (ScalarType "bytea") "U" False,
->         CatCreateScalar (ScalarType "char") "S" False,
->         CatCreateScalar (ScalarType "name") "S" False,
->         CatCreateScalar (ScalarType "int8") "N" False,
->         CatCreateScalar (ScalarType "int2") "N" False,
->         CatCreateScalar (ScalarType "int2vector") "A" False,
->         CatCreateScalar (ScalarType "int4") "N" False,
->         CatCreateScalar (ScalarType "regproc") "N" False,
->         CatCreateScalar (ScalarType "text") "S" True,
->         CatCreateScalar (ScalarType "oid") "N" True,
->         CatCreateScalar (ScalarType "tid") "U" False,
->         CatCreateScalar (ScalarType "xid") "U" False,
->         CatCreateScalar (ScalarType "cid") "U" False,
->         CatCreateScalar (ScalarType "oidvector") "A" False,
->         CatCreateScalar (ScalarType "xml") "U" False,
->         CatCreateScalar (ScalarType "point") "G" False,
->         CatCreateScalar (ScalarType "lseg") "G" False,
->         CatCreateScalar (ScalarType "path") "G" False,
->         CatCreateScalar (ScalarType "box") "G" False,
->         CatCreateScalar (ScalarType "polygon") "G" False,
->         CatCreateScalar (ScalarType "line") "G" False,
->         CatCreateScalar (ScalarType "float4") "N" False,
->         CatCreateScalar (ScalarType "float8") "N" True,
->         CatCreateScalar (ScalarType "abstime") "D" False,
->         CatCreateScalar (ScalarType "reltime") "T" False,
->         CatCreateScalar (ScalarType "tinterval") "T" False,
->         CatCreateScalar (ScalarType "circle") "G" False,
->         CatCreateScalar (ScalarType "money") "N" False,
->         CatCreateScalar (ScalarType "macaddr") "U" False,
->         CatCreateScalar (ScalarType "inet") "I" True,
->         CatCreateScalar (ScalarType "cidr") "I" False,
->         CatCreateScalar (ScalarType "aclitem") "U" False,
->         CatCreateScalar (ScalarType "bpchar") "S" False,
->         CatCreateScalar (ScalarType "varchar") "S" False,
->         CatCreateScalar (ScalarType "date") "D" False,
->         CatCreateScalar (ScalarType "time") "D" False,
->         CatCreateScalar (ScalarType "timestamp") "D" False,
->         CatCreateScalar (ScalarType "timestamptz") "D" True,
->         CatCreateScalar (ScalarType "interval") "T" True,
->         CatCreateScalar (ScalarType "timetz") "D" False,
->         CatCreateScalar (ScalarType "bit") "V" False,
->         CatCreateScalar (ScalarType "varbit") "V" True,
->         CatCreateScalar (ScalarType "numeric") "N" False,
->         CatCreateScalar (ScalarType "refcursor") "U" False,
->         CatCreateScalar (ScalarType "regprocedure") "N" False,
->         CatCreateScalar (ScalarType "regoper") "N" False,
->         CatCreateScalar (ScalarType "regoperator") "N" False,
->         CatCreateScalar (ScalarType "regclass") "N" False,
->         CatCreateScalar (ScalarType "regtype") "N" False,
->         CatCreateScalar (ScalarType "uuid") "U" False,
->         CatCreateScalar (ScalarType "tsvector") "U" False,
->         CatCreateScalar (ScalarType "gtsvector") "U" False,
->         CatCreateScalar (ScalarType "tsquery") "U" False,
->         CatCreateScalar (ScalarType "regconfig") "N" False,
->         CatCreateScalar (ScalarType "regdictionary") "N" False,
->         CatCreateScalar (ScalarType "txid_snapshot") "U" False,
->         CatCreateDomain (DomainType "information_schema.cardinal_number")
->           (ScalarType "int4"),
->         CatCreateDomain (DomainType "information_schema.character_data")
->           (ScalarType "varchar"),
->         CatCreateDomain (DomainType "information_schema.sql_identifier")
->           (ScalarType "varchar"),
->         CatCreateDomain (DomainType "information_schema.time_stamp")
->           (ScalarType "timestamptz"),
->         CatCreateDomain (DomainType "information_schema.yes_or_no")
->           (ScalarType "varchar"),
->         CatCreateCast (ScalarType "int8") (ScalarType "int2")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "int8") (ScalarType "int4")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "int8") (ScalarType "float4")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int8") (ScalarType "float8")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int8") (ScalarType "numeric")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int2") (ScalarType "int8")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int2") (ScalarType "int4")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int2") (ScalarType "float4")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int2") (ScalarType "float8")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int2") (ScalarType "numeric")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "int8")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "int2")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "float4")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "float8")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "numeric")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "float4") (ScalarType "int8")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "float4") (ScalarType "int2")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "float4") (ScalarType "int4")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "float4") (ScalarType "float8")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "float4") (ScalarType "numeric")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "float8") (ScalarType "int8")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "float8") (ScalarType "int2")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "float8") (ScalarType "int4")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "float8") (ScalarType "float4")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "float8") (ScalarType "numeric")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "numeric") (ScalarType "int8")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "numeric") (ScalarType "int2")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "numeric") (ScalarType "int4")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "numeric") (ScalarType "float4")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "numeric") (ScalarType "float8")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "money") (ScalarType "numeric")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "numeric") (ScalarType "money")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "money")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "int8") (ScalarType "money")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "bool")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "bool") (ScalarType "int4")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "int8") (ScalarType "oid")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int2") (ScalarType "oid")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "oid")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "oid") (ScalarType "int8")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "oid") (ScalarType "int4")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "oid") (ScalarType "regproc")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regproc") (ScalarType "oid")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int8") (ScalarType "regproc")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int2") (ScalarType "regproc")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "regproc")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regproc") (ScalarType "int8")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "regproc") (ScalarType "int4")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "regproc") (ScalarType "regprocedure")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regprocedure") (ScalarType "regproc")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "oid") (ScalarType "regprocedure")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regprocedure") (ScalarType "oid")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int8") (ScalarType "regprocedure")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int2") (ScalarType "regprocedure")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "regprocedure")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regprocedure") (ScalarType "int8")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "regprocedure") (ScalarType "int4")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "oid") (ScalarType "regoper")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regoper") (ScalarType "oid")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int8") (ScalarType "regoper")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int2") (ScalarType "regoper")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "regoper")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regoper") (ScalarType "int8")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "regoper") (ScalarType "int4")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "regoper") (ScalarType "regoperator")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regoperator") (ScalarType "regoper")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "oid") (ScalarType "regoperator")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regoperator") (ScalarType "oid")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int8") (ScalarType "regoperator")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int2") (ScalarType "regoperator")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "regoperator")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regoperator") (ScalarType "int8")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "regoperator") (ScalarType "int4")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "oid") (ScalarType "regclass")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regclass") (ScalarType "oid")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int8") (ScalarType "regclass")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int2") (ScalarType "regclass")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "regclass")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regclass") (ScalarType "int8")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "regclass") (ScalarType "int4")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "oid") (ScalarType "regtype")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regtype") (ScalarType "oid")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int8") (ScalarType "regtype")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int2") (ScalarType "regtype")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "regtype")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regtype") (ScalarType "int8")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "regtype") (ScalarType "int4")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "oid") (ScalarType "regconfig")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regconfig") (ScalarType "oid")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int8") (ScalarType "regconfig")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int2") (ScalarType "regconfig")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "regconfig")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regconfig") (ScalarType "int8")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "regconfig") (ScalarType "int4")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "oid") (ScalarType "regdictionary")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regdictionary") (ScalarType "oid")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int8") (ScalarType "regdictionary")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int2") (ScalarType "regdictionary")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "regdictionary")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "regdictionary") (ScalarType "int8")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "regdictionary") (ScalarType "int4")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "text") (ScalarType "regclass")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "varchar") (ScalarType "regclass")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "text") (ScalarType "bpchar")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "text") (ScalarType "varchar")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "bpchar") (ScalarType "text")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "bpchar") (ScalarType "varchar")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "varchar") (ScalarType "text")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "varchar") (ScalarType "bpchar")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "char") (ScalarType "text")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "char") (ScalarType "bpchar")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "char") (ScalarType "varchar")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "name") (ScalarType "text")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "name") (ScalarType "bpchar")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "name") (ScalarType "varchar")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "text") (ScalarType "char")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "bpchar") (ScalarType "char")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "varchar") (ScalarType "char")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "text") (ScalarType "name")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "bpchar") (ScalarType "name")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "varchar") (ScalarType "name")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "char") (ScalarType "int4")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "char")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "pg_node_tree") (ScalarType "text")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "abstime") (ScalarType "date")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "abstime") (ScalarType "time")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "abstime") (ScalarType "timestamp")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "abstime") (ScalarType "timestamptz")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "reltime") (ScalarType "interval")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "date") (ScalarType "timestamp")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "date") (ScalarType "timestamptz")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "time") (ScalarType "interval")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "time") (ScalarType "timetz")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "timestamp") (ScalarType "abstime")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "timestamp") (ScalarType "date")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "timestamp") (ScalarType "time")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "timestamp") (ScalarType "timestamptz")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "timestamptz") (ScalarType "abstime")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "timestamptz") (ScalarType "date")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "timestamptz") (ScalarType "time")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "timestamptz") (ScalarType "timestamp")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "timestamptz") (ScalarType "timetz")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "interval") (ScalarType "reltime")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "interval") (ScalarType "time")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "timetz") (ScalarType "time")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "abstime")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "abstime") (ScalarType "int4")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "reltime")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "reltime") (ScalarType "int4")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "lseg") (ScalarType "point")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "path") (ScalarType "point")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "path") (ScalarType "polygon")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "box") (ScalarType "point")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "box") (ScalarType "lseg")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "box") (ScalarType "polygon")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "box") (ScalarType "circle")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "polygon") (ScalarType "point")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "polygon") (ScalarType "path")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "polygon") (ScalarType "box")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "polygon") (ScalarType "circle")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "circle") (ScalarType "point")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "circle") (ScalarType "box")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "circle") (ScalarType "polygon")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "cidr") (ScalarType "inet")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "inet") (ScalarType "cidr")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "bit") (ScalarType "varbit")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "varbit") (ScalarType "bit")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "int8") (ScalarType "bit")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "int4") (ScalarType "bit")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "bit") (ScalarType "int8")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "bit") (ScalarType "int4")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "cidr") (ScalarType "text")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "inet") (ScalarType "text")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "bool") (ScalarType "text")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "xml") (ScalarType "text")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "text") (ScalarType "xml")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "cidr") (ScalarType "varchar")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "inet") (ScalarType "varchar")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "bool") (ScalarType "varchar")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "xml") (ScalarType "varchar")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "varchar") (ScalarType "xml")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "cidr") (ScalarType "bpchar")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "inet") (ScalarType "bpchar")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "bool") (ScalarType "bpchar")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "xml") (ScalarType "bpchar")
->           AssignmentCastContext,
->         CatCreateCast (ScalarType "bpchar") (ScalarType "xml")
->           ExplicitCastContext,
->         CatCreateCast (ScalarType "bpchar") (ScalarType "bpchar")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "varchar") (ScalarType "varchar")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "time") (ScalarType "time")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "timestamp") (ScalarType "timestamp")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "timestamptz") (ScalarType "timestamptz")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "interval") (ScalarType "interval")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "timetz") (ScalarType "timetz")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "bit") (ScalarType "bit")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "varbit") (ScalarType "varbit")
->           ImplicitCastContext,
->         CatCreateCast (ScalarType "numeric") (ScalarType "numeric")
->           ImplicitCastContext,
->         CatCreateFunction FunPrefix "~" [ScalarType "bit"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunPrefix "~" [ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunPrefix "~" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunPrefix "~" [ScalarType "inet"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunPrefix "~" [ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunPrefix "||/" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunPrefix "|/" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunPrefix "|" [ScalarType "tinterval"]
->           (ScalarType "abstime")
->           False,
->         CatCreateFunction FunPrefix "@@" [ScalarType "lseg"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunPrefix "@@" [ScalarType "polygon"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunPrefix "@@" [ScalarType "circle"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunPrefix "@@" [ScalarType "box"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunPrefix "@@" [ScalarType "path"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunPrefix "@-@" [ScalarType "lseg"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunPrefix "@-@" [ScalarType "path"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunPrefix "@" [ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunPrefix "@" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunPrefix "@" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunPrefix "@" [ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunPrefix "@" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunPrefix "@" [ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunPrefix "?|" [ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunPrefix "?|" [ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunPrefix "?-" [ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunPrefix "?-" [ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunPrefix "-" [ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunPrefix "-" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunPrefix "-" [ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunPrefix "-" [ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunPrefix "-" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunPrefix "-" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunPrefix "-" [ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunPrefix "+" [ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunPrefix "+" [ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunPrefix "+" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunPrefix "+" [ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunPrefix "+" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunPrefix "+" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunPrefix "#" [ScalarType "path"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunPrefix "#" [ScalarType "polygon"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunPrefix "!!" [ScalarType "tsquery"]
->           (ScalarType "tsquery")
->           False,
->         CatCreateFunction FunPrefix "!!" [ScalarType "int8"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunPostfix "!" [ScalarType "int8"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunBinary "~~*"
->           [ScalarType "bpchar", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~~*"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~~*"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~~"
->           [ScalarType "bpchar", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~~"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~~"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~~"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~>~"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~>~"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~>=~"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~>=~"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~="
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~="
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~="
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~="
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~="
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~<~"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~<~"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~<=~"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~<=~"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~*"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~*"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~*"
->           [ScalarType "bpchar", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~"
->           [ScalarType "bpchar", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~"
->           [ArrayType (ScalarType "aclitem"), ScalarType "aclitem"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~"
->           [ScalarType "circle", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~"
->           [ScalarType "polygon", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~"
->           [ScalarType "path", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "~"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "||"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunBinary "||"
->           [ScalarType "text", Pseudo AnyNonArray]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunBinary "||"
->           [Pseudo AnyNonArray, ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunBinary "||"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "tsquery")
->           False,
->         CatCreateFunction FunBinary "||"
->           [ScalarType "varbit", ScalarType "varbit"]
->           (ScalarType "varbit")
->           False,
->         CatCreateFunction FunBinary "||" [Pseudo AnyArray, Pseudo AnyArray]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunBinary "||"
->           [Pseudo AnyArray, Pseudo AnyElement]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunBinary "||"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunBinary "||"
->           [ScalarType "tsvector", ScalarType "tsvector"]
->           (ScalarType "tsvector")
->           False,
->         CatCreateFunction FunBinary "||"
->           [Pseudo AnyElement, Pseudo AnyArray]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunBinary "|>>"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "|>>"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "|>>"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "|&>"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "|&>"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "|&>"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "|"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "|"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "|"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunBinary "|"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunBinary "|"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunBinary "^"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "^"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunBinary "@@@"
->           [ScalarType "tsvector", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "@@@"
->           [ScalarType "tsquery", ScalarType "tsvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "@@"
->           [ScalarType "tsquery", ScalarType "tsvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "@@"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "@@"
->           [ScalarType "tsvector", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "@@"
->           [ScalarType "text", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "@>"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "@>"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "@>"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "@>"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "@>"
->           [ArrayType (ScalarType "aclitem"), ScalarType "aclitem"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "@>"
->           [ScalarType "box", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "@>"
->           [ScalarType "circle", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "@>"
->           [ScalarType "polygon", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "@>"
->           [ScalarType "path", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "@>" [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "?||"
->           [ScalarType "line", ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "?||"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "?|"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "?-|"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "?-|"
->           [ScalarType "line", ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "?-"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "?#"
->           [ScalarType "line", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "?#"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "?#"
->           [ScalarType "lseg", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "?#"
->           [ScalarType "line", ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "?#"
->           [ScalarType "lseg", ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "?#"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "?#"
->           [ScalarType "path", ScalarType "path"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">^"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">^"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">>="
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">>"
->           [ScalarType "bit", ScalarType "int4"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunBinary ">>"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">>"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">>"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">>"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">>"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary ">>"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary ">>"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunBinary ">>"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "date", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">=" [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "abstime", ScalarType "abstime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "date", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "reltime", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "timestamp", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "name", ScalarType "name"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "timetz", ScalarType "timetz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "timestamptz", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "bool", ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "oid", ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "tsvector", ScalarType "tsvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "oidvector", ScalarType "oidvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "timestamp", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "timestamptz", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "macaddr", ScalarType "macaddr"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">=" [Pseudo Record, Pseudo Record]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "tid", ScalarType "tid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "char", ScalarType "char"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "uuid", ScalarType "uuid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "path", ScalarType "path"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "varbit", ScalarType "varbit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">=" [Pseudo AnyEnum, Pseudo AnyEnum]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">="
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "tsvector", ScalarType "tsvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">" [Pseudo AnyEnum, Pseudo AnyEnum]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "uuid", ScalarType "uuid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "tid", ScalarType "tid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "timestamptz", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "timestamp", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "timestamptz", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "timestamp", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "date", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "date", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "abstime", ScalarType "abstime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "reltime", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "oid", ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "oidvector", ScalarType "oidvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "char", ScalarType "char"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "name", ScalarType "name"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "varbit", ScalarType "varbit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "path", ScalarType "path"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "macaddr", ScalarType "macaddr"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">" [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "timetz", ScalarType "timetz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">" [Pseudo Record, Pseudo Record]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "bool", ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary ">"
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "tsvector", ScalarType "tsvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "oidvector", ScalarType "oidvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "oid", ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "macaddr", ScalarType "macaddr"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "=" [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "line", ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "reltime", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "abstime", ScalarType "abstime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "date", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "name", ScalarType "name"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "date", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "timestamp", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "timetz", ScalarType "timetz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "char", ScalarType "char"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "timestamptz", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "bool", ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "timestamp", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "timestamptz", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "tid", ScalarType "tid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "uuid", ScalarType "uuid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "int2vector", ScalarType "int2vector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "cid", ScalarType "cid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "xid", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "=" [Pseudo Record, Pseudo Record]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "=" [Pseudo AnyEnum, Pseudo AnyEnum]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "xid", ScalarType "xid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "path", ScalarType "path"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "aclitem", ScalarType "aclitem"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "varbit", ScalarType "varbit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "="
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<^"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<^"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<@"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<@" [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<@"
->           [ScalarType "lseg", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<@"
->           [ScalarType "lseg", ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<@"
->           [ScalarType "point", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<@"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<@"
->           [ScalarType "point", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<@"
->           [ScalarType "point", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<@"
->           [ScalarType "point", ScalarType "path"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<@"
->           [ScalarType "point", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<@"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<@"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<@"
->           [ScalarType "point", ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<?>"
->           [ScalarType "abstime", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "bool", ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "timetz", ScalarType "timetz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "timestamptz", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "date", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "timestamp", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "macaddr", ScalarType "macaddr"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "timestamp", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "tsvector", ScalarType "tsvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>" [Pseudo Record, Pseudo Record]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "reltime", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>" [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "timestamptz", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "oidvector", ScalarType "oidvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "name", ScalarType "name"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>" [Pseudo AnyEnum, Pseudo AnyEnum]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "abstime", ScalarType "abstime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "oid", ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "uuid", ScalarType "uuid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "tid", ScalarType "tid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "char", ScalarType "char"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "date", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "varbit", ScalarType "varbit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<>"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "varbit", ScalarType "varbit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "name", ScalarType "name"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "char", ScalarType "char"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "tsvector", ScalarType "tsvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<=" [Pseudo AnyEnum, Pseudo AnyEnum]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "uuid", ScalarType "uuid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "tid", ScalarType "tid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "timetz", ScalarType "timetz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "timestamptz", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "timestamp", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<=" [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "timestamptz", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "macaddr", ScalarType "macaddr"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "timestamp", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<=" [Pseudo Record, Pseudo Record]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "date", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "date", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "bool", ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "path", ScalarType "path"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "abstime", ScalarType "abstime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "reltime", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "oid", ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "oidvector", ScalarType "oidvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<="
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<<|"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<<|"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<<|"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<<="
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<<"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "<<"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<<"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<<"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "<<"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<<"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunBinary "<<"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<<"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<<"
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<<"
->           [ScalarType "bit", ScalarType "int4"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunBinary "<->"
->           [ScalarType "line", ScalarType "box"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "<->"
->           [ScalarType "circle", ScalarType "polygon"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "<->"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "<->"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "<->"
->           [ScalarType "lseg", ScalarType "line"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "<->"
->           [ScalarType "line", ScalarType "line"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "<->"
->           [ScalarType "point", ScalarType "line"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "<->"
->           [ScalarType "point", ScalarType "lseg"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "<->"
->           [ScalarType "path", ScalarType "path"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "<->"
->           [ScalarType "lseg", ScalarType "box"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "<->"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "<->"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "<->"
->           [ScalarType "point", ScalarType "circle"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "<->"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "<->"
->           [ScalarType "point", ScalarType "path"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "<->"
->           [ScalarType "point", ScalarType "box"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "<#>"
->           [ScalarType "abstime", ScalarType "abstime"]
->           (ScalarType "tinterval")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "varbit", ScalarType "varbit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "char", ScalarType "char"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "timestamp", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<" [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "macaddr", ScalarType "macaddr"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "timestamptz", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "timestamptz", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "timestamp", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "timetz", ScalarType "timetz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "date", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "name", ScalarType "name"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "oidvector", ScalarType "oidvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "date", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "tid", ScalarType "tid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "uuid", ScalarType "uuid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "path", ScalarType "path"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<" [Pseudo AnyEnum, Pseudo AnyEnum]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "bool", ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "abstime", ScalarType "abstime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<" [Pseudo Record, Pseudo Record]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "tsvector", ScalarType "tsvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "reltime", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "oid", ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "<"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "circle", ScalarType "point"]
->           (ScalarType "circle")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "interval", ScalarType "float8"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "money", ScalarType "int2"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "money", ScalarType "int4"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "money", ScalarType "float8"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "money", ScalarType "float4"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "box", ScalarType "point"]
->           (ScalarType "box")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunBinary "/"
->           [ScalarType "path", ScalarType "point"]
->           (ScalarType "path")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "date", ScalarType "interval"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "time", ScalarType "interval"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "path", ScalarType "point"]
->           (ScalarType "path")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "abstime", ScalarType "reltime"]
->           (ScalarType "abstime")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "timestamptz", ScalarType "interval"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ArrayType (ScalarType "aclitem"), ScalarType "aclitem"]
->           (ArrayType (ScalarType "aclitem"))
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "circle", ScalarType "point"]
->           (ScalarType "circle")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "inet", ScalarType "int8"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "box", ScalarType "point"]
->           (ScalarType "box")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "timetz", ScalarType "interval"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "timestamp", ScalarType "interval"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "-"
->           [ScalarType "date", ScalarType "int4"]
->           (ScalarType "date")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "interval", ScalarType "timetz"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "box", ScalarType "point"]
->           (ScalarType "box")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "timestamp", ScalarType "interval"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "interval", ScalarType "date"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "timetz", ScalarType "date"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "date", ScalarType "int4"]
->           (ScalarType "date")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "int8", ScalarType "inet"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "time", ScalarType "interval"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "interval", ScalarType "time"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "inet", ScalarType "int8"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ArrayType (ScalarType "aclitem"), ScalarType "aclitem"]
->           (ArrayType (ScalarType "aclitem"))
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "date", ScalarType "interval"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "abstime", ScalarType "reltime"]
->           (ScalarType "abstime")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "timestamptz", ScalarType "interval"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "circle", ScalarType "point"]
->           (ScalarType "circle")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "path", ScalarType "path"]
->           (ScalarType "path")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "path", ScalarType "point"]
->           (ScalarType "path")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "date", ScalarType "timetz"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "int4", ScalarType "date"]
->           (ScalarType "date")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "interval", ScalarType "timestamptz"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "date", ScalarType "time"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "timetz", ScalarType "interval"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "interval", ScalarType "timestamp"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunBinary "+"
->           [ScalarType "time", ScalarType "date"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "path", ScalarType "point"]
->           (ScalarType "path")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "box", ScalarType "point"]
->           (ScalarType "box")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "money", ScalarType "float4"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "float4", ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "money", ScalarType "float8"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "money", ScalarType "int4"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "money", ScalarType "int2"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "float8", ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "int4", ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "int2", ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "float8", ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "interval", ScalarType "float8"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "circle", ScalarType "point"]
->           (ScalarType "circle")
->           False,
->         CatCreateFunction FunBinary "*"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunBinary "&>"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "&>"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "&>"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "&<|"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "&<|"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "&<|"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "&<"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "&<"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "&<"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "&&"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "&&" [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "&&"
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "&&"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "&&"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "tsquery")
->           False,
->         CatCreateFunction FunBinary "&&"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "&"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunBinary "&"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "&"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunBinary "&"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "&"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunBinary "%"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunBinary "%"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "%"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunBinary "%"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "#>="
->           [ScalarType "tinterval", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "#>"
->           [ScalarType "tinterval", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "#="
->           [ScalarType "tinterval", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "#<>"
->           [ScalarType "tinterval", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "#<="
->           [ScalarType "tinterval", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "#<"
->           [ScalarType "tinterval", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "##"
->           [ScalarType "line", ScalarType "lseg"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunBinary "##"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunBinary "##"
->           [ScalarType "point", ScalarType "box"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunBinary "##"
->           [ScalarType "point", ScalarType "lseg"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunBinary "##"
->           [ScalarType "point", ScalarType "line"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunBinary "##"
->           [ScalarType "lseg", ScalarType "box"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunBinary "##"
->           [ScalarType "line", ScalarType "box"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunBinary "##"
->           [ScalarType "lseg", ScalarType "line"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunBinary "#"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "box")
->           False,
->         CatCreateFunction FunBinary "#"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunBinary "#"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunBinary "#"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunBinary "#"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunBinary "#"
->           [ScalarType "line", ScalarType "line"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunBinary "#"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunBinary "!~~*"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "!~~*"
->           [ScalarType "bpchar", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "!~~*"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "!~~"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "!~~"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "!~~"
->           [ScalarType "bpchar", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "!~~"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "!~*"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "!~*"
->           [ScalarType "bpchar", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "!~*"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "!~"
->           [ScalarType "bpchar", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "!~"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunBinary "!~"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "RI_FKey_cascade_del" [] (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "RI_FKey_cascade_upd" [] (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "RI_FKey_check_ins" [] (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "RI_FKey_check_upd" [] (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "RI_FKey_noaction_del" []
->           (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "RI_FKey_noaction_upd" []
->           (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "RI_FKey_restrict_del" []
->           (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "RI_FKey_restrict_upd" []
->           (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "RI_FKey_setdefault_del" []
->           (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "RI_FKey_setdefault_upd" []
->           (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "RI_FKey_setnull_del" [] (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "RI_FKey_setnull_upd" [] (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "abbrev" [ScalarType "cidr"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "abbrev" [ScalarType "inet"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "abs" [ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "abs" [ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "abs" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "abs" [ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "abs" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "abs" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "abstime" [ScalarType "timestamp"]
->           (ScalarType "abstime")
->           False,
->         CatCreateFunction FunName "abstime" [ScalarType "timestamptz"]
->           (ScalarType "abstime")
->           False,
->         CatCreateFunction FunName "abstimeeq"
->           [ScalarType "abstime", ScalarType "abstime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "abstimege"
->           [ScalarType "abstime", ScalarType "abstime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "abstimegt"
->           [ScalarType "abstime", ScalarType "abstime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "abstimein" [Pseudo Cstring]
->           (ScalarType "abstime")
->           False,
->         CatCreateFunction FunName "abstimele"
->           [ScalarType "abstime", ScalarType "abstime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "abstimelt"
->           [ScalarType "abstime", ScalarType "abstime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "abstimene"
->           [ScalarType "abstime", ScalarType "abstime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "abstimeout" [ScalarType "abstime"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "abstimerecv" [Pseudo Internal]
->           (ScalarType "abstime")
->           False,
->         CatCreateFunction FunName "abstimesend" [ScalarType "abstime"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "aclcontains"
->           [ArrayType (ScalarType "aclitem"), ScalarType "aclitem"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "aclexplode"
->           [ArrayType (ScalarType "aclitem")]
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "aclinsert"
->           [ArrayType (ScalarType "aclitem"), ScalarType "aclitem"]
->           (ArrayType (ScalarType "aclitem"))
->           False,
->         CatCreateFunction FunName "aclitemeq"
->           [ScalarType "aclitem", ScalarType "aclitem"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "aclitemin" [Pseudo Cstring]
->           (ScalarType "aclitem")
->           False,
->         CatCreateFunction FunName "aclitemout" [ScalarType "aclitem"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "aclremove"
->           [ArrayType (ScalarType "aclitem"), ScalarType "aclitem"]
->           (ArrayType (ScalarType "aclitem"))
->           False,
->         CatCreateFunction FunName "acos" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "age" [ScalarType "xid"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "age" [ScalarType "timestamp"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "age" [ScalarType "timestamptz"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "age"
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "age"
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "any_in" [Pseudo Cstring] (Pseudo Any)
->           False,
->         CatCreateFunction FunName "any_out" [Pseudo Any] (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "anyarray_in" [Pseudo Cstring]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunName "anyarray_out" [Pseudo AnyArray]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "anyarray_recv" [Pseudo Internal]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunName "anyarray_send" [Pseudo AnyArray]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "anyelement_in" [Pseudo Cstring]
->           (Pseudo AnyElement)
->           False,
->         CatCreateFunction FunName "anyelement_out" [Pseudo AnyElement]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "anyenum_in" [Pseudo Cstring]
->           (Pseudo AnyEnum)
->           False,
->         CatCreateFunction FunName "anyenum_out" [Pseudo AnyEnum]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "anynonarray_in" [Pseudo Cstring]
->           (Pseudo AnyNonArray)
->           False,
->         CatCreateFunction FunName "anynonarray_out" [Pseudo AnyNonArray]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "anytextcat"
->           [Pseudo AnyNonArray, ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "area" [ScalarType "path"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "area" [ScalarType "box"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "area" [ScalarType "circle"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "areajoinsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int2", Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "areasel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "array_agg_finalfn" [Pseudo Internal]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunName "array_agg_transfn"
->           [Pseudo Internal, Pseudo AnyElement]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "array_append"
->           [Pseudo AnyArray, Pseudo AnyElement]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunName "array_cat"
->           [Pseudo AnyArray, Pseudo AnyArray]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunName "array_dims" [Pseudo AnyArray]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "array_eq"
->           [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "array_fill"
->           [Pseudo AnyElement, ArrayType (ScalarType "int4")]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunName "array_fill"
->           [Pseudo AnyElement, ArrayType (ScalarType "int4"),
->            ArrayType (ScalarType "int4")]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunName "array_ge"
->           [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "array_gt"
->           [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "array_in"
->           [Pseudo Cstring, ScalarType "oid", ScalarType "int4"]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunName "array_larger"
->           [Pseudo AnyArray, Pseudo AnyArray]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunName "array_le"
->           [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "array_length"
->           [Pseudo AnyArray, ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "array_lower"
->           [Pseudo AnyArray, ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "array_lt"
->           [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "array_ndims" [Pseudo AnyArray]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "array_ne"
->           [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "array_out" [Pseudo AnyArray]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "array_prepend"
->           [Pseudo AnyElement, Pseudo AnyArray]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunName "array_recv"
->           [Pseudo Internal, ScalarType "oid", ScalarType "int4"]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunName "array_send" [Pseudo AnyArray]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "array_smaller"
->           [Pseudo AnyArray, Pseudo AnyArray]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunName "array_to_string"
->           [Pseudo AnyArray, ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "array_to_string"
->           [Pseudo AnyArray, ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "array_upper"
->           [Pseudo AnyArray, ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "arraycontained"
->           [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "arraycontains"
->           [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "arrayoverlap"
->           [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "ascii" [ScalarType "text"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "ascii_to_mic"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "ascii_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "asin" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "atan" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "atan2"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "big5_to_euc_tw"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "big5_to_mic"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "big5_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "bit"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunName "bit"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunName "bit"
->           [ScalarType "bit", ScalarType "int4", ScalarType "bool"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunName "bit_in"
->           [Pseudo Cstring, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunName "bit_length" [ScalarType "bytea"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "bit_length" [ScalarType "text"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "bit_length" [ScalarType "bit"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "bit_out" [ScalarType "bit"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "bit_recv"
->           [Pseudo Internal, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunName "bit_send" [ScalarType "bit"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "bitand"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunName "bitcat"
->           [ScalarType "varbit", ScalarType "varbit"]
->           (ScalarType "varbit")
->           False,
->         CatCreateFunction FunName "bitcmp"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "biteq"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bitge"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bitgt"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bitle"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bitlt"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bitne"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bitnot" [ScalarType "bit"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunName "bitor"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunName "bitshiftleft"
->           [ScalarType "bit", ScalarType "int4"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunName "bitshiftright"
->           [ScalarType "bit", ScalarType "int4"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunName "bittypmodin"
->           [ArrayType (Pseudo Cstring)]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "bittypmodout" [ScalarType "int4"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "bitxor"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunName "bool" [ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "booland_statefunc"
->           [ScalarType "bool", ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "booleq"
->           [ScalarType "bool", ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "boolge"
->           [ScalarType "bool", ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "boolgt"
->           [ScalarType "bool", ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "boolin" [Pseudo Cstring]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "boolle"
->           [ScalarType "bool", ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "boollt"
->           [ScalarType "bool", ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "boolne"
->           [ScalarType "bool", ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "boolor_statefunc"
->           [ScalarType "bool", ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "boolout" [ScalarType "bool"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "boolrecv" [Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "boolsend" [ScalarType "bool"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "box" [ScalarType "polygon"]
->           (ScalarType "box")
->           False,
->         CatCreateFunction FunName "box" [ScalarType "circle"]
->           (ScalarType "box")
->           False,
->         CatCreateFunction FunName "box"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "box")
->           False,
->         CatCreateFunction FunName "box_above"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_above_eq"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_add"
->           [ScalarType "box", ScalarType "point"]
->           (ScalarType "box")
->           False,
->         CatCreateFunction FunName "box_below"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_below_eq"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_center" [ScalarType "box"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "box_contain"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_contain_pt"
->           [ScalarType "box", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_contained"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_distance"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "box_div"
->           [ScalarType "box", ScalarType "point"]
->           (ScalarType "box")
->           False,
->         CatCreateFunction FunName "box_eq"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_ge"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_gt"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_in" [Pseudo Cstring]
->           (ScalarType "box")
->           False,
->         CatCreateFunction FunName "box_intersect"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "box")
->           False,
->         CatCreateFunction FunName "box_le"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_left"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_lt"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_mul"
->           [ScalarType "box", ScalarType "point"]
->           (ScalarType "box")
->           False,
->         CatCreateFunction FunName "box_out" [ScalarType "box"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "box_overabove"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_overbelow"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_overlap"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_overleft"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_overright"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_recv" [Pseudo Internal]
->           (ScalarType "box")
->           False,
->         CatCreateFunction FunName "box_right"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_same"
->           [ScalarType "box", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "box_send" [ScalarType "box"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "box_sub"
->           [ScalarType "box", ScalarType "point"]
->           (ScalarType "box")
->           False,
->         CatCreateFunction FunName "bpchar" [ScalarType "char"]
->           (ScalarType "bpchar")
->           False,
->         CatCreateFunction FunName "bpchar" [ScalarType "name"]
->           (ScalarType "bpchar")
->           False,
->         CatCreateFunction FunName "bpchar"
->           [ScalarType "bpchar", ScalarType "int4", ScalarType "bool"]
->           (ScalarType "bpchar")
->           False,
->         CatCreateFunction FunName "bpchar_larger"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bpchar")
->           False,
->         CatCreateFunction FunName "bpchar_pattern_ge"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpchar_pattern_gt"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpchar_pattern_le"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpchar_pattern_lt"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpchar_smaller"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bpchar")
->           False,
->         CatCreateFunction FunName "bpcharcmp"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "bpchareq"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpcharge"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpchargt"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpchariclike"
->           [ScalarType "bpchar", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpcharicnlike"
->           [ScalarType "bpchar", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpcharicregexeq"
->           [ScalarType "bpchar", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpcharicregexne"
->           [ScalarType "bpchar", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpcharin"
->           [Pseudo Cstring, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "bpchar")
->           False,
->         CatCreateFunction FunName "bpcharle"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpcharlike"
->           [ScalarType "bpchar", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpcharlt"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpcharne"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpcharnlike"
->           [ScalarType "bpchar", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpcharout" [ScalarType "bpchar"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "bpcharrecv"
->           [Pseudo Internal, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "bpchar")
->           False,
->         CatCreateFunction FunName "bpcharregexeq"
->           [ScalarType "bpchar", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpcharregexne"
->           [ScalarType "bpchar", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bpcharsend" [ScalarType "bpchar"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "bpchartypmodin"
->           [ArrayType (Pseudo Cstring)]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "bpchartypmodout" [ScalarType "int4"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "broadcast" [ScalarType "inet"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunName "btabstimecmp"
->           [ScalarType "abstime", ScalarType "abstime"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btarraycmp"
->           [Pseudo AnyArray, Pseudo AnyArray]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btbeginscan"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "btboolcmp"
->           [ScalarType "bool", ScalarType "bool"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btbpchar_pattern_cmp"
->           [ScalarType "bpchar", ScalarType "bpchar"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btbuild"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "btbuildempty" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "btbulkdelete"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "btcharcmp"
->           [ScalarType "char", ScalarType "char"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btcostestimate"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "btendscan" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "btfloat48cmp"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btfloat4cmp"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btfloat84cmp"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btfloat8cmp"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btgetbitmap"
->           [Pseudo Internal, Pseudo Internal]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "btgettuple"
->           [Pseudo Internal, Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "btinsert"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "btint24cmp"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btint28cmp"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btint2cmp"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btint42cmp"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btint48cmp"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btint4cmp"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btint82cmp"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btint84cmp"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btint8cmp"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btmarkpos" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "btnamecmp"
->           [ScalarType "name", ScalarType "name"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btoidcmp"
->           [ScalarType "oid", ScalarType "oid"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btoidvectorcmp"
->           [ScalarType "oidvector", ScalarType "oidvector"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btoptions"
->           [ArrayType (ScalarType "text"), ScalarType "bool"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "btrecordcmp"
->           [Pseudo Record, Pseudo Record]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btreltimecmp"
->           [ScalarType "reltime", ScalarType "reltime"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btrescan"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "btrestrpos" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "btrim" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "btrim"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "btrim"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "bttext_pattern_cmp"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "bttextcmp"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "bttidcmp"
->           [ScalarType "tid", ScalarType "tid"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "bttintervalcmp"
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "btvacuumcleanup"
->           [Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "byteacat"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "byteacmp"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "byteaeq"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "byteage"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "byteagt"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "byteain" [Pseudo Cstring]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "byteale"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bytealike"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "bytealt"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "byteane"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "byteanlike"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "byteaout" [ScalarType "bytea"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "bytearecv" [Pseudo Internal]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "byteasend" [ScalarType "bytea"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "cash_cmp"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "cash_div_cash"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "cash_div_flt4"
->           [ScalarType "money", ScalarType "float4"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "cash_div_flt8"
->           [ScalarType "money", ScalarType "float8"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "cash_div_int2"
->           [ScalarType "money", ScalarType "int2"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "cash_div_int4"
->           [ScalarType "money", ScalarType "int4"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "cash_eq"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "cash_ge"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "cash_gt"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "cash_in" [Pseudo Cstring]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "cash_le"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "cash_lt"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "cash_mi"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "cash_mul_flt4"
->           [ScalarType "money", ScalarType "float4"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "cash_mul_flt8"
->           [ScalarType "money", ScalarType "float8"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "cash_mul_int2"
->           [ScalarType "money", ScalarType "int2"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "cash_mul_int4"
->           [ScalarType "money", ScalarType "int4"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "cash_ne"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "cash_out" [ScalarType "money"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "cash_pl"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "cash_recv" [Pseudo Internal]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "cash_send" [ScalarType "money"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "cash_words" [ScalarType "money"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "cashlarger"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "cashsmaller"
->           [ScalarType "money", ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "cbrt" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "ceil" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "ceil" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "ceiling" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "ceiling" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "center" [ScalarType "box"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "center" [ScalarType "circle"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "char" [ScalarType "int4"]
->           (ScalarType "char")
->           False,
->         CatCreateFunction FunName "char" [ScalarType "text"]
->           (ScalarType "char")
->           False,
->         CatCreateFunction FunName "char_length" [ScalarType "text"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "char_length" [ScalarType "bpchar"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "character_length" [ScalarType "text"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "character_length" [ScalarType "bpchar"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "chareq"
->           [ScalarType "char", ScalarType "char"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "charge"
->           [ScalarType "char", ScalarType "char"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "chargt"
->           [ScalarType "char", ScalarType "char"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "charin" [Pseudo Cstring]
->           (ScalarType "char")
->           False,
->         CatCreateFunction FunName "charle"
->           [ScalarType "char", ScalarType "char"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "charlt"
->           [ScalarType "char", ScalarType "char"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "charne"
->           [ScalarType "char", ScalarType "char"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "charout" [ScalarType "char"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "charrecv" [Pseudo Internal]
->           (ScalarType "char")
->           False,
->         CatCreateFunction FunName "charsend" [ScalarType "char"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "chr" [ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "cideq"
->           [ScalarType "cid", ScalarType "cid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "cidin" [Pseudo Cstring]
->           (ScalarType "cid")
->           False,
->         CatCreateFunction FunName "cidout" [ScalarType "cid"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "cidr" [ScalarType "inet"]
->           (ScalarType "cidr")
->           False,
->         CatCreateFunction FunName "cidr_in" [Pseudo Cstring]
->           (ScalarType "cidr")
->           False,
->         CatCreateFunction FunName "cidr_out" [ScalarType "cidr"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "cidr_recv" [Pseudo Internal]
->           (ScalarType "cidr")
->           False,
->         CatCreateFunction FunName "cidr_send" [ScalarType "cidr"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "cidrecv" [Pseudo Internal]
->           (ScalarType "cid")
->           False,
->         CatCreateFunction FunName "cidsend" [ScalarType "cid"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "circle" [ScalarType "box"]
->           (ScalarType "circle")
->           False,
->         CatCreateFunction FunName "circle" [ScalarType "polygon"]
->           (ScalarType "circle")
->           False,
->         CatCreateFunction FunName "circle"
->           [ScalarType "point", ScalarType "float8"]
->           (ScalarType "circle")
->           False,
->         CatCreateFunction FunName "circle_above"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_add_pt"
->           [ScalarType "circle", ScalarType "point"]
->           (ScalarType "circle")
->           False,
->         CatCreateFunction FunName "circle_below"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_center" [ScalarType "circle"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "circle_contain"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_contain_pt"
->           [ScalarType "circle", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_contained"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_distance"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "circle_div_pt"
->           [ScalarType "circle", ScalarType "point"]
->           (ScalarType "circle")
->           False,
->         CatCreateFunction FunName "circle_eq"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_ge"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_gt"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_in" [Pseudo Cstring]
->           (ScalarType "circle")
->           False,
->         CatCreateFunction FunName "circle_le"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_left"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_lt"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_mul_pt"
->           [ScalarType "circle", ScalarType "point"]
->           (ScalarType "circle")
->           False,
->         CatCreateFunction FunName "circle_ne"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_out" [ScalarType "circle"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "circle_overabove"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_overbelow"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_overlap"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_overleft"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_overright"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_recv" [Pseudo Internal]
->           (ScalarType "circle")
->           False,
->         CatCreateFunction FunName "circle_right"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_same"
->           [ScalarType "circle", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "circle_send" [ScalarType "circle"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "circle_sub_pt"
->           [ScalarType "circle", ScalarType "point"]
->           (ScalarType "circle")
->           False,
->         CatCreateFunction FunName "clock_timestamp" []
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "close_lb"
->           [ScalarType "line", ScalarType "box"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "close_ls"
->           [ScalarType "line", ScalarType "lseg"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "close_lseg"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "close_pb"
->           [ScalarType "point", ScalarType "box"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "close_pl"
->           [ScalarType "point", ScalarType "line"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "close_ps"
->           [ScalarType "point", ScalarType "lseg"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "close_sb"
->           [ScalarType "lseg", ScalarType "box"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "close_sl"
->           [ScalarType "lseg", ScalarType "line"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "col_description"
->           [ScalarType "oid", ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "contjoinsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int2", Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "contsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "convert"
->           [ScalarType "bytea", ScalarType "name", ScalarType "name"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "convert_from"
->           [ScalarType "bytea", ScalarType "name"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "convert_to"
->           [ScalarType "text", ScalarType "name"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "cos" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "cot" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "cstring_in" [Pseudo Cstring]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "cstring_out" [Pseudo Cstring]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "cstring_recv" [Pseudo Internal]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "cstring_send" [Pseudo Cstring]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "current_database" [] (ScalarType "name")
->           False,
->         CatCreateFunction FunName "current_query" [] (ScalarType "text")
->           False,
->         CatCreateFunction FunName "current_schema" [] (ScalarType "name")
->           False,
->         CatCreateFunction FunName "current_schemas" [ScalarType "bool"]
->           (ArrayType (ScalarType "name"))
->           False,
->         CatCreateFunction FunName "current_setting" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "current_user" [] (ScalarType "name")
->           False,
->         CatCreateFunction FunName "currtid"
->           [ScalarType "oid", ScalarType "tid"]
->           (ScalarType "tid")
->           False,
->         CatCreateFunction FunName "currtid2"
->           [ScalarType "text", ScalarType "tid"]
->           (ScalarType "tid")
->           False,
->         CatCreateFunction FunName "currval" [ScalarType "regclass"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "cursor_to_xml"
->           [ScalarType "refcursor", ScalarType "int4", ScalarType "bool",
->            ScalarType "bool", ScalarType "text"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "cursor_to_xmlschema"
->           [ScalarType "refcursor", ScalarType "bool", ScalarType "bool",
->            ScalarType "text"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "database_to_xml"
->           [ScalarType "bool", ScalarType "bool", ScalarType "text"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "database_to_xml_and_xmlschema"
->           [ScalarType "bool", ScalarType "bool", ScalarType "text"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "database_to_xmlschema"
->           [ScalarType "bool", ScalarType "bool", ScalarType "text"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "date" [ScalarType "abstime"]
->           (ScalarType "date")
->           False,
->         CatCreateFunction FunName "date" [ScalarType "timestamp"]
->           (ScalarType "date")
->           False,
->         CatCreateFunction FunName "date" [ScalarType "timestamptz"]
->           (ScalarType "date")
->           False,
->         CatCreateFunction FunName "date_cmp"
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "date_cmp_timestamp"
->           [ScalarType "date", ScalarType "timestamp"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "date_cmp_timestamptz"
->           [ScalarType "date", ScalarType "timestamptz"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "date_eq"
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_eq_timestamp"
->           [ScalarType "date", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_eq_timestamptz"
->           [ScalarType "date", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_ge"
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_ge_timestamp"
->           [ScalarType "date", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_ge_timestamptz"
->           [ScalarType "date", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_gt"
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_gt_timestamp"
->           [ScalarType "date", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_gt_timestamptz"
->           [ScalarType "date", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_in" [Pseudo Cstring]
->           (ScalarType "date")
->           False,
->         CatCreateFunction FunName "date_larger"
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "date")
->           False,
->         CatCreateFunction FunName "date_le"
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_le_timestamp"
->           [ScalarType "date", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_le_timestamptz"
->           [ScalarType "date", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_lt"
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_lt_timestamp"
->           [ScalarType "date", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_lt_timestamptz"
->           [ScalarType "date", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_mi"
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "date_mi_interval"
->           [ScalarType "date", ScalarType "interval"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "date_mii"
->           [ScalarType "date", ScalarType "int4"]
->           (ScalarType "date")
->           False,
->         CatCreateFunction FunName "date_ne"
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_ne_timestamp"
->           [ScalarType "date", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_ne_timestamptz"
->           [ScalarType "date", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "date_out" [ScalarType "date"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "date_part"
->           [ScalarType "text", ScalarType "abstime"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "date_part"
->           [ScalarType "text", ScalarType "reltime"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "date_part"
->           [ScalarType "text", ScalarType "date"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "date_part"
->           [ScalarType "text", ScalarType "time"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "date_part"
->           [ScalarType "text", ScalarType "timestamp"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "date_part"
->           [ScalarType "text", ScalarType "timestamptz"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "date_part"
->           [ScalarType "text", ScalarType "interval"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "date_part"
->           [ScalarType "text", ScalarType "timetz"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "date_pl_interval"
->           [ScalarType "date", ScalarType "interval"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "date_pli"
->           [ScalarType "date", ScalarType "int4"]
->           (ScalarType "date")
->           False,
->         CatCreateFunction FunName "date_recv" [Pseudo Internal]
->           (ScalarType "date")
->           False,
->         CatCreateFunction FunName "date_send" [ScalarType "date"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "date_smaller"
->           [ScalarType "date", ScalarType "date"]
->           (ScalarType "date")
->           False,
->         CatCreateFunction FunName "date_trunc"
->           [ScalarType "text", ScalarType "timestamp"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "date_trunc"
->           [ScalarType "text", ScalarType "timestamptz"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "date_trunc"
->           [ScalarType "text", ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "datetime_pl"
->           [ScalarType "date", ScalarType "time"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "datetimetz_pl"
->           [ScalarType "date", ScalarType "timetz"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "dcbrt" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "decode"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "degrees" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "dexp" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "diagonal" [ScalarType "box"]
->           (ScalarType "lseg")
->           False,
->         CatCreateFunction FunName "diameter" [ScalarType "circle"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "dispell_init" [Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "dispell_lexize"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "dist_cpoly"
->           [ScalarType "circle", ScalarType "polygon"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "dist_lb"
->           [ScalarType "line", ScalarType "box"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "dist_pb"
->           [ScalarType "point", ScalarType "box"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "dist_pc"
->           [ScalarType "point", ScalarType "circle"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "dist_pl"
->           [ScalarType "point", ScalarType "line"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "dist_ppath"
->           [ScalarType "point", ScalarType "path"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "dist_ps"
->           [ScalarType "point", ScalarType "lseg"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "dist_sb"
->           [ScalarType "lseg", ScalarType "box"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "dist_sl"
->           [ScalarType "lseg", ScalarType "line"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "div"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "dlog1" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "dlog10" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "domain_in"
->           [Pseudo Cstring, ScalarType "oid", ScalarType "int4"]
->           (Pseudo Any)
->           False,
->         CatCreateFunction FunName "domain_recv"
->           [Pseudo Internal, ScalarType "oid", ScalarType "int4"]
->           (Pseudo Any)
->           False,
->         CatCreateFunction FunName "dpow"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "dround" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "dsimple_init" [Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "dsimple_lexize"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "dsnowball_init" [Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "dsnowball_lexize"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "dsqrt" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "dsynonym_init" [Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "dsynonym_lexize"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "dtrunc" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "encode"
->           [ScalarType "bytea", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "enum_cmp"
->           [Pseudo AnyEnum, Pseudo AnyEnum]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "enum_eq"
->           [Pseudo AnyEnum, Pseudo AnyEnum]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "enum_first" [Pseudo AnyEnum]
->           (Pseudo AnyEnum)
->           False,
->         CatCreateFunction FunName "enum_ge"
->           [Pseudo AnyEnum, Pseudo AnyEnum]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "enum_gt"
->           [Pseudo AnyEnum, Pseudo AnyEnum]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "enum_in"
->           [Pseudo Cstring, ScalarType "oid"]
->           (Pseudo AnyEnum)
->           False,
->         CatCreateFunction FunName "enum_larger"
->           [Pseudo AnyEnum, Pseudo AnyEnum]
->           (Pseudo AnyEnum)
->           False,
->         CatCreateFunction FunName "enum_last" [Pseudo AnyEnum]
->           (Pseudo AnyEnum)
->           False,
->         CatCreateFunction FunName "enum_le"
->           [Pseudo AnyEnum, Pseudo AnyEnum]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "enum_lt"
->           [Pseudo AnyEnum, Pseudo AnyEnum]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "enum_ne"
->           [Pseudo AnyEnum, Pseudo AnyEnum]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "enum_out" [Pseudo AnyEnum]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "enum_range" [Pseudo AnyEnum]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunName "enum_range"
->           [Pseudo AnyEnum, Pseudo AnyEnum]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunName "enum_recv"
->           [Pseudo Cstring, ScalarType "oid"]
->           (Pseudo AnyEnum)
->           False,
->         CatCreateFunction FunName "enum_send" [Pseudo AnyEnum]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "enum_smaller"
->           [Pseudo AnyEnum, Pseudo AnyEnum]
->           (Pseudo AnyEnum)
->           False,
->         CatCreateFunction FunName "eqjoinsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int2", Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "eqsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "euc_cn_to_mic"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "euc_cn_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "euc_jis_2004_to_shift_jis_2004"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "euc_jis_2004_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "euc_jp_to_mic"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "euc_jp_to_sjis"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "euc_jp_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "euc_kr_to_mic"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "euc_kr_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "euc_tw_to_big5"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "euc_tw_to_mic"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "euc_tw_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "exp" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "exp" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "factorial" [ScalarType "int8"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "family" [ScalarType "inet"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "fdw_handler_in" [Pseudo Cstring]
->           (Pseudo FdwHandler)
->           False,
->         CatCreateFunction FunName "fdw_handler_out" [Pseudo FdwHandler]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "float4" [ScalarType "int8"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "float4" [ScalarType "int2"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "float4" [ScalarType "int4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "float4" [ScalarType "float8"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "float4" [ScalarType "numeric"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "float48div"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float48eq"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float48ge"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float48gt"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float48le"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float48lt"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float48mi"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float48mul"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float48ne"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float48pl"
->           [ScalarType "float4", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float4_accum"
->           [ArrayType (ScalarType "float8"), ScalarType "float4"]
->           (ArrayType (ScalarType "float8"))
->           False,
->         CatCreateFunction FunName "float4abs" [ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "float4div"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "float4eq"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float4ge"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float4gt"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float4in" [Pseudo Cstring]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "float4larger"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "float4le"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float4lt"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float4mi"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "float4mul"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "float4ne"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float4out" [ScalarType "float4"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "float4pl"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "float4recv" [Pseudo Internal]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "float4send" [ScalarType "float4"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "float4smaller"
->           [ScalarType "float4", ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "float4um" [ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "float4up" [ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "float8" [ScalarType "int8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8" [ScalarType "int2"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8" [ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8" [ScalarType "float4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8" [ScalarType "numeric"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float84div"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float84eq"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float84ge"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float84gt"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float84le"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float84lt"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float84mi"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float84mul"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float84ne"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float84pl"
->           [ScalarType "float8", ScalarType "float4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8_accum"
->           [ArrayType (ScalarType "float8"), ScalarType "float8"]
->           (ArrayType (ScalarType "float8"))
->           False,
->         CatCreateFunction FunName "float8_avg"
->           [ArrayType (ScalarType "float8")]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8_corr"
->           [ArrayType (ScalarType "float8")]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8_covar_pop"
->           [ArrayType (ScalarType "float8")]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8_covar_samp"
->           [ArrayType (ScalarType "float8")]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8_regr_accum"
->           [ArrayType (ScalarType "float8"), ScalarType "float8",
->            ScalarType "float8"]
->           (ArrayType (ScalarType "float8"))
->           False,
->         CatCreateFunction FunName "float8_regr_avgx"
->           [ArrayType (ScalarType "float8")]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8_regr_avgy"
->           [ArrayType (ScalarType "float8")]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8_regr_intercept"
->           [ArrayType (ScalarType "float8")]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8_regr_r2"
->           [ArrayType (ScalarType "float8")]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8_regr_slope"
->           [ArrayType (ScalarType "float8")]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8_regr_sxx"
->           [ArrayType (ScalarType "float8")]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8_regr_sxy"
->           [ArrayType (ScalarType "float8")]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8_regr_syy"
->           [ArrayType (ScalarType "float8")]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8_stddev_pop"
->           [ArrayType (ScalarType "float8")]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8_stddev_samp"
->           [ArrayType (ScalarType "float8")]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8_var_pop"
->           [ArrayType (ScalarType "float8")]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8_var_samp"
->           [ArrayType (ScalarType "float8")]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8abs" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8div"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8eq"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float8ge"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float8gt"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float8in" [Pseudo Cstring]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8larger"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8le"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float8lt"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float8mi"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8mul"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8ne"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "float8out" [ScalarType "float8"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "float8pl"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8recv" [Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8send" [ScalarType "float8"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "float8smaller"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8um" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "float8up" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "floor" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "floor" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "flt4_mul_cash"
->           [ScalarType "float4", ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "flt8_mul_cash"
->           [ScalarType "float8", ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "fmgr_c_validator" [ScalarType "oid"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "fmgr_internal_validator"
->           [ScalarType "oid"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "fmgr_sql_validator" [ScalarType "oid"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "format" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "format_type"
->           [ScalarType "oid", ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "gb18030_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "gbk_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "generate_series"
->           [ScalarType "int8", ScalarType "int8"]
->           (SetOfType (ScalarType "int8"))
->           False,
->         CatCreateFunction FunName "generate_series"
->           [ScalarType "int4", ScalarType "int4"]
->           (SetOfType (ScalarType "int4"))
->           False,
->         CatCreateFunction FunName "generate_series"
->           [ScalarType "int8", ScalarType "int8", ScalarType "int8"]
->           (SetOfType (ScalarType "int8"))
->           False,
->         CatCreateFunction FunName "generate_series"
->           [ScalarType "int4", ScalarType "int4", ScalarType "int4"]
->           (SetOfType (ScalarType "int4"))
->           False,
->         CatCreateFunction FunName "generate_series"
->           [ScalarType "timestamp", ScalarType "timestamp",
->            ScalarType "interval"]
->           (SetOfType (ScalarType "timestamp"))
->           False,
->         CatCreateFunction FunName "generate_series"
->           [ScalarType "timestamptz", ScalarType "timestamptz",
->            ScalarType "interval"]
->           (SetOfType (ScalarType "timestamptz"))
->           False,
->         CatCreateFunction FunName "generate_subscripts"
->           [Pseudo AnyArray, ScalarType "int4"]
->           (SetOfType (ScalarType "int4"))
->           False,
->         CatCreateFunction FunName "generate_subscripts"
->           [Pseudo AnyArray, ScalarType "int4", ScalarType "bool"]
->           (SetOfType (ScalarType "int4"))
->           False,
->         CatCreateFunction FunName "get_bit"
->           [ScalarType "bytea", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "get_bit"
->           [ScalarType "bit", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "get_byte"
->           [ScalarType "bytea", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "get_current_ts_config" []
->           (ScalarType "regconfig")
->           False,
->         CatCreateFunction FunName "getdatabaseencoding" []
->           (ScalarType "name")
->           False,
->         CatCreateFunction FunName "getpgusername" [] (ScalarType "name")
->           False,
->         CatCreateFunction FunName "gin_cmp_prefix"
->           [ScalarType "text", ScalarType "text", ScalarType "int2",
->            Pseudo Internal]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "gin_cmp_tslexeme"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "gin_extract_tsquery"
->           [ScalarType "tsquery", Pseudo Internal, ScalarType "int2",
->            Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gin_extract_tsquery"
->           [ScalarType "tsquery", Pseudo Internal, ScalarType "int2",
->            Pseudo Internal, Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gin_extract_tsvector"
->           [ScalarType "tsvector", Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gin_extract_tsvector"
->           [ScalarType "tsvector", Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gin_tsquery_consistent"
->           [Pseudo Internal, ScalarType "int2", ScalarType "tsquery",
->            ScalarType "int4", Pseudo Internal, Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "gin_tsquery_consistent"
->           [Pseudo Internal, ScalarType "int2", ScalarType "tsquery",
->            ScalarType "int4", Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "ginarrayconsistent"
->           [Pseudo Internal, ScalarType "int2", Pseudo AnyArray,
->            ScalarType "int4", Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "ginarrayextract"
->           [Pseudo AnyArray, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "ginarrayextract"
->           [Pseudo AnyArray, Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "ginbeginscan"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "ginbuild"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "ginbuildempty" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "ginbulkdelete"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gincostestimate"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "ginendscan" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "gingetbitmap"
->           [Pseudo Internal, Pseudo Internal]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "gininsert"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "ginmarkpos" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "ginoptions"
->           [ArrayType (ScalarType "text"), ScalarType "bool"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "ginqueryarrayextract"
->           [Pseudo AnyArray, Pseudo Internal, ScalarType "int2",
->            Pseudo Internal, Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "ginrescan"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "ginrestrpos" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "ginvacuumcleanup"
->           [Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gist_box_compress" [Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gist_box_consistent"
->           [Pseudo Internal, ScalarType "box", ScalarType "int4",
->            ScalarType "oid", Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "gist_box_decompress" [Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gist_box_penalty"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gist_box_picksplit"
->           [Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gist_box_same"
->           [ScalarType "box", ScalarType "box", Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gist_box_union"
->           [Pseudo Internal, Pseudo Internal]
->           (ScalarType "box")
->           False,
->         CatCreateFunction FunName "gist_circle_compress" [Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gist_circle_consistent"
->           [Pseudo Internal, ScalarType "circle", ScalarType "int4",
->            ScalarType "oid", Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "gist_point_compress" [Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gist_point_consistent"
->           [Pseudo Internal, ScalarType "point", ScalarType "int4",
->            ScalarType "oid", Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "gist_point_distance"
->           [Pseudo Internal, ScalarType "point", ScalarType "int4",
->            ScalarType "oid"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "gist_poly_compress" [Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gist_poly_consistent"
->           [Pseudo Internal, ScalarType "polygon", ScalarType "int4",
->            ScalarType "oid", Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "gistbeginscan"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gistbuild"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gistbuildempty" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "gistbulkdelete"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gistcostestimate"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "gistendscan" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "gistgetbitmap"
->           [Pseudo Internal, Pseudo Internal]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "gistgettuple"
->           [Pseudo Internal, Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "gistinsert"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "gistmarkpos" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "gistoptions"
->           [ArrayType (ScalarType "text"), ScalarType "bool"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "gistrescan"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "gistrestrpos" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "gistvacuumcleanup"
->           [Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gtsquery_compress" [Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gtsquery_consistent"
->           [Pseudo Internal, Pseudo Internal, ScalarType "int4",
->            ScalarType "oid", Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "gtsquery_decompress" [Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gtsquery_penalty"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gtsquery_picksplit"
->           [Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gtsquery_same"
->           [ScalarType "int8", ScalarType "int8", Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gtsquery_union"
->           [Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gtsvector_compress" [Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gtsvector_consistent"
->           [Pseudo Internal, ScalarType "gtsvector", ScalarType "int4",
->            ScalarType "oid", Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "gtsvector_decompress" [Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gtsvector_penalty"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gtsvector_picksplit"
->           [Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gtsvector_same"
->           [ScalarType "gtsvector", ScalarType "gtsvector", Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gtsvector_union"
->           [Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "gtsvectorin" [Pseudo Cstring]
->           (ScalarType "gtsvector")
->           False,
->         CatCreateFunction FunName "gtsvectorout" [ScalarType "gtsvector"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "has_any_column_privilege"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_any_column_privilege"
->           [ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_any_column_privilege"
->           [ScalarType "name", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_any_column_privilege"
->           [ScalarType "name", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_any_column_privilege"
->           [ScalarType "oid", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_any_column_privilege"
->           [ScalarType "oid", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_column_privilege"
->           [ScalarType "text", ScalarType "int2", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_column_privilege"
->           [ScalarType "text", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_column_privilege"
->           [ScalarType "oid", ScalarType "int2", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_column_privilege"
->           [ScalarType "oid", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_column_privilege"
->           [ScalarType "name", ScalarType "text", ScalarType "int2",
->            ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_column_privilege"
->           [ScalarType "name", ScalarType "text", ScalarType "text",
->            ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_column_privilege"
->           [ScalarType "name", ScalarType "oid", ScalarType "int2",
->            ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_column_privilege"
->           [ScalarType "name", ScalarType "oid", ScalarType "text",
->            ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_column_privilege"
->           [ScalarType "oid", ScalarType "text", ScalarType "int2",
->            ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_column_privilege"
->           [ScalarType "oid", ScalarType "text", ScalarType "text",
->            ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_column_privilege"
->           [ScalarType "oid", ScalarType "oid", ScalarType "int2",
->            ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_column_privilege"
->           [ScalarType "oid", ScalarType "oid", ScalarType "text",
->            ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_database_privilege"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_database_privilege"
->           [ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_database_privilege"
->           [ScalarType "name", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_database_privilege"
->           [ScalarType "name", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_database_privilege"
->           [ScalarType "oid", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_database_privilege"
->           [ScalarType "oid", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_foreign_data_wrapper_privilege"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_foreign_data_wrapper_privilege"
->           [ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_foreign_data_wrapper_privilege"
->           [ScalarType "name", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_foreign_data_wrapper_privilege"
->           [ScalarType "name", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_foreign_data_wrapper_privilege"
->           [ScalarType "oid", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_foreign_data_wrapper_privilege"
->           [ScalarType "oid", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_function_privilege"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_function_privilege"
->           [ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_function_privilege"
->           [ScalarType "name", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_function_privilege"
->           [ScalarType "name", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_function_privilege"
->           [ScalarType "oid", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_function_privilege"
->           [ScalarType "oid", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_language_privilege"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_language_privilege"
->           [ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_language_privilege"
->           [ScalarType "name", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_language_privilege"
->           [ScalarType "name", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_language_privilege"
->           [ScalarType "oid", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_language_privilege"
->           [ScalarType "oid", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_schema_privilege"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_schema_privilege"
->           [ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_schema_privilege"
->           [ScalarType "name", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_schema_privilege"
->           [ScalarType "name", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_schema_privilege"
->           [ScalarType "oid", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_schema_privilege"
->           [ScalarType "oid", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_sequence_privilege"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_sequence_privilege"
->           [ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_sequence_privilege"
->           [ScalarType "name", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_sequence_privilege"
->           [ScalarType "name", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_sequence_privilege"
->           [ScalarType "oid", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_sequence_privilege"
->           [ScalarType "oid", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_server_privilege"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_server_privilege"
->           [ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_server_privilege"
->           [ScalarType "name", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_server_privilege"
->           [ScalarType "name", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_server_privilege"
->           [ScalarType "oid", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_server_privilege"
->           [ScalarType "oid", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_table_privilege"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_table_privilege"
->           [ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_table_privilege"
->           [ScalarType "name", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_table_privilege"
->           [ScalarType "name", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_table_privilege"
->           [ScalarType "oid", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_table_privilege"
->           [ScalarType "oid", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_tablespace_privilege"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_tablespace_privilege"
->           [ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_tablespace_privilege"
->           [ScalarType "name", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_tablespace_privilege"
->           [ScalarType "name", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_tablespace_privilege"
->           [ScalarType "oid", ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "has_tablespace_privilege"
->           [ScalarType "oid", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "hash_aclitem" [ScalarType "aclitem"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hash_array" [Pseudo AnyArray]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hash_numeric" [ScalarType "numeric"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hashbeginscan"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "hashbpchar" [ScalarType "bpchar"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hashbuild"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "hashbuildempty" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "hashbulkdelete"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "hashchar" [ScalarType "char"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hashcostestimate"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "hashendscan" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "hashenum" [Pseudo AnyEnum]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hashfloat4" [ScalarType "float4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hashfloat8" [ScalarType "float8"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hashgetbitmap"
->           [Pseudo Internal, Pseudo Internal]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "hashgettuple"
->           [Pseudo Internal, Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "hashinet" [ScalarType "inet"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hashinsert"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "hashint2" [ScalarType "int2"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hashint2vector"
->           [ScalarType "int2vector"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hashint4" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hashint8" [ScalarType "int8"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hashmacaddr" [ScalarType "macaddr"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hashmarkpos" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "hashname" [ScalarType "name"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hashoid" [ScalarType "oid"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hashoidvector" [ScalarType "oidvector"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hashoptions"
->           [ArrayType (ScalarType "text"), ScalarType "bool"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "hashrescan"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal, Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "hashrestrpos" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "hashtext" [ScalarType "text"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "hashvacuumcleanup"
->           [Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "hashvarlena" [Pseudo Internal]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "height" [ScalarType "box"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "host" [ScalarType "inet"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "hostmask" [ScalarType "inet"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunName "iclikejoinsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int2", Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "iclikesel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "icnlikejoinsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int2", Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "icnlikesel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "icregexeqjoinsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int2", Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "icregexeqsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "icregexnejoinsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int2", Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "icregexnesel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "inet_client_addr" [] (ScalarType "inet")
->           False,
->         CatCreateFunction FunName "inet_client_port" [] (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "inet_in" [Pseudo Cstring]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunName "inet_out" [ScalarType "inet"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "inet_recv" [Pseudo Internal]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunName "inet_send" [ScalarType "inet"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "inet_server_addr" [] (ScalarType "inet")
->           False,
->         CatCreateFunction FunName "inet_server_port" [] (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "inetand"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunName "inetmi"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "inetmi_int8"
->           [ScalarType "inet", ScalarType "int8"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunName "inetnot" [ScalarType "inet"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunName "inetor"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunName "inetpl"
->           [ScalarType "inet", ScalarType "int8"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunName "initcap" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "int2" [ScalarType "int8"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2" [ScalarType "int4"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2" [ScalarType "float4"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2" [ScalarType "float8"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2" [ScalarType "numeric"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int24div"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int24eq"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int24ge"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int24gt"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int24le"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int24lt"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int24mi"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int24mul"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int24ne"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int24pl"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int28div"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int28eq"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int28ge"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int28gt"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int28le"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int28lt"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int28mi"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int28mul"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int28ne"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int28pl"
->           [ScalarType "int2", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int2_accum"
->           [ArrayType (ScalarType "numeric"), ScalarType "int2"]
->           (ArrayType (ScalarType "numeric"))
->           False,
->         CatCreateFunction FunName "int2_avg_accum"
->           [ArrayType (ScalarType "int8"), ScalarType "int2"]
->           (ArrayType (ScalarType "int8"))
->           False,
->         CatCreateFunction FunName "int2_mul_cash"
->           [ScalarType "int2", ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "int2_sum"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int2abs" [ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2and"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2div"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2eq"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int2ge"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int2gt"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int2in" [Pseudo Cstring]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2larger"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2le"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int2lt"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int2mi"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2mod"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2mul"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2ne"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int2not" [ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2or"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2out" [ScalarType "int2"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "int2pl"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2recv" [Pseudo Internal]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2send" [ScalarType "int2"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "int2shl"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2shr"
->           [ScalarType "int2", ScalarType "int4"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2smaller"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2um" [ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2up" [ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int2vectoreq"
->           [ScalarType "int2vector", ScalarType "int2vector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int2vectorin" [Pseudo Cstring]
->           (ScalarType "int2vector")
->           False,
->         CatCreateFunction FunName "int2vectorout" [ScalarType "int2vector"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "int2vectorrecv" [Pseudo Internal]
->           (ScalarType "int2vector")
->           False,
->         CatCreateFunction FunName "int2vectorsend"
->           [ScalarType "int2vector"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "int2xor"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "int4" [ScalarType "bool"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4" [ScalarType "char"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4" [ScalarType "int8"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4" [ScalarType "int2"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4" [ScalarType "float4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4" [ScalarType "float8"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4" [ScalarType "bit"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4" [ScalarType "numeric"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int42div"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int42eq"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int42ge"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int42gt"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int42le"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int42lt"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int42mi"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int42mul"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int42ne"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int42pl"
->           [ScalarType "int4", ScalarType "int2"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int48div"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int48eq"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int48ge"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int48gt"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int48le"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int48lt"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int48mi"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int48mul"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int48ne"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int48pl"
->           [ScalarType "int4", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int4_accum"
->           [ArrayType (ScalarType "numeric"), ScalarType "int4"]
->           (ArrayType (ScalarType "numeric"))
->           False,
->         CatCreateFunction FunName "int4_avg_accum"
->           [ArrayType (ScalarType "int8"), ScalarType "int4"]
->           (ArrayType (ScalarType "int8"))
->           False,
->         CatCreateFunction FunName "int4_mul_cash"
->           [ScalarType "int4", ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "int4_sum"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int4abs" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4and"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4div"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4eq"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int4ge"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int4gt"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int4in" [Pseudo Cstring]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4inc" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4larger"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4le"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int4lt"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int4mi"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4mod"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4mul"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4ne"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int4not" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4or"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4out" [ScalarType "int4"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "int4pl"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4recv" [Pseudo Internal]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4send" [ScalarType "int4"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "int4shl"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4shr"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4smaller"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4um" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4up" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int4xor"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "int8" [ScalarType "int2"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8" [ScalarType "int4"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8" [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8" [ScalarType "float4"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8" [ScalarType "float8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8" [ScalarType "bit"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8" [ScalarType "numeric"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int82div"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int82eq"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int82ge"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int82gt"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int82le"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int82lt"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int82mi"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int82mul"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int82ne"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int82pl"
->           [ScalarType "int8", ScalarType "int2"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int84div"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int84eq"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int84ge"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int84gt"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int84le"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int84lt"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int84mi"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int84mul"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int84ne"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int84pl"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8_accum"
->           [ArrayType (ScalarType "numeric"), ScalarType "int8"]
->           (ArrayType (ScalarType "numeric"))
->           False,
->         CatCreateFunction FunName "int8_avg"
->           [ArrayType (ScalarType "int8")]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "int8_avg_accum"
->           [ArrayType (ScalarType "numeric"), ScalarType "int8"]
->           (ArrayType (ScalarType "numeric"))
->           False,
->         CatCreateFunction FunName "int8_sum"
->           [ScalarType "numeric", ScalarType "int8"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "int8abs" [ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8and"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8div"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8eq"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int8ge"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int8gt"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int8in" [Pseudo Cstring]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8inc" [ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8inc_any"
->           [ScalarType "int8", Pseudo Any]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8inc_float8_float8"
->           [ScalarType "int8", ScalarType "float8", ScalarType "float8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8larger"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8le"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int8lt"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int8mi"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8mod"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8mul"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8ne"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "int8not" [ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8or"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8out" [ScalarType "int8"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "int8pl"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8pl_inet"
->           [ScalarType "int8", ScalarType "inet"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunName "int8recv" [Pseudo Internal]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8send" [ScalarType "int8"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "int8shl"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8shr"
->           [ScalarType "int8", ScalarType "int4"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8smaller"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8um" [ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8up" [ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "int8xor"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "integer_pl_date"
->           [ScalarType "int4", ScalarType "date"]
->           (ScalarType "date")
->           False,
->         CatCreateFunction FunName "inter_lb"
->           [ScalarType "line", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "inter_sb"
->           [ScalarType "lseg", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "inter_sl"
->           [ScalarType "lseg", ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "internal_in" [Pseudo Cstring]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "internal_out" [Pseudo Internal]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "interval" [ScalarType "reltime"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "interval" [ScalarType "time"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "interval"
->           [ScalarType "interval", ScalarType "int4"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "interval_accum"
->           [ArrayType (ScalarType "interval"), ScalarType "interval"]
->           (ArrayType (ScalarType "interval"))
->           False,
->         CatCreateFunction FunName "interval_avg"
->           [ArrayType (ScalarType "interval")]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "interval_cmp"
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "interval_div"
->           [ScalarType "interval", ScalarType "float8"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "interval_eq"
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "interval_ge"
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "interval_gt"
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "interval_hash" [ScalarType "interval"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "interval_in"
->           [Pseudo Cstring, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "interval_larger"
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "interval_le"
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "interval_lt"
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "interval_mi"
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "interval_mul"
->           [ScalarType "interval", ScalarType "float8"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "interval_ne"
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "interval_out" [ScalarType "interval"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "interval_pl"
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "interval_pl_date"
->           [ScalarType "interval", ScalarType "date"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "interval_pl_time"
->           [ScalarType "interval", ScalarType "time"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunName "interval_pl_timestamp"
->           [ScalarType "interval", ScalarType "timestamp"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "interval_pl_timestamptz"
->           [ScalarType "interval", ScalarType "timestamptz"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "interval_pl_timetz"
->           [ScalarType "interval", ScalarType "timetz"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunName "interval_recv"
->           [Pseudo Internal, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "interval_send" [ScalarType "interval"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "interval_smaller"
->           [ScalarType "interval", ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "interval_um" [ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "intervaltypmodin"
->           [ArrayType (Pseudo Cstring)]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "intervaltypmodout" [ScalarType "int4"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "intinterval"
->           [ScalarType "abstime", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "isclosed" [ScalarType "path"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "isfinite" [ScalarType "abstime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "isfinite" [ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "isfinite" [ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "isfinite" [ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "isfinite" [ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "ishorizontal" [ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "ishorizontal" [ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "ishorizontal"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "iso8859_1_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "iso8859_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "iso_to_koi8r"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "iso_to_mic"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "iso_to_win1251"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "iso_to_win866"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "isopen" [ScalarType "path"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "isparallel"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "isparallel"
->           [ScalarType "line", ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "isperp"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "isperp"
->           [ScalarType "line", ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "isvertical" [ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "isvertical" [ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "isvertical"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "johab_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "justify_days" [ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "justify_hours" [ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "justify_interval"
->           [ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "koi8r_to_iso"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "koi8r_to_mic"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "koi8r_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "koi8r_to_win1251"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "koi8r_to_win866"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "koi8u_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "language_handler_in" [Pseudo Cstring]
->           (Pseudo LanguageHandler)
->           False,
->         CatCreateFunction FunName "language_handler_out"
->           [Pseudo LanguageHandler]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "lastval" [] (ScalarType "int8") False,
->         CatCreateFunction FunName "latin1_to_mic"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "latin2_to_mic"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "latin2_to_win1250"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "latin3_to_mic"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "latin4_to_mic"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "left"
->           [ScalarType "text", ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "length" [ScalarType "bytea"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "length" [ScalarType "text"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "length" [ScalarType "lseg"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "length" [ScalarType "path"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "length" [ScalarType "bpchar"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "length" [ScalarType "bit"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "length" [ScalarType "tsvector"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "length"
->           [ScalarType "bytea", ScalarType "name"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "like"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "like"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "like"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "like_escape"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "like_escape"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "likejoinsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int2", Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "likesel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "line"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "line")
->           False,
->         CatCreateFunction FunName "line_distance"
->           [ScalarType "line", ScalarType "line"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "line_eq"
->           [ScalarType "line", ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "line_horizontal" [ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "line_in" [Pseudo Cstring]
->           (ScalarType "line")
->           False,
->         CatCreateFunction FunName "line_interpt"
->           [ScalarType "line", ScalarType "line"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "line_intersect"
->           [ScalarType "line", ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "line_out" [ScalarType "line"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "line_parallel"
->           [ScalarType "line", ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "line_perp"
->           [ScalarType "line", ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "line_recv" [Pseudo Internal]
->           (ScalarType "line")
->           False,
->         CatCreateFunction FunName "line_send" [ScalarType "line"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "line_vertical" [ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "ln" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "ln" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "lo_close" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "lo_creat" [ScalarType "int4"]
->           (ScalarType "oid")
->           False,
->         CatCreateFunction FunName "lo_create" [ScalarType "oid"]
->           (ScalarType "oid")
->           False,
->         CatCreateFunction FunName "lo_export"
->           [ScalarType "oid", ScalarType "text"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "lo_import" [ScalarType "text"]
->           (ScalarType "oid")
->           False,
->         CatCreateFunction FunName "lo_import"
->           [ScalarType "text", ScalarType "oid"]
->           (ScalarType "oid")
->           False,
->         CatCreateFunction FunName "lo_lseek"
->           [ScalarType "int4", ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "lo_open"
->           [ScalarType "oid", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "lo_tell" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "lo_truncate"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "lo_unlink" [ScalarType "oid"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "log" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "log" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "log"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "loread"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "lower" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "lowrite"
->           [ScalarType "int4", ScalarType "bytea"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "lpad"
->           [ScalarType "text", ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "lpad"
->           [ScalarType "text", ScalarType "int4", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "lseg" [ScalarType "box"]
->           (ScalarType "lseg")
->           False,
->         CatCreateFunction FunName "lseg"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "lseg")
->           False,
->         CatCreateFunction FunName "lseg_center" [ScalarType "lseg"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "lseg_distance"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "lseg_eq"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "lseg_ge"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "lseg_gt"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "lseg_horizontal" [ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "lseg_in" [Pseudo Cstring]
->           (ScalarType "lseg")
->           False,
->         CatCreateFunction FunName "lseg_interpt"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "lseg_intersect"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "lseg_le"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "lseg_length" [ScalarType "lseg"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "lseg_lt"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "lseg_ne"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "lseg_out" [ScalarType "lseg"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "lseg_parallel"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "lseg_perp"
->           [ScalarType "lseg", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "lseg_recv" [Pseudo Internal]
->           (ScalarType "lseg")
->           False,
->         CatCreateFunction FunName "lseg_send" [ScalarType "lseg"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "lseg_vertical" [ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "ltrim" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "ltrim"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "macaddr_cmp"
->           [ScalarType "macaddr", ScalarType "macaddr"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "macaddr_eq"
->           [ScalarType "macaddr", ScalarType "macaddr"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "macaddr_ge"
->           [ScalarType "macaddr", ScalarType "macaddr"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "macaddr_gt"
->           [ScalarType "macaddr", ScalarType "macaddr"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "macaddr_in" [Pseudo Cstring]
->           (ScalarType "macaddr")
->           False,
->         CatCreateFunction FunName "macaddr_le"
->           [ScalarType "macaddr", ScalarType "macaddr"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "macaddr_lt"
->           [ScalarType "macaddr", ScalarType "macaddr"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "macaddr_ne"
->           [ScalarType "macaddr", ScalarType "macaddr"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "macaddr_out" [ScalarType "macaddr"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "macaddr_recv" [Pseudo Internal]
->           (ScalarType "macaddr")
->           False,
->         CatCreateFunction FunName "macaddr_send" [ScalarType "macaddr"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "makeaclitem"
->           [ScalarType "oid", ScalarType "oid", ScalarType "text",
->            ScalarType "bool"]
->           (ScalarType "aclitem")
->           False,
->         CatCreateFunction FunName "masklen" [ScalarType "inet"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "md5" [ScalarType "bytea"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "md5" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "mic_to_ascii"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "mic_to_big5"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "mic_to_euc_cn"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "mic_to_euc_jp"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "mic_to_euc_kr"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "mic_to_euc_tw"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "mic_to_iso"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "mic_to_koi8r"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "mic_to_latin1"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "mic_to_latin2"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "mic_to_latin3"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "mic_to_latin4"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "mic_to_sjis"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "mic_to_win1250"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "mic_to_win1251"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "mic_to_win866"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "mktinterval"
->           [ScalarType "abstime", ScalarType "abstime"]
->           (ScalarType "tinterval")
->           False,
->         CatCreateFunction FunName "mod"
->           [ScalarType "int8", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "mod"
->           [ScalarType "int2", ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunName "mod"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "mod"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "money" [ScalarType "int8"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "money" [ScalarType "int4"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "money" [ScalarType "numeric"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunName "mul_d_interval"
->           [ScalarType "float8", ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "name" [ScalarType "text"]
->           (ScalarType "name")
->           False,
->         CatCreateFunction FunName "name" [ScalarType "bpchar"]
->           (ScalarType "name")
->           False,
->         CatCreateFunction FunName "name" [ScalarType "varchar"]
->           (ScalarType "name")
->           False,
->         CatCreateFunction FunName "nameeq"
->           [ScalarType "name", ScalarType "name"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "namege"
->           [ScalarType "name", ScalarType "name"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "namegt"
->           [ScalarType "name", ScalarType "name"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "nameiclike"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "nameicnlike"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "nameicregexeq"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "nameicregexne"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "namein" [Pseudo Cstring]
->           (ScalarType "name")
->           False,
->         CatCreateFunction FunName "namele"
->           [ScalarType "name", ScalarType "name"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "namelike"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "namelt"
->           [ScalarType "name", ScalarType "name"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "namene"
->           [ScalarType "name", ScalarType "name"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "namenlike"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "nameout" [ScalarType "name"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "namerecv" [Pseudo Internal]
->           (ScalarType "name")
->           False,
->         CatCreateFunction FunName "nameregexeq"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "nameregexne"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "namesend" [ScalarType "name"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "neqjoinsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int2", Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "neqsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "netmask" [ScalarType "inet"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunName "network" [ScalarType "inet"]
->           (ScalarType "cidr")
->           False,
->         CatCreateFunction FunName "network_cmp"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "network_eq"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "network_ge"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "network_gt"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "network_le"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "network_lt"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "network_ne"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "network_sub"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "network_subeq"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "network_sup"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "network_supeq"
->           [ScalarType "inet", ScalarType "inet"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "nextval" [ScalarType "regclass"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "nlikejoinsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int2", Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "nlikesel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "notlike"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "notlike"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "notlike"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "now" [] (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "npoints" [ScalarType "path"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "npoints" [ScalarType "polygon"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "numeric" [ScalarType "int8"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric" [ScalarType "int2"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric" [ScalarType "int4"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric" [ScalarType "float4"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric" [ScalarType "float8"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric" [ScalarType "money"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric"
->           [ScalarType "numeric", ScalarType "int4"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_abs" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_accum"
->           [ArrayType (ScalarType "numeric"), ScalarType "numeric"]
->           (ArrayType (ScalarType "numeric"))
->           False,
->         CatCreateFunction FunName "numeric_add"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_avg"
->           [ArrayType (ScalarType "numeric")]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_avg_accum"
->           [ArrayType (ScalarType "numeric"), ScalarType "numeric"]
->           (ArrayType (ScalarType "numeric"))
->           False,
->         CatCreateFunction FunName "numeric_cmp"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "numeric_div"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_div_trunc"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_eq"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "numeric_exp" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_fac" [ScalarType "int8"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_ge"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "numeric_gt"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "numeric_in"
->           [Pseudo Cstring, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_inc" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_larger"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_le"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "numeric_ln" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_log"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_lt"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "numeric_mod"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_mul"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_ne"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "numeric_out" [ScalarType "numeric"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "numeric_power"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_recv"
->           [Pseudo Internal, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_send" [ScalarType "numeric"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "numeric_smaller"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_sqrt" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_stddev_pop"
->           [ArrayType (ScalarType "numeric")]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_stddev_samp"
->           [ArrayType (ScalarType "numeric")]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_sub"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_uminus" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_uplus" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_var_pop"
->           [ArrayType (ScalarType "numeric")]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numeric_var_samp"
->           [ArrayType (ScalarType "numeric")]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "numerictypmodin"
->           [ArrayType (Pseudo Cstring)]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "numerictypmodout" [ScalarType "int4"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "numnode" [ScalarType "tsquery"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "obj_description" [ScalarType "oid"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "obj_description"
->           [ScalarType "oid", ScalarType "name"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "octet_length" [ScalarType "bytea"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "octet_length" [ScalarType "text"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "octet_length" [ScalarType "bpchar"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "octet_length" [ScalarType "bit"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "oid" [ScalarType "int8"]
->           (ScalarType "oid")
->           False,
->         CatCreateFunction FunName "oideq"
->           [ScalarType "oid", ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "oidge"
->           [ScalarType "oid", ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "oidgt"
->           [ScalarType "oid", ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "oidin" [Pseudo Cstring]
->           (ScalarType "oid")
->           False,
->         CatCreateFunction FunName "oidlarger"
->           [ScalarType "oid", ScalarType "oid"]
->           (ScalarType "oid")
->           False,
->         CatCreateFunction FunName "oidle"
->           [ScalarType "oid", ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "oidlt"
->           [ScalarType "oid", ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "oidne"
->           [ScalarType "oid", ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "oidout" [ScalarType "oid"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "oidrecv" [Pseudo Internal]
->           (ScalarType "oid")
->           False,
->         CatCreateFunction FunName "oidsend" [ScalarType "oid"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "oidsmaller"
->           [ScalarType "oid", ScalarType "oid"]
->           (ScalarType "oid")
->           False,
->         CatCreateFunction FunName "oidvectoreq"
->           [ScalarType "oidvector", ScalarType "oidvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "oidvectorge"
->           [ScalarType "oidvector", ScalarType "oidvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "oidvectorgt"
->           [ScalarType "oidvector", ScalarType "oidvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "oidvectorin" [Pseudo Cstring]
->           (ScalarType "oidvector")
->           False,
->         CatCreateFunction FunName "oidvectorle"
->           [ScalarType "oidvector", ScalarType "oidvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "oidvectorlt"
->           [ScalarType "oidvector", ScalarType "oidvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "oidvectorne"
->           [ScalarType "oidvector", ScalarType "oidvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "oidvectorout" [ScalarType "oidvector"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "oidvectorrecv" [Pseudo Internal]
->           (ScalarType "oidvector")
->           False,
->         CatCreateFunction FunName "oidvectorsend" [ScalarType "oidvector"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "oidvectortypes" [ScalarType "oidvector"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "on_pb"
->           [ScalarType "point", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "on_pl"
->           [ScalarType "point", ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "on_ppath"
->           [ScalarType "point", ScalarType "path"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "on_ps"
->           [ScalarType "point", ScalarType "lseg"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "on_sb"
->           [ScalarType "lseg", ScalarType "box"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "on_sl"
->           [ScalarType "lseg", ScalarType "line"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "opaque_in" [Pseudo Cstring]
->           (Pseudo Opaque)
->           False,
->         CatCreateFunction FunName "opaque_out" [Pseudo Opaque]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "overlaps"
->           [ScalarType "time", ScalarType "time", ScalarType "time",
->            ScalarType "time"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "overlaps"
->           [ScalarType "time", ScalarType "time", ScalarType "time",
->            ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "overlaps"
->           [ScalarType "time", ScalarType "interval", ScalarType "time",
->            ScalarType "time"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "overlaps"
->           [ScalarType "time", ScalarType "interval", ScalarType "time",
->            ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "overlaps"
->           [ScalarType "timestamp", ScalarType "timestamp",
->            ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "overlaps"
->           [ScalarType "timestamp", ScalarType "timestamp",
->            ScalarType "timestamp", ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "overlaps"
->           [ScalarType "timestamp", ScalarType "interval",
->            ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "overlaps"
->           [ScalarType "timestamp", ScalarType "interval",
->            ScalarType "timestamp", ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "overlaps"
->           [ScalarType "timestamptz", ScalarType "timestamptz",
->            ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "overlaps"
->           [ScalarType "timestamptz", ScalarType "timestamptz",
->            ScalarType "timestamptz", ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "overlaps"
->           [ScalarType "timestamptz", ScalarType "interval",
->            ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "overlaps"
->           [ScalarType "timestamptz", ScalarType "interval",
->            ScalarType "timestamptz", ScalarType "interval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "overlaps"
->           [ScalarType "timetz", ScalarType "timetz", ScalarType "timetz",
->            ScalarType "timetz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "overlay"
->           [ScalarType "bytea", ScalarType "bytea", ScalarType "int4"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "overlay"
->           [ScalarType "text", ScalarType "text", ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "overlay"
->           [ScalarType "bit", ScalarType "bit", ScalarType "int4"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunName "overlay"
->           [ScalarType "bytea", ScalarType "bytea", ScalarType "int4",
->            ScalarType "int4"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "overlay"
->           [ScalarType "text", ScalarType "text", ScalarType "int4",
->            ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "overlay"
->           [ScalarType "bit", ScalarType "bit", ScalarType "int4",
->            ScalarType "int4"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunName "path" [ScalarType "polygon"]
->           (ScalarType "path")
->           False,
->         CatCreateFunction FunName "path_add"
->           [ScalarType "path", ScalarType "path"]
->           (ScalarType "path")
->           False,
->         CatCreateFunction FunName "path_add_pt"
->           [ScalarType "path", ScalarType "point"]
->           (ScalarType "path")
->           False,
->         CatCreateFunction FunName "path_center" [ScalarType "path"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "path_contain_pt"
->           [ScalarType "path", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "path_distance"
->           [ScalarType "path", ScalarType "path"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "path_div_pt"
->           [ScalarType "path", ScalarType "point"]
->           (ScalarType "path")
->           False,
->         CatCreateFunction FunName "path_in" [Pseudo Cstring]
->           (ScalarType "path")
->           False,
->         CatCreateFunction FunName "path_inter"
->           [ScalarType "path", ScalarType "path"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "path_length" [ScalarType "path"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "path_mul_pt"
->           [ScalarType "path", ScalarType "point"]
->           (ScalarType "path")
->           False,
->         CatCreateFunction FunName "path_n_eq"
->           [ScalarType "path", ScalarType "path"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "path_n_ge"
->           [ScalarType "path", ScalarType "path"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "path_n_gt"
->           [ScalarType "path", ScalarType "path"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "path_n_le"
->           [ScalarType "path", ScalarType "path"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "path_n_lt"
->           [ScalarType "path", ScalarType "path"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "path_npoints" [ScalarType "path"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "path_out" [ScalarType "path"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "path_recv" [Pseudo Internal]
->           (ScalarType "path")
->           False,
->         CatCreateFunction FunName "path_send" [ScalarType "path"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "path_sub_pt"
->           [ScalarType "path", ScalarType "point"]
->           (ScalarType "path")
->           False,
->         CatCreateFunction FunName "pclose" [ScalarType "path"]
->           (ScalarType "path")
->           False,
->         CatCreateFunction FunName "pg_advisory_lock" [ScalarType "int8"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_advisory_lock"
->           [ScalarType "int4", ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_advisory_lock_shared"
->           [ScalarType "int8"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_advisory_lock_shared"
->           [ScalarType "int4", ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_advisory_unlock" [ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_advisory_unlock"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_advisory_unlock_all" [] (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_advisory_unlock_shared"
->           [ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_advisory_unlock_shared"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_advisory_xact_lock"
->           [ScalarType "int8"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_advisory_xact_lock"
->           [ScalarType "int4", ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_advisory_xact_lock_shared"
->           [ScalarType "int8"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_advisory_xact_lock_shared"
->           [ScalarType "int4", ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_available_extension_versions" []
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "pg_available_extensions" []
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "pg_backend_pid" [] (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "pg_cancel_backend" [ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_char_to_encoding" [ScalarType "name"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "pg_client_encoding" []
->           (ScalarType "name")
->           False,
->         CatCreateFunction FunName "pg_collation_is_visible"
->           [ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_column_size" [Pseudo Any]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "pg_conf_load_time" []
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "pg_conversion_is_visible"
->           [ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_create_restore_point"
->           [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_current_xlog_insert_location" []
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_current_xlog_location" []
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_cursor" []
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "pg_database_size" [ScalarType "name"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_database_size" [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_describe_object"
->           [ScalarType "oid", ScalarType "oid", ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_encoding_max_length"
->           [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "pg_encoding_to_char" [ScalarType "int4"]
->           (ScalarType "name")
->           False,
->         CatCreateFunction FunName "pg_extension_config_dump"
->           [ScalarType "regclass", ScalarType "text"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_extension_update_paths"
->           [ScalarType "name"]
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "pg_function_is_visible"
->           [ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_get_constraintdef" [ScalarType "oid"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_constraintdef"
->           [ScalarType "oid", ScalarType "bool"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_expr"
->           [ScalarType "pg_node_tree", ScalarType "oid"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_expr"
->           [ScalarType "pg_node_tree", ScalarType "oid", ScalarType "bool"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_function_arguments"
->           [ScalarType "oid"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_function_identity_arguments"
->           [ScalarType "oid"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_function_result"
->           [ScalarType "oid"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_functiondef" [ScalarType "oid"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_indexdef" [ScalarType "oid"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_indexdef"
->           [ScalarType "oid", ScalarType "int4", ScalarType "bool"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_keywords" []
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "pg_get_ruledef" [ScalarType "oid"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_ruledef"
->           [ScalarType "oid", ScalarType "bool"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_serial_sequence"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_triggerdef" [ScalarType "oid"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_triggerdef"
->           [ScalarType "oid", ScalarType "bool"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_userbyid" [ScalarType "oid"]
->           (ScalarType "name")
->           False,
->         CatCreateFunction FunName "pg_get_viewdef" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_viewdef" [ScalarType "oid"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_viewdef"
->           [ScalarType "text", ScalarType "bool"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_get_viewdef"
->           [ScalarType "oid", ScalarType "bool"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_has_role"
->           [ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_has_role"
->           [ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_has_role"
->           [ScalarType "name", ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_has_role"
->           [ScalarType "name", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_has_role"
->           [ScalarType "oid", ScalarType "name", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_has_role"
->           [ScalarType "oid", ScalarType "oid", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_indexes_size" [ScalarType "regclass"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_is_in_recovery" []
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_is_other_temp_schema"
->           [ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_is_xlog_replay_paused" []
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_last_xact_replay_timestamp" []
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "pg_last_xlog_receive_location" []
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_last_xlog_replay_location" []
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_listening_channels" []
->           (SetOfType (ScalarType "text"))
->           False,
->         CatCreateFunction FunName "pg_lock_status" []
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "pg_ls_dir" [ScalarType "text"]
->           (SetOfType (ScalarType "text"))
->           False,
->         CatCreateFunction FunName "pg_my_temp_schema" [] (ScalarType "oid")
->           False,
->         CatCreateFunction FunName "pg_node_tree_in" [Pseudo Cstring]
->           (ScalarType "pg_node_tree")
->           False,
->         CatCreateFunction FunName "pg_node_tree_out"
->           [ScalarType "pg_node_tree"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "pg_node_tree_recv" [Pseudo Internal]
->           (ScalarType "pg_node_tree")
->           False,
->         CatCreateFunction FunName "pg_node_tree_send"
->           [ScalarType "pg_node_tree"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "pg_notify"
->           [ScalarType "text", ScalarType "text"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_opclass_is_visible"
->           [ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_operator_is_visible"
->           [ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_options_to_table"
->           [ArrayType (ScalarType "text")]
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "pg_postmaster_start_time" []
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "pg_prepared_statement" []
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "pg_prepared_xact" []
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "pg_read_binary_file" [ScalarType "text"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "pg_read_binary_file"
->           [ScalarType "text", ScalarType "int8", ScalarType "int8"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "pg_read_file" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_read_file"
->           [ScalarType "text", ScalarType "int8", ScalarType "int8"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_relation_filenode"
->           [ScalarType "regclass"]
->           (ScalarType "oid")
->           False,
->         CatCreateFunction FunName "pg_relation_filepath"
->           [ScalarType "regclass"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_relation_size"
->           [ScalarType "regclass"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_relation_size"
->           [ScalarType "regclass", ScalarType "text"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_reload_conf" [] (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_rotate_logfile" []
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_sequence_parameters"
->           [ScalarType "oid"]
->           (Pseudo Record)
->           False,
->         CatCreateFunction FunName "pg_show_all_settings" []
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "pg_size_pretty" [ScalarType "int8"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_sleep" [ScalarType "float8"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_start_backup"
->           [ScalarType "text", ScalarType "bool"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_stat_clear_snapshot" [] (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_stat_file" [ScalarType "text"]
->           (Pseudo Record)
->           False,
->         CatCreateFunction FunName "pg_stat_get_activity"
->           [ScalarType "int4"]
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "pg_stat_get_analyze_count"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_autoanalyze_count"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_autovacuum_count"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_backend_activity"
->           [ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_stat_get_backend_activity_start"
->           [ScalarType "int4"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "pg_stat_get_backend_client_addr"
->           [ScalarType "int4"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunName "pg_stat_get_backend_client_port"
->           [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "pg_stat_get_backend_dbid"
->           [ScalarType "int4"]
->           (ScalarType "oid")
->           False,
->         CatCreateFunction FunName "pg_stat_get_backend_idset" []
->           (SetOfType (ScalarType "int4"))
->           False,
->         CatCreateFunction FunName "pg_stat_get_backend_pid"
->           [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "pg_stat_get_backend_start"
->           [ScalarType "int4"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "pg_stat_get_backend_userid"
->           [ScalarType "int4"]
->           (ScalarType "oid")
->           False,
->         CatCreateFunction FunName "pg_stat_get_backend_waiting"
->           [ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_stat_get_backend_xact_start"
->           [ScalarType "int4"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName
->           "pg_stat_get_bgwriter_buf_written_checkpoints"
->           []
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_bgwriter_buf_written_clean"
->           []
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_bgwriter_maxwritten_clean"
->           []
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName
->           "pg_stat_get_bgwriter_requested_checkpoints"
->           []
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_bgwriter_stat_reset_time" []
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "pg_stat_get_bgwriter_timed_checkpoints"
->           []
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_blocks_fetched"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_blocks_hit"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_buf_alloc" []
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_buf_fsync_backend" []
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_buf_written_backend" []
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_db_blocks_fetched"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_db_blocks_hit"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_db_conflict_all"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_db_conflict_bufferpin"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_db_conflict_lock"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_db_conflict_snapshot"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName
->           "pg_stat_get_db_conflict_startup_deadlock"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_db_conflict_tablespace"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_db_numbackends"
->           [ScalarType "oid"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "pg_stat_get_db_stat_reset_time"
->           [ScalarType "oid"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "pg_stat_get_db_tuples_deleted"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_db_tuples_fetched"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_db_tuples_inserted"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_db_tuples_returned"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_db_tuples_updated"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_db_xact_commit"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_db_xact_rollback"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_dead_tuples"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_function_calls"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_function_self_time"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_function_time"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_last_analyze_time"
->           [ScalarType "oid"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "pg_stat_get_last_autoanalyze_time"
->           [ScalarType "oid"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "pg_stat_get_last_autovacuum_time"
->           [ScalarType "oid"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "pg_stat_get_last_vacuum_time"
->           [ScalarType "oid"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "pg_stat_get_live_tuples"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_numscans" [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_tuples_deleted"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_tuples_fetched"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_tuples_hot_updated"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_tuples_inserted"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_tuples_returned"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_tuples_updated"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_vacuum_count"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_wal_senders" []
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "pg_stat_get_xact_blocks_fetched"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_xact_blocks_hit"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_xact_function_calls"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_xact_function_self_time"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_xact_function_time"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_xact_numscans"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_xact_tuples_deleted"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_xact_tuples_fetched"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_xact_tuples_hot_updated"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_xact_tuples_inserted"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_xact_tuples_returned"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_get_xact_tuples_updated"
->           [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_stat_reset" [] (Pseudo Void) False,
->         CatCreateFunction FunName "pg_stat_reset_shared"
->           [ScalarType "text"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_stat_reset_single_function_counters"
->           [ScalarType "oid"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_stat_reset_single_table_counters"
->           [ScalarType "oid"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_stop_backup" [] (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_switch_xlog" [] (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_table_is_visible" [ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_table_size" [ScalarType "regclass"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_tablespace_databases"
->           [ScalarType "oid"]
->           (SetOfType (ScalarType "oid"))
->           False,
->         CatCreateFunction FunName "pg_tablespace_size" [ScalarType "name"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_tablespace_size" [ScalarType "oid"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_terminate_backend"
->           [ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_timezone_abbrevs" []
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "pg_timezone_names" []
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "pg_total_relation_size"
->           [ScalarType "regclass"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "pg_try_advisory_lock"
->           [ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_try_advisory_lock"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_try_advisory_lock_shared"
->           [ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_try_advisory_lock_shared"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_try_advisory_xact_lock"
->           [ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_try_advisory_xact_lock"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_try_advisory_xact_lock_shared"
->           [ScalarType "int8"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_try_advisory_xact_lock_shared"
->           [ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_ts_config_is_visible"
->           [ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_ts_dict_is_visible"
->           [ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_ts_parser_is_visible"
->           [ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_ts_template_is_visible"
->           [ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_type_is_visible" [ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pg_typeof" [Pseudo Any]
->           (ScalarType "regtype")
->           False,
->         CatCreateFunction FunName "pg_xlog_replay_pause" [] (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_xlog_replay_resume" [] (Pseudo Void)
->           False,
->         CatCreateFunction FunName "pg_xlogfile_name" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "pg_xlogfile_name_offset"
->           [ScalarType "text"]
->           (Pseudo Record)
->           False,
->         CatCreateFunction FunName "pi" [] (ScalarType "float8") False,
->         CatCreateFunction FunName "plainto_tsquery" [ScalarType "text"]
->           (ScalarType "tsquery")
->           False,
->         CatCreateFunction FunName "plainto_tsquery"
->           [ScalarType "regconfig", ScalarType "text"]
->           (ScalarType "tsquery")
->           False,
->         CatCreateFunction FunName "plpgsql_call_handler" []
->           (Pseudo LanguageHandler)
->           False,
->         CatCreateFunction FunName "plpgsql_inline_handler"
->           [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "plpgsql_validator" [ScalarType "oid"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "point" [ScalarType "lseg"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "point" [ScalarType "path"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "point" [ScalarType "box"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "point" [ScalarType "polygon"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "point" [ScalarType "circle"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "point"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "point_above"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "point_add"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "point_below"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "point_distance"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "point_div"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "point_eq"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "point_horiz"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "point_in" [Pseudo Cstring]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "point_left"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "point_mul"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "point_ne"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "point_out" [ScalarType "point"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "point_recv" [Pseudo Internal]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "point_right"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "point_send" [ScalarType "point"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "point_sub"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "point_vert"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "poly_above"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "poly_below"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "poly_center" [ScalarType "polygon"]
->           (ScalarType "point")
->           False,
->         CatCreateFunction FunName "poly_contain"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "poly_contain_pt"
->           [ScalarType "polygon", ScalarType "point"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "poly_contained"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "poly_distance"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "poly_in" [Pseudo Cstring]
->           (ScalarType "polygon")
->           False,
->         CatCreateFunction FunName "poly_left"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "poly_npoints" [ScalarType "polygon"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "poly_out" [ScalarType "polygon"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "poly_overabove"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "poly_overbelow"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "poly_overlap"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "poly_overleft"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "poly_overright"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "poly_recv" [Pseudo Internal]
->           (ScalarType "polygon")
->           False,
->         CatCreateFunction FunName "poly_right"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "poly_same"
->           [ScalarType "polygon", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "poly_send" [ScalarType "polygon"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "polygon" [ScalarType "path"]
->           (ScalarType "polygon")
->           False,
->         CatCreateFunction FunName "polygon" [ScalarType "box"]
->           (ScalarType "polygon")
->           False,
->         CatCreateFunction FunName "polygon" [ScalarType "circle"]
->           (ScalarType "polygon")
->           False,
->         CatCreateFunction FunName "polygon"
->           [ScalarType "int4", ScalarType "circle"]
->           (ScalarType "polygon")
->           False,
->         CatCreateFunction FunName "popen" [ScalarType "path"]
->           (ScalarType "path")
->           False,
->         CatCreateFunction FunName "position"
->           [ScalarType "bytea", ScalarType "bytea"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "position"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "position"
->           [ScalarType "bit", ScalarType "bit"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "positionjoinsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int2", Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "positionsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "postgresql_fdw_validator"
->           [ArrayType (ScalarType "text"), ScalarType "oid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pow"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "pow"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "power"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "power"
->           [ScalarType "numeric", ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "prsd_end" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "prsd_headline"
->           [Pseudo Internal, Pseudo Internal, ScalarType "tsquery"]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "prsd_lextype" [Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "prsd_nexttoken"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "prsd_start"
->           [Pseudo Internal, ScalarType "int4"]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "pt_contained_circle"
->           [ScalarType "point", ScalarType "circle"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "pt_contained_poly"
->           [ScalarType "point", ScalarType "polygon"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "query_to_xml"
->           [ScalarType "text", ScalarType "bool", ScalarType "bool",
->            ScalarType "text"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "query_to_xml_and_xmlschema"
->           [ScalarType "text", ScalarType "bool", ScalarType "bool",
->            ScalarType "text"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "query_to_xmlschema"
->           [ScalarType "text", ScalarType "bool", ScalarType "bool",
->            ScalarType "text"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "querytree" [ScalarType "tsquery"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "quote_ident" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "quote_literal" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "quote_literal" [Pseudo AnyElement]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "quote_nullable" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "quote_nullable" [Pseudo AnyElement]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "radians" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "radius" [ScalarType "circle"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "random" [] (ScalarType "float8") False,
->         CatCreateFunction FunName "record_eq"
->           [Pseudo Record, Pseudo Record]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "record_ge"
->           [Pseudo Record, Pseudo Record]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "record_gt"
->           [Pseudo Record, Pseudo Record]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "record_in"
->           [Pseudo Cstring, ScalarType "oid", ScalarType "int4"]
->           (Pseudo Record)
->           False,
->         CatCreateFunction FunName "record_le"
->           [Pseudo Record, Pseudo Record]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "record_lt"
->           [Pseudo Record, Pseudo Record]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "record_ne"
->           [Pseudo Record, Pseudo Record]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "record_out" [Pseudo Record]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "record_recv"
->           [Pseudo Internal, ScalarType "oid", ScalarType "int4"]
->           (Pseudo Record)
->           False,
->         CatCreateFunction FunName "record_send" [Pseudo Record]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "regclass" [ScalarType "text"]
->           (ScalarType "regclass")
->           False,
->         CatCreateFunction FunName "regclassin" [Pseudo Cstring]
->           (ScalarType "regclass")
->           False,
->         CatCreateFunction FunName "regclassout" [ScalarType "regclass"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "regclassrecv" [Pseudo Internal]
->           (ScalarType "regclass")
->           False,
->         CatCreateFunction FunName "regclasssend" [ScalarType "regclass"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "regconfigin" [Pseudo Cstring]
->           (ScalarType "regconfig")
->           False,
->         CatCreateFunction FunName "regconfigout" [ScalarType "regconfig"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "regconfigrecv" [Pseudo Internal]
->           (ScalarType "regconfig")
->           False,
->         CatCreateFunction FunName "regconfigsend" [ScalarType "regconfig"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "regdictionaryin" [Pseudo Cstring]
->           (ScalarType "regdictionary")
->           False,
->         CatCreateFunction FunName "regdictionaryout"
->           [ScalarType "regdictionary"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "regdictionaryrecv" [Pseudo Internal]
->           (ScalarType "regdictionary")
->           False,
->         CatCreateFunction FunName "regdictionarysend"
->           [ScalarType "regdictionary"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "regexeqjoinsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int2", Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "regexeqsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "regexnejoinsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int2", Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "regexnesel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "regexp_matches"
->           [ScalarType "text", ScalarType "text"]
->           (SetOfType (ArrayType (ScalarType "text")))
->           False,
->         CatCreateFunction FunName "regexp_matches"
->           [ScalarType "text", ScalarType "text", ScalarType "text"]
->           (SetOfType (ArrayType (ScalarType "text")))
->           False,
->         CatCreateFunction FunName "regexp_replace"
->           [ScalarType "text", ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "regexp_replace"
->           [ScalarType "text", ScalarType "text", ScalarType "text",
->            ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "regexp_split_to_array"
->           [ScalarType "text", ScalarType "text"]
->           (ArrayType (ScalarType "text"))
->           False,
->         CatCreateFunction FunName "regexp_split_to_array"
->           [ScalarType "text", ScalarType "text", ScalarType "text"]
->           (ArrayType (ScalarType "text"))
->           False,
->         CatCreateFunction FunName "regexp_split_to_table"
->           [ScalarType "text", ScalarType "text"]
->           (SetOfType (ScalarType "text"))
->           False,
->         CatCreateFunction FunName "regexp_split_to_table"
->           [ScalarType "text", ScalarType "text", ScalarType "text"]
->           (SetOfType (ScalarType "text"))
->           False,
->         CatCreateFunction FunName "regoperatorin" [Pseudo Cstring]
->           (ScalarType "regoperator")
->           False,
->         CatCreateFunction FunName "regoperatorout"
->           [ScalarType "regoperator"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "regoperatorrecv" [Pseudo Internal]
->           (ScalarType "regoperator")
->           False,
->         CatCreateFunction FunName "regoperatorsend"
->           [ScalarType "regoperator"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "regoperin" [Pseudo Cstring]
->           (ScalarType "regoper")
->           False,
->         CatCreateFunction FunName "regoperout" [ScalarType "regoper"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "regoperrecv" [Pseudo Internal]
->           (ScalarType "regoper")
->           False,
->         CatCreateFunction FunName "regopersend" [ScalarType "regoper"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "regprocedurein" [Pseudo Cstring]
->           (ScalarType "regprocedure")
->           False,
->         CatCreateFunction FunName "regprocedureout"
->           [ScalarType "regprocedure"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "regprocedurerecv" [Pseudo Internal]
->           (ScalarType "regprocedure")
->           False,
->         CatCreateFunction FunName "regproceduresend"
->           [ScalarType "regprocedure"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "regprocin" [Pseudo Cstring]
->           (ScalarType "regproc")
->           False,
->         CatCreateFunction FunName "regprocout" [ScalarType "regproc"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "regprocrecv" [Pseudo Internal]
->           (ScalarType "regproc")
->           False,
->         CatCreateFunction FunName "regprocsend" [ScalarType "regproc"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "regtypein" [Pseudo Cstring]
->           (ScalarType "regtype")
->           False,
->         CatCreateFunction FunName "regtypeout" [ScalarType "regtype"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "regtyperecv" [Pseudo Internal]
->           (ScalarType "regtype")
->           False,
->         CatCreateFunction FunName "regtypesend" [ScalarType "regtype"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "reltime" [ScalarType "interval"]
->           (ScalarType "reltime")
->           False,
->         CatCreateFunction FunName "reltimeeq"
->           [ScalarType "reltime", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "reltimege"
->           [ScalarType "reltime", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "reltimegt"
->           [ScalarType "reltime", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "reltimein" [Pseudo Cstring]
->           (ScalarType "reltime")
->           False,
->         CatCreateFunction FunName "reltimele"
->           [ScalarType "reltime", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "reltimelt"
->           [ScalarType "reltime", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "reltimene"
->           [ScalarType "reltime", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "reltimeout" [ScalarType "reltime"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "reltimerecv" [Pseudo Internal]
->           (ScalarType "reltime")
->           False,
->         CatCreateFunction FunName "reltimesend" [ScalarType "reltime"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "repeat"
->           [ScalarType "text", ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "replace"
->           [ScalarType "text", ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "reverse" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "right"
->           [ScalarType "text", ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "round" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "round" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "round"
->           [ScalarType "numeric", ScalarType "int4"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "rpad"
->           [ScalarType "text", ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "rpad"
->           [ScalarType "text", ScalarType "int4", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "rtrim" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "rtrim"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "scalargtjoinsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int2", Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "scalargtsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "scalarltjoinsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int2", Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "scalarltsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "schema_to_xml"
->           [ScalarType "name", ScalarType "bool", ScalarType "bool",
->            ScalarType "text"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "schema_to_xml_and_xmlschema"
->           [ScalarType "name", ScalarType "bool", ScalarType "bool",
->            ScalarType "text"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "schema_to_xmlschema"
->           [ScalarType "name", ScalarType "bool", ScalarType "bool",
->            ScalarType "text"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "session_user" [] (ScalarType "name")
->           False,
->         CatCreateFunction FunName "set_bit"
->           [ScalarType "bytea", ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "set_bit"
->           [ScalarType "bit", ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunName "set_byte"
->           [ScalarType "bytea", ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "set_config"
->           [ScalarType "text", ScalarType "text", ScalarType "bool"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "set_masklen"
->           [ScalarType "cidr", ScalarType "int4"]
->           (ScalarType "cidr")
->           False,
->         CatCreateFunction FunName "set_masklen"
->           [ScalarType "inet", ScalarType "int4"]
->           (ScalarType "inet")
->           False,
->         CatCreateFunction FunName "setseed" [ScalarType "float8"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "setval"
->           [ScalarType "regclass", ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "setval"
->           [ScalarType "regclass", ScalarType "int8", ScalarType "bool"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "setweight"
->           [ScalarType "tsvector", ScalarType "char"]
->           (ScalarType "tsvector")
->           False,
->         CatCreateFunction FunName "shell_in" [Pseudo Cstring]
->           (Pseudo Opaque)
->           False,
->         CatCreateFunction FunName "shell_out" [Pseudo Opaque]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "shift_jis_2004_to_euc_jis_2004"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "shift_jis_2004_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "shobj_description"
->           [ScalarType "oid", ScalarType "name"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "sign" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "sign" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "similar_escape"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "sin" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "sjis_to_euc_jp"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "sjis_to_mic"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "sjis_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "slope"
->           [ScalarType "point", ScalarType "point"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "smgreq"
->           [ScalarType "smgr", ScalarType "smgr"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "smgrin" [Pseudo Cstring]
->           (ScalarType "smgr")
->           False,
->         CatCreateFunction FunName "smgrne"
->           [ScalarType "smgr", ScalarType "smgr"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "smgrout" [ScalarType "smgr"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "split_part"
->           [ScalarType "text", ScalarType "text", ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "sqrt" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "sqrt" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "statement_timestamp" []
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "string_agg_finalfn" [Pseudo Internal]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "string_agg_transfn"
->           [Pseudo Internal, ScalarType "text", ScalarType "text"]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "string_to_array"
->           [ScalarType "text", ScalarType "text"]
->           (ArrayType (ScalarType "text"))
->           False,
->         CatCreateFunction FunName "string_to_array"
->           [ScalarType "text", ScalarType "text", ScalarType "text"]
->           (ArrayType (ScalarType "text"))
->           False,
->         CatCreateFunction FunName "strip" [ScalarType "tsvector"]
->           (ScalarType "tsvector")
->           False,
->         CatCreateFunction FunName "strpos"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "substr"
->           [ScalarType "bytea", ScalarType "int4"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "substr"
->           [ScalarType "text", ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "substr"
->           [ScalarType "bytea", ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "substr"
->           [ScalarType "text", ScalarType "int4", ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "substring"
->           [ScalarType "bytea", ScalarType "int4"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "substring"
->           [ScalarType "text", ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "substring"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "substring"
->           [ScalarType "bit", ScalarType "int4"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunName "substring"
->           [ScalarType "bytea", ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "substring"
->           [ScalarType "text", ScalarType "int4", ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "substring"
->           [ScalarType "text", ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "substring"
->           [ScalarType "bit", ScalarType "int4", ScalarType "int4"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunName "suppress_redundant_updates_trigger" []
->           (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "table_to_xml"
->           [ScalarType "regclass", ScalarType "bool", ScalarType "bool",
->            ScalarType "text"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "table_to_xml_and_xmlschema"
->           [ScalarType "regclass", ScalarType "bool", ScalarType "bool",
->            ScalarType "text"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "table_to_xmlschema"
->           [ScalarType "regclass", ScalarType "bool", ScalarType "bool",
->            ScalarType "text"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "tan" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "text" [ScalarType "bool"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "text" [ScalarType "char"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "text" [ScalarType "name"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "text" [ScalarType "xml"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "text" [ScalarType "inet"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "text" [ScalarType "bpchar"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "text_ge"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "text_gt"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "text_larger"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "text_le"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "text_lt"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "text_pattern_ge"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "text_pattern_gt"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "text_pattern_le"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "text_pattern_lt"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "text_smaller"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "textanycat"
->           [ScalarType "text", Pseudo AnyNonArray]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "textcat"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "texteq"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "texticlike"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "texticnlike"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "texticregexeq"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "texticregexne"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "textin" [Pseudo Cstring]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "textlen" [ScalarType "text"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "textlike"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "textne"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "textnlike"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "textout" [ScalarType "text"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "textrecv" [Pseudo Internal]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "textregexeq"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "textregexne"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "textsend" [ScalarType "text"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "thesaurus_init" [Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "thesaurus_lexize"
->           [Pseudo Internal, Pseudo Internal, Pseudo Internal,
->            Pseudo Internal]
->           (Pseudo Internal)
->           False,
->         CatCreateFunction FunName "tideq"
->           [ScalarType "tid", ScalarType "tid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tidge"
->           [ScalarType "tid", ScalarType "tid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tidgt"
->           [ScalarType "tid", ScalarType "tid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tidin" [Pseudo Cstring]
->           (ScalarType "tid")
->           False,
->         CatCreateFunction FunName "tidlarger"
->           [ScalarType "tid", ScalarType "tid"]
->           (ScalarType "tid")
->           False,
->         CatCreateFunction FunName "tidle"
->           [ScalarType "tid", ScalarType "tid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tidlt"
->           [ScalarType "tid", ScalarType "tid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tidne"
->           [ScalarType "tid", ScalarType "tid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tidout" [ScalarType "tid"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "tidrecv" [Pseudo Internal]
->           (ScalarType "tid")
->           False,
->         CatCreateFunction FunName "tidsend" [ScalarType "tid"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "tidsmaller"
->           [ScalarType "tid", ScalarType "tid"]
->           (ScalarType "tid")
->           False,
->         CatCreateFunction FunName "time" [ScalarType "abstime"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunName "time" [ScalarType "timestamp"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunName "time" [ScalarType "timestamptz"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunName "time" [ScalarType "interval"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunName "time" [ScalarType "timetz"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunName "time"
->           [ScalarType "time", ScalarType "int4"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunName "time_cmp"
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "time_eq"
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "time_ge"
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "time_gt"
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "time_hash" [ScalarType "time"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "time_in"
->           [Pseudo Cstring, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunName "time_larger"
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunName "time_le"
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "time_lt"
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "time_mi_interval"
->           [ScalarType "time", ScalarType "interval"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunName "time_mi_time"
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "time_ne"
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "time_out" [ScalarType "time"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "time_pl_interval"
->           [ScalarType "time", ScalarType "interval"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunName "time_recv"
->           [Pseudo Internal, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunName "time_send" [ScalarType "time"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "time_smaller"
->           [ScalarType "time", ScalarType "time"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunName "timedate_pl"
->           [ScalarType "time", ScalarType "date"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "timemi"
->           [ScalarType "abstime", ScalarType "reltime"]
->           (ScalarType "abstime")
->           False,
->         CatCreateFunction FunName "timenow" [] (ScalarType "abstime")
->           False,
->         CatCreateFunction FunName "timeofday" [] (ScalarType "text") False,
->         CatCreateFunction FunName "timepl"
->           [ScalarType "abstime", ScalarType "reltime"]
->           (ScalarType "abstime")
->           False,
->         CatCreateFunction FunName "timestamp" [ScalarType "abstime"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "timestamp" [ScalarType "date"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "timestamp" [ScalarType "timestamptz"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "timestamp"
->           [ScalarType "date", ScalarType "time"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "timestamp"
->           [ScalarType "timestamp", ScalarType "int4"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "timestamp_cmp"
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "timestamp_cmp_date"
->           [ScalarType "timestamp", ScalarType "date"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "timestamp_cmp_timestamptz"
->           [ScalarType "timestamp", ScalarType "timestamptz"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "timestamp_eq"
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_eq_date"
->           [ScalarType "timestamp", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_eq_timestamptz"
->           [ScalarType "timestamp", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_ge"
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_ge_date"
->           [ScalarType "timestamp", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_ge_timestamptz"
->           [ScalarType "timestamp", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_gt"
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_gt_date"
->           [ScalarType "timestamp", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_gt_timestamptz"
->           [ScalarType "timestamp", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_hash" [ScalarType "timestamp"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "timestamp_in"
->           [Pseudo Cstring, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "timestamp_larger"
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "timestamp_le"
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_le_date"
->           [ScalarType "timestamp", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_le_timestamptz"
->           [ScalarType "timestamp", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_lt"
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_lt_date"
->           [ScalarType "timestamp", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_lt_timestamptz"
->           [ScalarType "timestamp", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_mi"
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "timestamp_mi_interval"
->           [ScalarType "timestamp", ScalarType "interval"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "timestamp_ne"
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_ne_date"
->           [ScalarType "timestamp", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_ne_timestamptz"
->           [ScalarType "timestamp", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamp_out" [ScalarType "timestamp"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "timestamp_pl_interval"
->           [ScalarType "timestamp", ScalarType "interval"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "timestamp_recv"
->           [Pseudo Internal, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "timestamp_send" [ScalarType "timestamp"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "timestamp_smaller"
->           [ScalarType "timestamp", ScalarType "timestamp"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "timestamptypmodin"
->           [ArrayType (Pseudo Cstring)]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "timestamptypmodout" [ScalarType "int4"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "timestamptz" [ScalarType "abstime"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "timestamptz" [ScalarType "date"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "timestamptz" [ScalarType "timestamp"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "timestamptz"
->           [ScalarType "date", ScalarType "time"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "timestamptz"
->           [ScalarType "date", ScalarType "timetz"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "timestamptz"
->           [ScalarType "timestamptz", ScalarType "int4"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "timestamptz_cmp"
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "timestamptz_cmp_date"
->           [ScalarType "timestamptz", ScalarType "date"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "timestamptz_cmp_timestamp"
->           [ScalarType "timestamptz", ScalarType "timestamp"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "timestamptz_eq"
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_eq_date"
->           [ScalarType "timestamptz", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_eq_timestamp"
->           [ScalarType "timestamptz", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_ge"
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_ge_date"
->           [ScalarType "timestamptz", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_ge_timestamp"
->           [ScalarType "timestamptz", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_gt"
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_gt_date"
->           [ScalarType "timestamptz", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_gt_timestamp"
->           [ScalarType "timestamptz", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_in"
->           [Pseudo Cstring, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "timestamptz_larger"
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "timestamptz_le"
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_le_date"
->           [ScalarType "timestamptz", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_le_timestamp"
->           [ScalarType "timestamptz", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_lt"
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_lt_date"
->           [ScalarType "timestamptz", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_lt_timestamp"
->           [ScalarType "timestamptz", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_mi"
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunName "timestamptz_mi_interval"
->           [ScalarType "timestamptz", ScalarType "interval"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "timestamptz_ne"
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_ne_date"
->           [ScalarType "timestamptz", ScalarType "date"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_ne_timestamp"
->           [ScalarType "timestamptz", ScalarType "timestamp"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timestamptz_out"
->           [ScalarType "timestamptz"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "timestamptz_pl_interval"
->           [ScalarType "timestamptz", ScalarType "interval"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "timestamptz_recv"
->           [Pseudo Internal, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "timestamptz_send"
->           [ScalarType "timestamptz"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "timestamptz_smaller"
->           [ScalarType "timestamptz", ScalarType "timestamptz"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "timestamptztypmodin"
->           [ArrayType (Pseudo Cstring)]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "timestamptztypmodout"
->           [ScalarType "int4"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "timetypmodin"
->           [ArrayType (Pseudo Cstring)]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "timetypmodout" [ScalarType "int4"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "timetz" [ScalarType "time"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunName "timetz" [ScalarType "timestamptz"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunName "timetz"
->           [ScalarType "timetz", ScalarType "int4"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunName "timetz_cmp"
->           [ScalarType "timetz", ScalarType "timetz"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "timetz_eq"
->           [ScalarType "timetz", ScalarType "timetz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timetz_ge"
->           [ScalarType "timetz", ScalarType "timetz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timetz_gt"
->           [ScalarType "timetz", ScalarType "timetz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timetz_hash" [ScalarType "timetz"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "timetz_in"
->           [Pseudo Cstring, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunName "timetz_larger"
->           [ScalarType "timetz", ScalarType "timetz"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunName "timetz_le"
->           [ScalarType "timetz", ScalarType "timetz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timetz_lt"
->           [ScalarType "timetz", ScalarType "timetz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timetz_mi_interval"
->           [ScalarType "timetz", ScalarType "interval"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunName "timetz_ne"
->           [ScalarType "timetz", ScalarType "timetz"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "timetz_out" [ScalarType "timetz"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "timetz_pl_interval"
->           [ScalarType "timetz", ScalarType "interval"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunName "timetz_recv"
->           [Pseudo Internal, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunName "timetz_send" [ScalarType "timetz"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "timetz_smaller"
->           [ScalarType "timetz", ScalarType "timetz"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunName "timetzdate_pl"
->           [ScalarType "timetz", ScalarType "date"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "timetztypmodin"
->           [ArrayType (Pseudo Cstring)]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "timetztypmodout" [ScalarType "int4"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "timezone"
->           [ScalarType "text", ScalarType "timestamp"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "timezone"
->           [ScalarType "text", ScalarType "timestamptz"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "timezone"
->           [ScalarType "text", ScalarType "timetz"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunName "timezone"
->           [ScalarType "interval", ScalarType "timestamp"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "timezone"
->           [ScalarType "interval", ScalarType "timestamptz"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunName "timezone"
->           [ScalarType "interval", ScalarType "timetz"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunName "tinterval"
->           [ScalarType "abstime", ScalarType "abstime"]
->           (ScalarType "tinterval")
->           False,
->         CatCreateFunction FunName "tintervalct"
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tintervalend" [ScalarType "tinterval"]
->           (ScalarType "abstime")
->           False,
->         CatCreateFunction FunName "tintervaleq"
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tintervalge"
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tintervalgt"
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tintervalin" [Pseudo Cstring]
->           (ScalarType "tinterval")
->           False,
->         CatCreateFunction FunName "tintervalle"
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tintervalleneq"
->           [ScalarType "tinterval", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tintervallenge"
->           [ScalarType "tinterval", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tintervallengt"
->           [ScalarType "tinterval", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tintervallenle"
->           [ScalarType "tinterval", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tintervallenlt"
->           [ScalarType "tinterval", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tintervallenne"
->           [ScalarType "tinterval", ScalarType "reltime"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tintervallt"
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tintervalne"
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tintervalout" [ScalarType "tinterval"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "tintervalov"
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tintervalrecv" [Pseudo Internal]
->           (ScalarType "tinterval")
->           False,
->         CatCreateFunction FunName "tintervalrel" [ScalarType "tinterval"]
->           (ScalarType "reltime")
->           False,
->         CatCreateFunction FunName "tintervalsame"
->           [ScalarType "tinterval", ScalarType "tinterval"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tintervalsend" [ScalarType "tinterval"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "tintervalstart" [ScalarType "tinterval"]
->           (ScalarType "abstime")
->           False,
->         CatCreateFunction FunName "to_ascii" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "to_ascii"
->           [ScalarType "text", ScalarType "name"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "to_ascii"
->           [ScalarType "text", ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "to_char"
->           [ScalarType "int8", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "to_char"
->           [ScalarType "int4", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "to_char"
->           [ScalarType "float4", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "to_char"
->           [ScalarType "float8", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "to_char"
->           [ScalarType "timestamp", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "to_char"
->           [ScalarType "timestamptz", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "to_char"
->           [ScalarType "interval", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "to_char"
->           [ScalarType "numeric", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "to_date"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "date")
->           False,
->         CatCreateFunction FunName "to_hex" [ScalarType "int8"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "to_hex" [ScalarType "int4"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "to_number"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "to_timestamp" [ScalarType "float8"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "to_timestamp"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "to_tsquery" [ScalarType "text"]
->           (ScalarType "tsquery")
->           False,
->         CatCreateFunction FunName "to_tsquery"
->           [ScalarType "regconfig", ScalarType "text"]
->           (ScalarType "tsquery")
->           False,
->         CatCreateFunction FunName "to_tsvector" [ScalarType "text"]
->           (ScalarType "tsvector")
->           False,
->         CatCreateFunction FunName "to_tsvector"
->           [ScalarType "regconfig", ScalarType "text"]
->           (ScalarType "tsvector")
->           False,
->         CatCreateFunction FunName "transaction_timestamp" []
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunName "translate"
->           [ScalarType "text", ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "trigger_in" [Pseudo Cstring]
->           (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "trigger_out" [Pseudo Trigger]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "trunc" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "trunc" [ScalarType "macaddr"]
->           (ScalarType "macaddr")
->           False,
->         CatCreateFunction FunName "trunc" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "trunc"
->           [ScalarType "numeric", ScalarType "int4"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunName "ts_debug" [ScalarType "text"]
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "ts_debug"
->           [ScalarType "regconfig", ScalarType "text"]
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "ts_headline"
->           [ScalarType "text", ScalarType "tsquery"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "ts_headline"
->           [ScalarType "text", ScalarType "tsquery", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "ts_headline"
->           [ScalarType "regconfig", ScalarType "text", ScalarType "tsquery"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "ts_headline"
->           [ScalarType "regconfig", ScalarType "text", ScalarType "tsquery",
->            ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "ts_lexize"
->           [ScalarType "regdictionary", ScalarType "text"]
->           (ArrayType (ScalarType "text"))
->           False,
->         CatCreateFunction FunName "ts_match_qv"
->           [ScalarType "tsquery", ScalarType "tsvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "ts_match_tq"
->           [ScalarType "text", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "ts_match_tt"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "ts_match_vq"
->           [ScalarType "tsvector", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "ts_parse"
->           [ScalarType "text", ScalarType "text"]
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "ts_parse"
->           [ScalarType "oid", ScalarType "text"]
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "ts_rank"
->           [ScalarType "tsvector", ScalarType "tsquery"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "ts_rank"
->           [ArrayType (ScalarType "float4"), ScalarType "tsvector",
->            ScalarType "tsquery"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "ts_rank"
->           [ScalarType "tsvector", ScalarType "tsquery", ScalarType "int4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "ts_rank"
->           [ArrayType (ScalarType "float4"), ScalarType "tsvector",
->            ScalarType "tsquery", ScalarType "int4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "ts_rank_cd"
->           [ScalarType "tsvector", ScalarType "tsquery"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "ts_rank_cd"
->           [ArrayType (ScalarType "float4"), ScalarType "tsvector",
->            ScalarType "tsquery"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "ts_rank_cd"
->           [ScalarType "tsvector", ScalarType "tsquery", ScalarType "int4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "ts_rank_cd"
->           [ArrayType (ScalarType "float4"), ScalarType "tsvector",
->            ScalarType "tsquery", ScalarType "int4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunName "ts_rewrite"
->           [ScalarType "tsquery", ScalarType "text"]
->           (ScalarType "tsquery")
->           False,
->         CatCreateFunction FunName "ts_rewrite"
->           [ScalarType "tsquery", ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "tsquery")
->           False,
->         CatCreateFunction FunName "ts_stat" [ScalarType "text"]
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "ts_stat"
->           [ScalarType "text", ScalarType "text"]
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "ts_token_type" [ScalarType "text"]
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "ts_token_type" [ScalarType "oid"]
->           (SetOfType (Pseudo Record))
->           False,
->         CatCreateFunction FunName "ts_typanalyze" [Pseudo Internal]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tsmatchjoinsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int2", Pseudo Internal]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "tsmatchsel"
->           [Pseudo Internal, ScalarType "oid", Pseudo Internal,
->            ScalarType "int4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "tsq_mcontained"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tsq_mcontains"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tsquery_and"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "tsquery")
->           False,
->         CatCreateFunction FunName "tsquery_cmp"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "tsquery_eq"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tsquery_ge"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tsquery_gt"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tsquery_le"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tsquery_lt"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tsquery_ne"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tsquery_not" [ScalarType "tsquery"]
->           (ScalarType "tsquery")
->           False,
->         CatCreateFunction FunName "tsquery_or"
->           [ScalarType "tsquery", ScalarType "tsquery"]
->           (ScalarType "tsquery")
->           False,
->         CatCreateFunction FunName "tsqueryin" [Pseudo Cstring]
->           (ScalarType "tsquery")
->           False,
->         CatCreateFunction FunName "tsqueryout" [ScalarType "tsquery"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "tsqueryrecv" [Pseudo Internal]
->           (ScalarType "tsquery")
->           False,
->         CatCreateFunction FunName "tsquerysend" [ScalarType "tsquery"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "tsvector_cmp"
->           [ScalarType "tsvector", ScalarType "tsvector"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "tsvector_concat"
->           [ScalarType "tsvector", ScalarType "tsvector"]
->           (ScalarType "tsvector")
->           False,
->         CatCreateFunction FunName "tsvector_eq"
->           [ScalarType "tsvector", ScalarType "tsvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tsvector_ge"
->           [ScalarType "tsvector", ScalarType "tsvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tsvector_gt"
->           [ScalarType "tsvector", ScalarType "tsvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tsvector_le"
->           [ScalarType "tsvector", ScalarType "tsvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tsvector_lt"
->           [ScalarType "tsvector", ScalarType "tsvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tsvector_ne"
->           [ScalarType "tsvector", ScalarType "tsvector"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "tsvector_update_trigger" []
->           (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "tsvector_update_trigger_column" []
->           (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "tsvectorin" [Pseudo Cstring]
->           (ScalarType "tsvector")
->           False,
->         CatCreateFunction FunName "tsvectorout" [ScalarType "tsvector"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "tsvectorrecv" [Pseudo Internal]
->           (ScalarType "tsvector")
->           False,
->         CatCreateFunction FunName "tsvectorsend" [ScalarType "tsvector"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "txid_current" [] (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "txid_current_snapshot" []
->           (ScalarType "txid_snapshot")
->           False,
->         CatCreateFunction FunName "txid_snapshot_in" [Pseudo Cstring]
->           (ScalarType "txid_snapshot")
->           False,
->         CatCreateFunction FunName "txid_snapshot_out"
->           [ScalarType "txid_snapshot"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "txid_snapshot_recv" [Pseudo Internal]
->           (ScalarType "txid_snapshot")
->           False,
->         CatCreateFunction FunName "txid_snapshot_send"
->           [ScalarType "txid_snapshot"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "txid_snapshot_xip"
->           [ScalarType "txid_snapshot"]
->           (SetOfType (ScalarType "int8"))
->           False,
->         CatCreateFunction FunName "txid_snapshot_xmax"
->           [ScalarType "txid_snapshot"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "txid_snapshot_xmin"
->           [ScalarType "txid_snapshot"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunName "txid_visible_in_snapshot"
->           [ScalarType "int8", ScalarType "txid_snapshot"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "uhc_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "unique_key_recheck" [] (Pseudo Trigger)
->           False,
->         CatCreateFunction FunName "unknownin" [Pseudo Cstring]
->           (ScalarType "unknown")
->           False,
->         CatCreateFunction FunName "unknownout" [ScalarType "unknown"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "unknownrecv" [Pseudo Internal]
->           (ScalarType "unknown")
->           False,
->         CatCreateFunction FunName "unknownsend" [ScalarType "unknown"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "unnest" [Pseudo AnyArray]
->           (SetOfType (Pseudo AnyElement))
->           False,
->         CatCreateFunction FunName "upper" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunName "utf8_to_ascii"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_big5"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_euc_cn"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_euc_jis_2004"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_euc_jp"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_euc_kr"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_euc_tw"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_gb18030"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_gbk"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_iso8859"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_iso8859_1"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_johab"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_koi8r"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_koi8u"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_shift_jis_2004"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_sjis"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_uhc"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "utf8_to_win"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "uuid_cmp"
->           [ScalarType "uuid", ScalarType "uuid"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "uuid_eq"
->           [ScalarType "uuid", ScalarType "uuid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "uuid_ge"
->           [ScalarType "uuid", ScalarType "uuid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "uuid_gt"
->           [ScalarType "uuid", ScalarType "uuid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "uuid_hash" [ScalarType "uuid"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "uuid_in" [Pseudo Cstring]
->           (ScalarType "uuid")
->           False,
->         CatCreateFunction FunName "uuid_le"
->           [ScalarType "uuid", ScalarType "uuid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "uuid_lt"
->           [ScalarType "uuid", ScalarType "uuid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "uuid_ne"
->           [ScalarType "uuid", ScalarType "uuid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "uuid_out" [ScalarType "uuid"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "uuid_recv" [Pseudo Internal]
->           (ScalarType "uuid")
->           False,
->         CatCreateFunction FunName "uuid_send" [ScalarType "uuid"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "varbit"
->           [ScalarType "varbit", ScalarType "int4", ScalarType "bool"]
->           (ScalarType "varbit")
->           False,
->         CatCreateFunction FunName "varbit_in"
->           [Pseudo Cstring, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "varbit")
->           False,
->         CatCreateFunction FunName "varbit_out" [ScalarType "varbit"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "varbit_recv"
->           [Pseudo Internal, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "varbit")
->           False,
->         CatCreateFunction FunName "varbit_send" [ScalarType "varbit"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "varbitcmp"
->           [ScalarType "varbit", ScalarType "varbit"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "varbiteq"
->           [ScalarType "varbit", ScalarType "varbit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "varbitge"
->           [ScalarType "varbit", ScalarType "varbit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "varbitgt"
->           [ScalarType "varbit", ScalarType "varbit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "varbitle"
->           [ScalarType "varbit", ScalarType "varbit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "varbitlt"
->           [ScalarType "varbit", ScalarType "varbit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "varbitne"
->           [ScalarType "varbit", ScalarType "varbit"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "varbittypmodin"
->           [ArrayType (Pseudo Cstring)]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "varbittypmodout" [ScalarType "int4"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "varchar" [ScalarType "name"]
->           (ScalarType "varchar")
->           False,
->         CatCreateFunction FunName "varchar"
->           [ScalarType "varchar", ScalarType "int4", ScalarType "bool"]
->           (ScalarType "varchar")
->           False,
->         CatCreateFunction FunName "varcharin"
->           [Pseudo Cstring, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "varchar")
->           False,
->         CatCreateFunction FunName "varcharout" [ScalarType "varchar"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "varcharrecv"
->           [Pseudo Internal, ScalarType "oid", ScalarType "int4"]
->           (ScalarType "varchar")
->           False,
->         CatCreateFunction FunName "varcharsend" [ScalarType "varchar"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "varchartypmodin"
->           [ArrayType (Pseudo Cstring)]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "varchartypmodout" [ScalarType "int4"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "version" [] (ScalarType "text") False,
->         CatCreateFunction FunName "void_in" [Pseudo Cstring] (Pseudo Void)
->           False,
->         CatCreateFunction FunName "void_out" [Pseudo Void] (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "void_recv" [Pseudo Internal]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "void_send" [Pseudo Void]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "width" [ScalarType "box"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunName "width_bucket"
->           [ScalarType "float8", ScalarType "float8", ScalarType "float8",
->            ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "width_bucket"
->           [ScalarType "numeric", ScalarType "numeric", ScalarType "numeric",
->            ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunName "win1250_to_latin2"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "win1250_to_mic"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "win1251_to_iso"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "win1251_to_koi8r"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "win1251_to_mic"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "win1251_to_win866"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "win866_to_iso"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "win866_to_koi8r"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "win866_to_mic"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "win866_to_win1251"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "win_to_utf8"
->           [ScalarType "int4", ScalarType "int4", Pseudo Cstring,
->            Pseudo Internal, ScalarType "int4"]
->           (Pseudo Void)
->           False,
->         CatCreateFunction FunName "xideq"
->           [ScalarType "xid", ScalarType "xid"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "xideqint4"
->           [ScalarType "xid", ScalarType "int4"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "xidin" [Pseudo Cstring]
->           (ScalarType "xid")
->           False,
->         CatCreateFunction FunName "xidout" [ScalarType "xid"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "xidrecv" [Pseudo Internal]
->           (ScalarType "xid")
->           False,
->         CatCreateFunction FunName "xidsend" [ScalarType "xid"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "xml" [ScalarType "text"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "xml_in" [Pseudo Cstring]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "xml_is_well_formed" [ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "xml_is_well_formed_content"
->           [ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "xml_is_well_formed_document"
->           [ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "xml_out" [ScalarType "xml"]
->           (Pseudo Cstring)
->           False,
->         CatCreateFunction FunName "xml_recv" [Pseudo Internal]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "xml_send" [ScalarType "xml"]
->           (ScalarType "bytea")
->           False,
->         CatCreateFunction FunName "xmlcomment" [ScalarType "text"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "xmlconcat2"
->           [ScalarType "xml", ScalarType "xml"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunName "xmlexists"
->           [ScalarType "text", ScalarType "xml"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "xmlvalidate"
->           [ScalarType "xml", ScalarType "text"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "xpath"
->           [ScalarType "text", ScalarType "xml"]
->           (ArrayType (ScalarType "xml"))
->           False,
->         CatCreateFunction FunName "xpath"
->           [ScalarType "text", ScalarType "xml",
->            ArrayType (ScalarType "text")]
->           (ArrayType (ScalarType "xml"))
->           False,
->         CatCreateFunction FunName "xpath_exists"
->           [ScalarType "text", ScalarType "xml"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunName "xpath_exists"
->           [ScalarType "text", ScalarType "xml",
->            ArrayType (ScalarType "text")]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunAgg "array_agg" [Pseudo AnyElement]
->           (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunAgg "avg" [ScalarType "int8"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "avg" [ScalarType "int2"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "avg" [ScalarType "int4"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "avg" [ScalarType "float4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "avg" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "avg" [ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunAgg "avg" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "bit_and" [ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunAgg "bit_and" [ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunAgg "bit_and" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunAgg "bit_and" [ScalarType "bit"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunAgg "bit_or" [ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunAgg "bit_or" [ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunAgg "bit_or" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunAgg "bit_or" [ScalarType "bit"]
->           (ScalarType "bit")
->           False,
->         CatCreateFunction FunAgg "bool_and" [ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunAgg "bool_or" [ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunAgg "corr"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "count" [] (ScalarType "int8") False,
->         CatCreateFunction FunAgg "count" [Pseudo Any] (ScalarType "int8")
->           False,
->         CatCreateFunction FunAgg "covar_pop"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "covar_samp"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "every" [ScalarType "bool"]
->           (ScalarType "bool")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "oid"]
->           (ScalarType "oid")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "tid"]
->           (ScalarType "tid")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "abstime"]
->           (ScalarType "abstime")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "bpchar"]
->           (ScalarType "bpchar")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "date"]
->           (ScalarType "date")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "time"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "timestamp"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "timestamptz"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "timetz"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunAgg "max" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "max" [Pseudo AnyArray] (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunAgg "max" [Pseudo AnyEnum] (Pseudo AnyEnum)
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "int8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "int2"]
->           (ScalarType "int2")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "oid"]
->           (ScalarType "oid")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "tid"]
->           (ScalarType "tid")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "abstime"]
->           (ScalarType "abstime")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "bpchar"]
->           (ScalarType "bpchar")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "date"]
->           (ScalarType "date")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "time"]
->           (ScalarType "time")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "timestamp"]
->           (ScalarType "timestamp")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "timestamptz"]
->           (ScalarType "timestamptz")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "timetz"]
->           (ScalarType "timetz")
->           False,
->         CatCreateFunction FunAgg "min" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "min" [Pseudo AnyArray] (Pseudo AnyArray)
->           False,
->         CatCreateFunction FunAgg "min" [Pseudo AnyEnum] (Pseudo AnyEnum)
->           False,
->         CatCreateFunction FunAgg "regr_avgx"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "regr_avgy"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "regr_count"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunAgg "regr_intercept"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "regr_r2"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "regr_slope"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "regr_sxx"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "regr_sxy"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "regr_syy"
->           [ScalarType "float8", ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "stddev" [ScalarType "int8"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "stddev" [ScalarType "int2"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "stddev" [ScalarType "int4"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "stddev" [ScalarType "float4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "stddev" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "stddev" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "stddev_pop" [ScalarType "int8"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "stddev_pop" [ScalarType "int2"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "stddev_pop" [ScalarType "int4"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "stddev_pop" [ScalarType "float4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "stddev_pop" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "stddev_pop" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "stddev_samp" [ScalarType "int8"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "stddev_samp" [ScalarType "int2"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "stddev_samp" [ScalarType "int4"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "stddev_samp" [ScalarType "float4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "stddev_samp" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "stddev_samp" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "string_agg"
->           [ScalarType "text", ScalarType "text"]
->           (ScalarType "text")
->           False,
->         CatCreateFunction FunAgg "sum" [ScalarType "int8"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "sum" [ScalarType "int2"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunAgg "sum" [ScalarType "int4"]
->           (ScalarType "int8")
->           False,
->         CatCreateFunction FunAgg "sum" [ScalarType "float4"]
->           (ScalarType "float4")
->           False,
->         CatCreateFunction FunAgg "sum" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "sum" [ScalarType "money"]
->           (ScalarType "money")
->           False,
->         CatCreateFunction FunAgg "sum" [ScalarType "interval"]
->           (ScalarType "interval")
->           False,
->         CatCreateFunction FunAgg "sum" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "var_pop" [ScalarType "int8"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "var_pop" [ScalarType "int2"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "var_pop" [ScalarType "int4"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "var_pop" [ScalarType "float4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "var_pop" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "var_pop" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "var_samp" [ScalarType "int8"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "var_samp" [ScalarType "int2"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "var_samp" [ScalarType "int4"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "var_samp" [ScalarType "float4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "var_samp" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "var_samp" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "variance" [ScalarType "int8"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "variance" [ScalarType "int2"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "variance" [ScalarType "int4"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "variance" [ScalarType "float4"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "variance" [ScalarType "float8"]
->           (ScalarType "float8")
->           False,
->         CatCreateFunction FunAgg "variance" [ScalarType "numeric"]
->           (ScalarType "numeric")
->           False,
->         CatCreateFunction FunAgg "xmlagg" [ScalarType "xml"]
->           (ScalarType "xml")
->           False,
->         CatCreateFunction FunWindow "cume_dist" [] (ScalarType "float8")
->           False,
->         CatCreateFunction FunWindow "dense_rank" [] (ScalarType "int8")
->           False,
->         CatCreateFunction FunWindow "first_value" [Pseudo AnyElement]
->           (Pseudo AnyElement)
->           False,
->         CatCreateFunction FunWindow "lag" [Pseudo AnyElement]
->           (Pseudo AnyElement)
->           False,
->         CatCreateFunction FunWindow "lag"
->           [Pseudo AnyElement, ScalarType "int4"]
->           (Pseudo AnyElement)
->           False,
->         CatCreateFunction FunWindow "lag"
->           [Pseudo AnyElement, ScalarType "int4", Pseudo AnyElement]
->           (Pseudo AnyElement)
->           False,
->         CatCreateFunction FunWindow "last_value" [Pseudo AnyElement]
->           (Pseudo AnyElement)
->           False,
->         CatCreateFunction FunWindow "lead" [Pseudo AnyElement]
->           (Pseudo AnyElement)
->           False,
->         CatCreateFunction FunWindow "lead"
->           [Pseudo AnyElement, ScalarType "int4"]
->           (Pseudo AnyElement)
->           False,
->         CatCreateFunction FunWindow "lead"
->           [Pseudo AnyElement, ScalarType "int4", Pseudo AnyElement]
->           (Pseudo AnyElement)
->           False,
->         CatCreateFunction FunWindow "nth_value"
->           [Pseudo AnyElement, ScalarType "int4"]
->           (Pseudo AnyElement)
->           False,
->         CatCreateFunction FunWindow "ntile" [ScalarType "int4"]
->           (ScalarType "int4")
->           False,
->         CatCreateFunction FunWindow "percent_rank" [] (ScalarType "float8")
->           False,
->         CatCreateFunction FunWindow "rank" [] (ScalarType "int8") False,
->         CatCreateFunction FunWindow "row_number" [] (ScalarType "int8")
->           False,
->         CatCreateTable "pg_aggregate"
->           [("aggfnoid", ScalarType "regproc"),
->            ("aggtransfn", ScalarType "regproc"),
->            ("aggfinalfn", ScalarType "regproc"),
->            ("aggsortop", ScalarType "oid"),
->            ("aggtranstype", ScalarType "oid"),
->            ("agginitval", ScalarType "text")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_am"
->           [("amname", ScalarType "name"),
->            ("amstrategies", ScalarType "int2"),
->            ("amsupport", ScalarType "int2"),
->            ("amcanorder", ScalarType "bool"),
->            ("amcanorderbyop", ScalarType "bool"),
->            ("amcanbackward", ScalarType "bool"),
->            ("amcanunique", ScalarType "bool"),
->            ("amcanmulticol", ScalarType "bool"),
->            ("amoptionalkey", ScalarType "bool"),
->            ("amsearchnulls", ScalarType "bool"),
->            ("amstorage", ScalarType "bool"),
->            ("amclusterable", ScalarType "bool"),
->            ("ampredlocks", ScalarType "bool"),
->            ("amkeytype", ScalarType "oid"),
->            ("aminsert", ScalarType "regproc"),
->            ("ambeginscan", ScalarType "regproc"),
->            ("amgettuple", ScalarType "regproc"),
->            ("amgetbitmap", ScalarType "regproc"),
->            ("amrescan", ScalarType "regproc"),
->            ("amendscan", ScalarType "regproc"),
->            ("ammarkpos", ScalarType "regproc"),
->            ("amrestrpos", ScalarType "regproc"),
->            ("ambuild", ScalarType "regproc"),
->            ("ambuildempty", ScalarType "regproc"),
->            ("ambulkdelete", ScalarType "regproc"),
->            ("amvacuumcleanup", ScalarType "regproc"),
->            ("amcostestimate", ScalarType "regproc"),
->            ("amoptions", ScalarType "regproc")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_amop"
->           [("amopfamily", ScalarType "oid"),
->            ("amoplefttype", ScalarType "oid"),
->            ("amoprighttype", ScalarType "oid"),
->            ("amopstrategy", ScalarType "int2"),
->            ("amoppurpose", ScalarType "char"), ("amopopr", ScalarType "oid"),
->            ("amopmethod", ScalarType "oid"),
->            ("amopsortfamily", ScalarType "oid")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_amproc"
->           [("amprocfamily", ScalarType "oid"),
->            ("amproclefttype", ScalarType "oid"),
->            ("amprocrighttype", ScalarType "oid"),
->            ("amprocnum", ScalarType "int2"), ("amproc", ScalarType "regproc")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_attrdef"
->           [("adrelid", ScalarType "oid"), ("adnum", ScalarType "int2"),
->            ("adbin", ScalarType "pg_node_tree"), ("adsrc", ScalarType "text")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_attribute"
->           [("attrelid", ScalarType "oid"), ("attname", ScalarType "name"),
->            ("atttypid", ScalarType "oid"),
->            ("attstattarget", ScalarType "int4"),
->            ("attlen", ScalarType "int2"), ("attnum", ScalarType "int2"),
->            ("attndims", ScalarType "int4"),
->            ("attcacheoff", ScalarType "int4"),
->            ("atttypmod", ScalarType "int4"), ("attbyval", ScalarType "bool"),
->            ("attstorage", ScalarType "char"), ("attalign", ScalarType "char"),
->            ("attnotnull", ScalarType "bool"),
->            ("atthasdef", ScalarType "bool"),
->            ("attisdropped", ScalarType "bool"),
->            ("attislocal", ScalarType "bool"),
->            ("attinhcount", ScalarType "int4"),
->            ("attcollation", ScalarType "oid"),
->            ("attacl", ArrayType (ScalarType "aclitem")),
->            ("attoptions", ArrayType (ScalarType "text"))]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_auth_members"
->           [("roleid", ScalarType "oid"), ("member", ScalarType "oid"),
->            ("grantor", ScalarType "oid"), ("admin_option", ScalarType "bool")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_authid"
->           [("rolname", ScalarType "name"), ("rolsuper", ScalarType "bool"),
->            ("rolinherit", ScalarType "bool"),
->            ("rolcreaterole", ScalarType "bool"),
->            ("rolcreatedb", ScalarType "bool"),
->            ("rolcatupdate", ScalarType "bool"),
->            ("rolcanlogin", ScalarType "bool"),
->            ("rolreplication", ScalarType "bool"),
->            ("rolconnlimit", ScalarType "int4"),
->            ("rolpassword", ScalarType "text"),
->            ("rolvaliduntil", ScalarType "timestamptz")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_cast"
->           [("castsource", ScalarType "oid"),
->            ("casttarget", ScalarType "oid"), ("castfunc", ScalarType "oid"),
->            ("castcontext", ScalarType "char"),
->            ("castmethod", ScalarType "char")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_class"
->           [("relname", ScalarType "name"),
->            ("relnamespace", ScalarType "oid"), ("reltype", ScalarType "oid"),
->            ("reloftype", ScalarType "oid"), ("relowner", ScalarType "oid"),
->            ("relam", ScalarType "oid"), ("relfilenode", ScalarType "oid"),
->            ("reltablespace", ScalarType "oid"),
->            ("relpages", ScalarType "int4"),
->            ("reltuples", ScalarType "float4"),
->            ("reltoastrelid", ScalarType "oid"),
->            ("reltoastidxid", ScalarType "oid"),
->            ("relhasindex", ScalarType "bool"),
->            ("relisshared", ScalarType "bool"),
->            ("relpersistence", ScalarType "char"),
->            ("relkind", ScalarType "char"), ("relnatts", ScalarType "int2"),
->            ("relchecks", ScalarType "int2"),
->            ("relhasoids", ScalarType "bool"),
->            ("relhaspkey", ScalarType "bool"),
->            ("relhasrules", ScalarType "bool"),
->            ("relhastriggers", ScalarType "bool"),
->            ("relhassubclass", ScalarType "bool"),
->            ("relfrozenxid", ScalarType "xid"),
->            ("relacl", ArrayType (ScalarType "aclitem")),
->            ("reloptions", ArrayType (ScalarType "text"))]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_collation"
->           [("collname", ScalarType "name"),
->            ("collnamespace", ScalarType "oid"),
->            ("collowner", ScalarType "oid"),
->            ("collencoding", ScalarType "int4"),
->            ("collcollate", ScalarType "name"),
->            ("collctype", ScalarType "name")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_constraint"
->           [("conname", ScalarType "name"),
->            ("connamespace", ScalarType "oid"), ("contype", ScalarType "char"),
->            ("condeferrable", ScalarType "bool"),
->            ("condeferred", ScalarType "bool"),
->            ("convalidated", ScalarType "bool"),
->            ("conrelid", ScalarType "oid"), ("contypid", ScalarType "oid"),
->            ("conindid", ScalarType "oid"), ("confrelid", ScalarType "oid"),
->            ("confupdtype", ScalarType "char"),
->            ("confdeltype", ScalarType "char"),
->            ("confmatchtype", ScalarType "char"),
->            ("conislocal", ScalarType "bool"),
->            ("coninhcount", ScalarType "int4"),
->            ("conkey", ArrayType (ScalarType "int2")),
->            ("confkey", ArrayType (ScalarType "int2")),
->            ("conpfeqop", ArrayType (ScalarType "oid")),
->            ("conppeqop", ArrayType (ScalarType "oid")),
->            ("conffeqop", ArrayType (ScalarType "oid")),
->            ("conexclop", ArrayType (ScalarType "oid")),
->            ("conbin", ScalarType "pg_node_tree"),
->            ("consrc", ScalarType "text")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_conversion"
->           [("conname", ScalarType "name"),
->            ("connamespace", ScalarType "oid"), ("conowner", ScalarType "oid"),
->            ("conforencoding", ScalarType "int4"),
->            ("contoencoding", ScalarType "int4"),
->            ("conproc", ScalarType "regproc"),
->            ("condefault", ScalarType "bool")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_database"
->           [("datname", ScalarType "name"), ("datdba", ScalarType "oid"),
->            ("encoding", ScalarType "int4"), ("datcollate", ScalarType "name"),
->            ("datctype", ScalarType "name"),
->            ("datistemplate", ScalarType "bool"),
->            ("datallowconn", ScalarType "bool"),
->            ("datconnlimit", ScalarType "int4"),
->            ("datlastsysoid", ScalarType "oid"),
->            ("datfrozenxid", ScalarType "xid"),
->            ("dattablespace", ScalarType "oid"),
->            ("datacl", ArrayType (ScalarType "aclitem"))]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_db_role_setting"
->           [("setdatabase", ScalarType "oid"), ("setrole", ScalarType "oid"),
->            ("setconfig", ArrayType (ScalarType "text"))]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_default_acl"
->           [("defaclrole", ScalarType "oid"),
->            ("defaclnamespace", ScalarType "oid"),
->            ("defaclobjtype", ScalarType "char"),
->            ("defaclacl", ArrayType (ScalarType "aclitem"))]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_depend"
->           [("classid", ScalarType "oid"), ("objid", ScalarType "oid"),
->            ("objsubid", ScalarType "int4"), ("refclassid", ScalarType "oid"),
->            ("refobjid", ScalarType "oid"), ("refobjsubid", ScalarType "int4"),
->            ("deptype", ScalarType "char")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_description"
->           [("objoid", ScalarType "oid"), ("classoid", ScalarType "oid"),
->            ("objsubid", ScalarType "int4"),
->            ("description", ScalarType "text")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_enum"
->           [("enumtypid", ScalarType "oid"),
->            ("enumsortorder", ScalarType "float4"),
->            ("enumlabel", ScalarType "name")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_extension"
->           [("extname", ScalarType "name"), ("extowner", ScalarType "oid"),
->            ("extnamespace", ScalarType "oid"),
->            ("extrelocatable", ScalarType "bool"),
->            ("extversion", ScalarType "text"),
->            ("extconfig", ArrayType (ScalarType "oid")),
->            ("extcondition", ArrayType (ScalarType "text"))]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_foreign_data_wrapper"
->           [("fdwname", ScalarType "name"), ("fdwowner", ScalarType "oid"),
->            ("fdwhandler", ScalarType "oid"),
->            ("fdwvalidator", ScalarType "oid"),
->            ("fdwacl", ArrayType (ScalarType "aclitem")),
->            ("fdwoptions", ArrayType (ScalarType "text"))]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_foreign_server"
->           [("srvname", ScalarType "name"), ("srvowner", ScalarType "oid"),
->            ("srvfdw", ScalarType "oid"), ("srvtype", ScalarType "text"),
->            ("srvversion", ScalarType "text"),
->            ("srvacl", ArrayType (ScalarType "aclitem")),
->            ("srvoptions", ArrayType (ScalarType "text"))]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_foreign_table"
->           [("ftrelid", ScalarType "oid"), ("ftserver", ScalarType "oid"),
->            ("ftoptions", ArrayType (ScalarType "text"))]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_index"
->           [("indexrelid", ScalarType "oid"), ("indrelid", ScalarType "oid"),
->            ("indnatts", ScalarType "int2"),
->            ("indisunique", ScalarType "bool"),
->            ("indisprimary", ScalarType "bool"),
->            ("indisexclusion", ScalarType "bool"),
->            ("indimmediate", ScalarType "bool"),
->            ("indisclustered", ScalarType "bool"),
->            ("indisvalid", ScalarType "bool"),
->            ("indcheckxmin", ScalarType "bool"),
->            ("indisready", ScalarType "bool"),
->            ("indkey", ScalarType "int2vector"),
->            ("indcollation", ScalarType "oidvector"),
->            ("indclass", ScalarType "oidvector"),
->            ("indoption", ScalarType "int2vector"),
->            ("indexprs", ScalarType "pg_node_tree"),
->            ("indpred", ScalarType "pg_node_tree")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_inherits"
->           [("inhrelid", ScalarType "oid"), ("inhparent", ScalarType "oid"),
->            ("inhseqno", ScalarType "int4")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_language"
->           [("lanname", ScalarType "name"), ("lanowner", ScalarType "oid"),
->            ("lanispl", ScalarType "bool"),
->            ("lanpltrusted", ScalarType "bool"),
->            ("lanplcallfoid", ScalarType "oid"),
->            ("laninline", ScalarType "oid"),
->            ("lanvalidator", ScalarType "oid"),
->            ("lanacl", ArrayType (ScalarType "aclitem"))]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_largeobject"
->           [("loid", ScalarType "oid"), ("pageno", ScalarType "int4"),
->            ("data", ScalarType "bytea")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_largeobject_metadata"
->           [("lomowner", ScalarType "oid"),
->            ("lomacl", ArrayType (ScalarType "aclitem"))]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_namespace"
->           [("nspname", ScalarType "name"), ("nspowner", ScalarType "oid"),
->            ("nspacl", ArrayType (ScalarType "aclitem"))]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_opclass"
->           [("opcmethod", ScalarType "oid"), ("opcname", ScalarType "name"),
->            ("opcnamespace", ScalarType "oid"), ("opcowner", ScalarType "oid"),
->            ("opcfamily", ScalarType "oid"), ("opcintype", ScalarType "oid"),
->            ("opcdefault", ScalarType "bool"),
->            ("opckeytype", ScalarType "oid")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_operator"
->           [("oprname", ScalarType "name"),
->            ("oprnamespace", ScalarType "oid"), ("oprowner", ScalarType "oid"),
->            ("oprkind", ScalarType "char"), ("oprcanmerge", ScalarType "bool"),
->            ("oprcanhash", ScalarType "bool"), ("oprleft", ScalarType "oid"),
->            ("oprright", ScalarType "oid"), ("oprresult", ScalarType "oid"),
->            ("oprcom", ScalarType "oid"), ("oprnegate", ScalarType "oid"),
->            ("oprcode", ScalarType "regproc"),
->            ("oprrest", ScalarType "regproc"),
->            ("oprjoin", ScalarType "regproc")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_opfamily"
->           [("opfmethod", ScalarType "oid"), ("opfname", ScalarType "name"),
->            ("opfnamespace", ScalarType "oid"), ("opfowner", ScalarType "oid")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_pltemplate"
->           [("tmplname", ScalarType "name"),
->            ("tmpltrusted", ScalarType "bool"),
->            ("tmpldbacreate", ScalarType "bool"),
->            ("tmplhandler", ScalarType "text"),
->            ("tmplinline", ScalarType "text"),
->            ("tmplvalidator", ScalarType "text"),
->            ("tmpllibrary", ScalarType "text"),
->            ("tmplacl", ArrayType (ScalarType "aclitem"))]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_proc"
->           [("proname", ScalarType "name"),
->            ("pronamespace", ScalarType "oid"), ("proowner", ScalarType "oid"),
->            ("prolang", ScalarType "oid"), ("procost", ScalarType "float4"),
->            ("prorows", ScalarType "float4"),
->            ("provariadic", ScalarType "oid"), ("proisagg", ScalarType "bool"),
->            ("proiswindow", ScalarType "bool"),
->            ("prosecdef", ScalarType "bool"),
->            ("proisstrict", ScalarType "bool"),
->            ("proretset", ScalarType "bool"),
->            ("provolatile", ScalarType "char"),
->            ("pronargs", ScalarType "int2"),
->            ("pronargdefaults", ScalarType "int2"),
->            ("prorettype", ScalarType "oid"),
->            ("proargtypes", ScalarType "oidvector"),
->            ("proallargtypes", ArrayType (ScalarType "oid")),
->            ("proargmodes", ArrayType (ScalarType "char")),
->            ("proargnames", ArrayType (ScalarType "text")),
->            ("proargdefaults", ScalarType "pg_node_tree"),
->            ("prosrc", ScalarType "text"), ("probin", ScalarType "text"),
->            ("proconfig", ArrayType (ScalarType "text")),
->            ("proacl", ArrayType (ScalarType "aclitem"))]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_rewrite"
->           [("rulename", ScalarType "name"), ("ev_class", ScalarType "oid"),
->            ("ev_attr", ScalarType "int2"), ("ev_type", ScalarType "char"),
->            ("ev_enabled", ScalarType "char"),
->            ("is_instead", ScalarType "bool"),
->            ("ev_qual", ScalarType "pg_node_tree"),
->            ("ev_action", ScalarType "pg_node_tree")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_seclabel"
->           [("objoid", ScalarType "oid"), ("classoid", ScalarType "oid"),
->            ("objsubid", ScalarType "int4"), ("provider", ScalarType "text"),
->            ("label", ScalarType "text")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_shdepend"
->           [("dbid", ScalarType "oid"), ("classid", ScalarType "oid"),
->            ("objid", ScalarType "oid"), ("objsubid", ScalarType "int4"),
->            ("refclassid", ScalarType "oid"), ("refobjid", ScalarType "oid"),
->            ("deptype", ScalarType "char")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_shdescription"
->           [("objoid", ScalarType "oid"), ("classoid", ScalarType "oid"),
->            ("description", ScalarType "text")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_statistic"
->           [("starelid", ScalarType "oid"), ("staattnum", ScalarType "int2"),
->            ("stainherit", ScalarType "bool"),
->            ("stanullfrac", ScalarType "float4"),
->            ("stawidth", ScalarType "int4"),
->            ("stadistinct", ScalarType "float4"),
->            ("stakind1", ScalarType "int2"), ("stakind2", ScalarType "int2"),
->            ("stakind3", ScalarType "int2"), ("stakind4", ScalarType "int2"),
->            ("staop1", ScalarType "oid"), ("staop2", ScalarType "oid"),
->            ("staop3", ScalarType "oid"), ("staop4", ScalarType "oid"),
->            ("stanumbers1", ArrayType (ScalarType "float4")),
->            ("stanumbers2", ArrayType (ScalarType "float4")),
->            ("stanumbers3", ArrayType (ScalarType "float4")),
->            ("stanumbers4", ArrayType (ScalarType "float4")),
->            ("stavalues1", Pseudo AnyArray), ("stavalues2", Pseudo AnyArray),
->            ("stavalues3", Pseudo AnyArray), ("stavalues4", Pseudo AnyArray)]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_tablespace"
->           [("spcname", ScalarType "name"), ("spcowner", ScalarType "oid"),
->            ("spclocation", ScalarType "text"),
->            ("spcacl", ArrayType (ScalarType "aclitem")),
->            ("spcoptions", ArrayType (ScalarType "text"))]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_trigger"
->           [("tgrelid", ScalarType "oid"), ("tgname", ScalarType "name"),
->            ("tgfoid", ScalarType "oid"), ("tgtype", ScalarType "int2"),
->            ("tgenabled", ScalarType "char"),
->            ("tgisinternal", ScalarType "bool"),
->            ("tgconstrrelid", ScalarType "oid"),
->            ("tgconstrindid", ScalarType "oid"),
->            ("tgconstraint", ScalarType "oid"),
->            ("tgdeferrable", ScalarType "bool"),
->            ("tginitdeferred", ScalarType "bool"),
->            ("tgnargs", ScalarType "int2"),
->            ("tgattr", ScalarType "int2vector"),
->            ("tgargs", ScalarType "bytea"),
->            ("tgqual", ScalarType "pg_node_tree")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_ts_config"
->           [("cfgname", ScalarType "name"),
->            ("cfgnamespace", ScalarType "oid"), ("cfgowner", ScalarType "oid"),
->            ("cfgparser", ScalarType "oid")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_ts_config_map"
->           [("mapcfg", ScalarType "oid"), ("maptokentype", ScalarType "int4"),
->            ("mapseqno", ScalarType "int4"), ("mapdict", ScalarType "oid")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_ts_dict"
->           [("dictname", ScalarType "name"),
->            ("dictnamespace", ScalarType "oid"),
->            ("dictowner", ScalarType "oid"),
->            ("dicttemplate", ScalarType "oid"),
->            ("dictinitoption", ScalarType "text")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_ts_parser"
->           [("prsname", ScalarType "name"),
->            ("prsnamespace", ScalarType "oid"),
->            ("prsstart", ScalarType "regproc"),
->            ("prstoken", ScalarType "regproc"),
->            ("prsend", ScalarType "regproc"),
->            ("prsheadline", ScalarType "regproc"),
->            ("prslextype", ScalarType "regproc")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_ts_template"
->           [("tmplname", ScalarType "name"),
->            ("tmplnamespace", ScalarType "oid"),
->            ("tmplinit", ScalarType "regproc"),
->            ("tmpllexize", ScalarType "regproc")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_type"
->           [("typname", ScalarType "name"),
->            ("typnamespace", ScalarType "oid"), ("typowner", ScalarType "oid"),
->            ("typlen", ScalarType "int2"), ("typbyval", ScalarType "bool"),
->            ("typtype", ScalarType "char"), ("typcategory", ScalarType "char"),
->            ("typispreferred", ScalarType "bool"),
->            ("typisdefined", ScalarType "bool"),
->            ("typdelim", ScalarType "char"), ("typrelid", ScalarType "oid"),
->            ("typelem", ScalarType "oid"), ("typarray", ScalarType "oid"),
->            ("typinput", ScalarType "regproc"),
->            ("typoutput", ScalarType "regproc"),
->            ("typreceive", ScalarType "regproc"),
->            ("typsend", ScalarType "regproc"),
->            ("typmodin", ScalarType "regproc"),
->            ("typmodout", ScalarType "regproc"),
->            ("typanalyze", ScalarType "regproc"),
->            ("typalign", ScalarType "char"), ("typstorage", ScalarType "char"),
->            ("typnotnull", ScalarType "bool"),
->            ("typbasetype", ScalarType "oid"),
->            ("typtypmod", ScalarType "int4"), ("typndims", ScalarType "int4"),
->            ("typcollation", ScalarType "oid"),
->            ("typdefaultbin", ScalarType "pg_node_tree"),
->            ("typdefault", ScalarType "text")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "pg_user_mapping"
->           [("umuser", ScalarType "oid"), ("umserver", ScalarType "oid"),
->            ("umoptions", ArrayType (ScalarType "text"))]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("oid", ScalarType "oid"),
->            ("ctid", ScalarType "tid")],
->         CatCreateTable "information_schema.sql_features"
->           [("feature_id", DomainType "information_schema.character_data"),
->            ("feature_name", DomainType "information_schema.character_data"),
->            ("sub_feature_id", DomainType "information_schema.character_data"),
->            ("sub_feature_name",
->             DomainType "information_schema.character_data"),
->            ("is_supported", DomainType "information_schema.yes_or_no"),
->            ("is_verified_by", DomainType "information_schema.character_data"),
->            ("comments", DomainType "information_schema.character_data")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "information_schema.sql_implementation_info"
->           [("implementation_info_id",
->             DomainType "information_schema.character_data"),
->            ("implementation_info_name",
->             DomainType "information_schema.character_data"),
->            ("integer_value", DomainType "information_schema.cardinal_number"),
->            ("character_value",
->             DomainType "information_schema.character_data"),
->            ("comments", DomainType "information_schema.character_data")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "information_schema.sql_languages"
->           [("sql_language_source",
->             DomainType "information_schema.character_data"),
->            ("sql_language_year",
->             DomainType "information_schema.character_data"),
->            ("sql_language_conformance",
->             DomainType "information_schema.character_data"),
->            ("sql_language_integrity",
->             DomainType "information_schema.character_data"),
->            ("sql_language_implementation",
->             DomainType "information_schema.character_data"),
->            ("sql_language_binding_style",
->             DomainType "information_schema.character_data"),
->            ("sql_language_programming_language",
->             DomainType "information_schema.character_data")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "information_schema.sql_packages"
->           [("feature_id", DomainType "information_schema.character_data"),
->            ("feature_name", DomainType "information_schema.character_data"),
->            ("is_supported", DomainType "information_schema.yes_or_no"),
->            ("is_verified_by", DomainType "information_schema.character_data"),
->            ("comments", DomainType "information_schema.character_data")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "information_schema.sql_parts"
->           [("feature_id", DomainType "information_schema.character_data"),
->            ("feature_name", DomainType "information_schema.character_data"),
->            ("is_supported", DomainType "information_schema.yes_or_no"),
->            ("is_verified_by", DomainType "information_schema.character_data"),
->            ("comments", DomainType "information_schema.character_data")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "information_schema.sql_sizing"
->           [("sizing_id", DomainType "information_schema.cardinal_number"),
->            ("sizing_name", DomainType "information_schema.character_data"),
->            ("supported_value",
->             DomainType "information_schema.cardinal_number"),
->            ("comments", DomainType "information_schema.character_data")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateTable "information_schema.sql_sizing_profiles"
->           [("sizing_id", DomainType "information_schema.cardinal_number"),
->            ("sizing_name", DomainType "information_schema.character_data"),
->            ("profile_id", DomainType "information_schema.character_data"),
->            ("required_value",
->             DomainType "information_schema.cardinal_number"),
->            ("comments", DomainType "information_schema.character_data")]
->           [("tableoid", ScalarType "oid"), ("cmax", ScalarType "cid"),
->            ("xmax", ScalarType "xid"), ("cmin", ScalarType "cid"),
->            ("xmin", ScalarType "xid"), ("ctid", ScalarType "tid")],
->         CatCreateView "information_schema._pg_foreign_data_wrappers"
->           [("oid", ScalarType "oid"), ("fdwowner", ScalarType "oid"),
->            ("fdwoptions", ArrayType (ScalarType "text")),
->            ("foreign_data_wrapper_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_data_wrapper_name",
->             DomainType "information_schema.sql_identifier"),
->            ("authorization_identifier",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_data_wrapper_language",
->             DomainType "information_schema.character_data")],
->         CatCreateView "information_schema._pg_foreign_servers"
->           [("oid", ScalarType "oid"),
->            ("srvoptions", ArrayType (ScalarType "text")),
->            ("foreign_server_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_server_name",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_data_wrapper_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_data_wrapper_name",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_server_type",
->             DomainType "information_schema.character_data"),
->            ("foreign_server_version",
->             DomainType "information_schema.character_data"),
->            ("authorization_identifier",
->             DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema._pg_foreign_tables"
->           [("foreign_table_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_table_schema", ScalarType "name"),
->            ("foreign_table_name", ScalarType "name"),
->            ("ftoptions", ArrayType (ScalarType "text")),
->            ("foreign_server_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_server_name",
->             DomainType "information_schema.sql_identifier"),
->            ("authorization_identifier",
->             DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema._pg_user_mappings"
->           [("oid", ScalarType "oid"),
->            ("umoptions", ArrayType (ScalarType "text")),
->            ("umuser", ScalarType "oid"),
->            ("authorization_identifier",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_server_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_server_name",
->             DomainType "information_schema.sql_identifier"),
->            ("srvowner", DomainType "information_schema.sql_identifier")],
->         CatCreateView
->           "information_schema.administrable_role_authorizations"
->           [("grantee", DomainType "information_schema.sql_identifier"),
->            ("role_name", DomainType "information_schema.sql_identifier"),
->            ("is_grantable", DomainType "information_schema.yes_or_no")],
->         CatCreateView "information_schema.applicable_roles"
->           [("grantee", DomainType "information_schema.sql_identifier"),
->            ("role_name", DomainType "information_schema.sql_identifier"),
->            ("is_grantable", DomainType "information_schema.yes_or_no")],
->         CatCreateView "information_schema.attributes"
->           [("udt_catalog", DomainType "information_schema.sql_identifier"),
->            ("udt_schema", DomainType "information_schema.sql_identifier"),
->            ("udt_name", DomainType "information_schema.sql_identifier"),
->            ("attribute_name", DomainType "information_schema.sql_identifier"),
->            ("ordinal_position",
->             DomainType "information_schema.cardinal_number"),
->            ("attribute_default",
->             DomainType "information_schema.character_data"),
->            ("is_nullable", DomainType "information_schema.yes_or_no"),
->            ("data_type", DomainType "information_schema.character_data"),
->            ("character_maximum_length",
->             DomainType "information_schema.cardinal_number"),
->            ("character_octet_length",
->             DomainType "information_schema.cardinal_number"),
->            ("character_set_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("character_set_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("character_set_name",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_name", DomainType "information_schema.sql_identifier"),
->            ("numeric_precision",
->             DomainType "information_schema.cardinal_number"),
->            ("numeric_precision_radix",
->             DomainType "information_schema.cardinal_number"),
->            ("numeric_scale", DomainType "information_schema.cardinal_number"),
->            ("datetime_precision",
->             DomainType "information_schema.cardinal_number"),
->            ("interval_type", DomainType "information_schema.character_data"),
->            ("interval_precision",
->             DomainType "information_schema.character_data"),
->            ("attribute_udt_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("attribute_udt_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("attribute_udt_name",
->             DomainType "information_schema.sql_identifier"),
->            ("scope_catalog", DomainType "information_schema.sql_identifier"),
->            ("scope_schema", DomainType "information_schema.sql_identifier"),
->            ("scope_name", DomainType "information_schema.sql_identifier"),
->            ("maximum_cardinality",
->             DomainType "information_schema.cardinal_number"),
->            ("dtd_identifier", DomainType "information_schema.sql_identifier"),
->            ("is_derived_reference_attribute",
->             DomainType "information_schema.yes_or_no")],
->         CatCreateView "information_schema.character_sets"
->           [("character_set_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("character_set_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("character_set_name",
->             DomainType "information_schema.sql_identifier"),
->            ("character_repertoire",
->             DomainType "information_schema.sql_identifier"),
->            ("form_of_use", DomainType "information_schema.sql_identifier"),
->            ("default_collate_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("default_collate_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("default_collate_name",
->             DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.check_constraint_routine_usage"
->           [("constraint_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("constraint_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("constraint_name",
->             DomainType "information_schema.sql_identifier"),
->            ("specific_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("specific_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("specific_name", DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.check_constraints"
->           [("constraint_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("constraint_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("constraint_name",
->             DomainType "information_schema.sql_identifier"),
->            ("check_clause", DomainType "information_schema.character_data")],
->         CatCreateView
->           "information_schema.collation_character_set_applicability"
->           [("collation_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_name", DomainType "information_schema.sql_identifier"),
->            ("character_set_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("character_set_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("character_set_name",
->             DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.collations"
->           [("collation_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_name", DomainType "information_schema.sql_identifier"),
->            ("pad_attribute", DomainType "information_schema.character_data")],
->         CatCreateView "information_schema.column_domain_usage"
->           [("domain_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("domain_schema", DomainType "information_schema.sql_identifier"),
->            ("domain_name", DomainType "information_schema.sql_identifier"),
->            ("table_catalog", DomainType "information_schema.sql_identifier"),
->            ("table_schema", DomainType "information_schema.sql_identifier"),
->            ("table_name", DomainType "information_schema.sql_identifier"),
->            ("column_name", DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.column_privileges"
->           [("grantor", DomainType "information_schema.sql_identifier"),
->            ("grantee", DomainType "information_schema.sql_identifier"),
->            ("table_catalog", DomainType "information_schema.sql_identifier"),
->            ("table_schema", DomainType "information_schema.sql_identifier"),
->            ("table_name", DomainType "information_schema.sql_identifier"),
->            ("column_name", DomainType "information_schema.sql_identifier"),
->            ("privilege_type", DomainType "information_schema.character_data"),
->            ("is_grantable", DomainType "information_schema.yes_or_no")],
->         CatCreateView "information_schema.column_udt_usage"
->           [("udt_catalog", DomainType "information_schema.sql_identifier"),
->            ("udt_schema", DomainType "information_schema.sql_identifier"),
->            ("udt_name", DomainType "information_schema.sql_identifier"),
->            ("table_catalog", DomainType "information_schema.sql_identifier"),
->            ("table_schema", DomainType "information_schema.sql_identifier"),
->            ("table_name", DomainType "information_schema.sql_identifier"),
->            ("column_name", DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.columns"
->           [("table_catalog", DomainType "information_schema.sql_identifier"),
->            ("table_schema", DomainType "information_schema.sql_identifier"),
->            ("table_name", DomainType "information_schema.sql_identifier"),
->            ("column_name", DomainType "information_schema.sql_identifier"),
->            ("ordinal_position",
->             DomainType "information_schema.cardinal_number"),
->            ("column_default", DomainType "information_schema.character_data"),
->            ("is_nullable", DomainType "information_schema.yes_or_no"),
->            ("data_type", DomainType "information_schema.character_data"),
->            ("character_maximum_length",
->             DomainType "information_schema.cardinal_number"),
->            ("character_octet_length",
->             DomainType "information_schema.cardinal_number"),
->            ("numeric_precision",
->             DomainType "information_schema.cardinal_number"),
->            ("numeric_precision_radix",
->             DomainType "information_schema.cardinal_number"),
->            ("numeric_scale", DomainType "information_schema.cardinal_number"),
->            ("datetime_precision",
->             DomainType "information_schema.cardinal_number"),
->            ("interval_type", DomainType "information_schema.character_data"),
->            ("interval_precision",
->             DomainType "information_schema.character_data"),
->            ("character_set_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("character_set_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("character_set_name",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_name", DomainType "information_schema.sql_identifier"),
->            ("domain_catalog", DomainType "information_schema.sql_identifier"),
->            ("domain_schema", DomainType "information_schema.sql_identifier"),
->            ("domain_name", DomainType "information_schema.sql_identifier"),
->            ("udt_catalog", DomainType "information_schema.sql_identifier"),
->            ("udt_schema", DomainType "information_schema.sql_identifier"),
->            ("udt_name", DomainType "information_schema.sql_identifier"),
->            ("scope_catalog", DomainType "information_schema.sql_identifier"),
->            ("scope_schema", DomainType "information_schema.sql_identifier"),
->            ("scope_name", DomainType "information_schema.sql_identifier"),
->            ("maximum_cardinality",
->             DomainType "information_schema.cardinal_number"),
->            ("dtd_identifier", DomainType "information_schema.sql_identifier"),
->            ("is_self_referencing", DomainType "information_schema.yes_or_no"),
->            ("is_identity", DomainType "information_schema.yes_or_no"),
->            ("identity_generation",
->             DomainType "information_schema.character_data"),
->            ("identity_start", DomainType "information_schema.character_data"),
->            ("identity_increment",
->             DomainType "information_schema.character_data"),
->            ("identity_maximum",
->             DomainType "information_schema.character_data"),
->            ("identity_minimum",
->             DomainType "information_schema.character_data"),
->            ("identity_cycle", DomainType "information_schema.yes_or_no"),
->            ("is_generated", DomainType "information_schema.character_data"),
->            ("generation_expression",
->             DomainType "information_schema.character_data"),
->            ("is_updatable", DomainType "information_schema.yes_or_no")],
->         CatCreateView "information_schema.constraint_column_usage"
->           [("table_catalog", DomainType "information_schema.sql_identifier"),
->            ("table_schema", DomainType "information_schema.sql_identifier"),
->            ("table_name", DomainType "information_schema.sql_identifier"),
->            ("column_name", DomainType "information_schema.sql_identifier"),
->            ("constraint_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("constraint_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("constraint_name",
->             DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.constraint_table_usage"
->           [("table_catalog", DomainType "information_schema.sql_identifier"),
->            ("table_schema", DomainType "information_schema.sql_identifier"),
->            ("table_name", DomainType "information_schema.sql_identifier"),
->            ("constraint_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("constraint_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("constraint_name",
->             DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.data_type_privileges"
->           [("object_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("object_schema", DomainType "information_schema.sql_identifier"),
->            ("object_name", DomainType "information_schema.sql_identifier"),
->            ("object_type", DomainType "information_schema.character_data"),
->            ("dtd_identifier",
->             DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.domain_constraints"
->           [("constraint_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("constraint_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("constraint_name",
->             DomainType "information_schema.sql_identifier"),
->            ("domain_catalog", DomainType "information_schema.sql_identifier"),
->            ("domain_schema", DomainType "information_schema.sql_identifier"),
->            ("domain_name", DomainType "information_schema.sql_identifier"),
->            ("is_deferrable", DomainType "information_schema.yes_or_no"),
->            ("initially_deferred", DomainType "information_schema.yes_or_no")],
->         CatCreateView "information_schema.domain_udt_usage"
->           [("udt_catalog", DomainType "information_schema.sql_identifier"),
->            ("udt_schema", DomainType "information_schema.sql_identifier"),
->            ("udt_name", DomainType "information_schema.sql_identifier"),
->            ("domain_catalog", DomainType "information_schema.sql_identifier"),
->            ("domain_schema", DomainType "information_schema.sql_identifier"),
->            ("domain_name", DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.domains"
->           [("domain_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("domain_schema", DomainType "information_schema.sql_identifier"),
->            ("domain_name", DomainType "information_schema.sql_identifier"),
->            ("data_type", DomainType "information_schema.character_data"),
->            ("character_maximum_length",
->             DomainType "information_schema.cardinal_number"),
->            ("character_octet_length",
->             DomainType "information_schema.cardinal_number"),
->            ("character_set_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("character_set_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("character_set_name",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_name", DomainType "information_schema.sql_identifier"),
->            ("numeric_precision",
->             DomainType "information_schema.cardinal_number"),
->            ("numeric_precision_radix",
->             DomainType "information_schema.cardinal_number"),
->            ("numeric_scale", DomainType "information_schema.cardinal_number"),
->            ("datetime_precision",
->             DomainType "information_schema.cardinal_number"),
->            ("interval_type", DomainType "information_schema.character_data"),
->            ("interval_precision",
->             DomainType "information_schema.character_data"),
->            ("domain_default", DomainType "information_schema.character_data"),
->            ("udt_catalog", DomainType "information_schema.sql_identifier"),
->            ("udt_schema", DomainType "information_schema.sql_identifier"),
->            ("udt_name", DomainType "information_schema.sql_identifier"),
->            ("scope_catalog", DomainType "information_schema.sql_identifier"),
->            ("scope_schema", DomainType "information_schema.sql_identifier"),
->            ("scope_name", DomainType "information_schema.sql_identifier"),
->            ("maximum_cardinality",
->             DomainType "information_schema.cardinal_number"),
->            ("dtd_identifier",
->             DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.element_types"
->           [("object_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("object_schema", DomainType "information_schema.sql_identifier"),
->            ("object_name", DomainType "information_schema.sql_identifier"),
->            ("object_type", DomainType "information_schema.character_data"),
->            ("collection_type_identifier",
->             DomainType "information_schema.sql_identifier"),
->            ("data_type", DomainType "information_schema.character_data"),
->            ("character_maximum_length",
->             DomainType "information_schema.cardinal_number"),
->            ("character_octet_length",
->             DomainType "information_schema.cardinal_number"),
->            ("character_set_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("character_set_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("character_set_name",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_name", DomainType "information_schema.sql_identifier"),
->            ("numeric_precision",
->             DomainType "information_schema.cardinal_number"),
->            ("numeric_precision_radix",
->             DomainType "information_schema.cardinal_number"),
->            ("numeric_scale", DomainType "information_schema.cardinal_number"),
->            ("datetime_precision",
->             DomainType "information_schema.cardinal_number"),
->            ("interval_type", DomainType "information_schema.character_data"),
->            ("interval_precision",
->             DomainType "information_schema.character_data"),
->            ("domain_default", DomainType "information_schema.character_data"),
->            ("udt_catalog", DomainType "information_schema.sql_identifier"),
->            ("udt_schema", DomainType "information_schema.sql_identifier"),
->            ("udt_name", DomainType "information_schema.sql_identifier"),
->            ("scope_catalog", DomainType "information_schema.sql_identifier"),
->            ("scope_schema", DomainType "information_schema.sql_identifier"),
->            ("scope_name", DomainType "information_schema.sql_identifier"),
->            ("maximum_cardinality",
->             DomainType "information_schema.cardinal_number"),
->            ("dtd_identifier",
->             DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.enabled_roles"
->           [("role_name", DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.foreign_data_wrapper_options"
->           [("foreign_data_wrapper_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_data_wrapper_name",
->             DomainType "information_schema.sql_identifier"),
->            ("option_name", DomainType "information_schema.sql_identifier"),
->            ("option_value", DomainType "information_schema.character_data")],
->         CatCreateView "information_schema.foreign_data_wrappers"
->           [("foreign_data_wrapper_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_data_wrapper_name",
->             DomainType "information_schema.sql_identifier"),
->            ("authorization_identifier",
->             DomainType "information_schema.sql_identifier"),
->            ("library_name", DomainType "information_schema.character_data"),
->            ("foreign_data_wrapper_language",
->             DomainType "information_schema.character_data")],
->         CatCreateView "information_schema.foreign_server_options"
->           [("foreign_server_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_server_name",
->             DomainType "information_schema.sql_identifier"),
->            ("option_name", DomainType "information_schema.sql_identifier"),
->            ("option_value", DomainType "information_schema.character_data")],
->         CatCreateView "information_schema.foreign_servers"
->           [("foreign_server_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_server_name",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_data_wrapper_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_data_wrapper_name",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_server_type",
->             DomainType "information_schema.character_data"),
->            ("foreign_server_version",
->             DomainType "information_schema.character_data"),
->            ("authorization_identifier",
->             DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.foreign_table_options"
->           [("foreign_table_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_table_schema", ScalarType "name"),
->            ("foreign_table_name", ScalarType "name"),
->            ("option_name", DomainType "information_schema.sql_identifier"),
->            ("option_value", DomainType "information_schema.character_data")],
->         CatCreateView "information_schema.foreign_tables"
->           [("foreign_table_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_table_schema", ScalarType "name"),
->            ("foreign_table_name", ScalarType "name"),
->            ("foreign_server_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_server_name",
->             DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.information_schema_catalog_name"
->           [("catalog_name", DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.key_column_usage"
->           [("constraint_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("constraint_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("constraint_name",
->             DomainType "information_schema.sql_identifier"),
->            ("table_catalog", DomainType "information_schema.sql_identifier"),
->            ("table_schema", DomainType "information_schema.sql_identifier"),
->            ("table_name", DomainType "information_schema.sql_identifier"),
->            ("column_name", DomainType "information_schema.sql_identifier"),
->            ("ordinal_position",
->             DomainType "information_schema.cardinal_number"),
->            ("position_in_unique_constraint",
->             DomainType "information_schema.cardinal_number")],
->         CatCreateView "information_schema.parameters"
->           [("specific_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("specific_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("specific_name", DomainType "information_schema.sql_identifier"),
->            ("ordinal_position",
->             DomainType "information_schema.cardinal_number"),
->            ("parameter_mode", DomainType "information_schema.character_data"),
->            ("is_result", DomainType "information_schema.yes_or_no"),
->            ("as_locator", DomainType "information_schema.yes_or_no"),
->            ("parameter_name", DomainType "information_schema.sql_identifier"),
->            ("data_type", DomainType "information_schema.character_data"),
->            ("character_maximum_length",
->             DomainType "information_schema.cardinal_number"),
->            ("character_octet_length",
->             DomainType "information_schema.cardinal_number"),
->            ("character_set_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("character_set_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("character_set_name",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_name", DomainType "information_schema.sql_identifier"),
->            ("numeric_precision",
->             DomainType "information_schema.cardinal_number"),
->            ("numeric_precision_radix",
->             DomainType "information_schema.cardinal_number"),
->            ("numeric_scale", DomainType "information_schema.cardinal_number"),
->            ("datetime_precision",
->             DomainType "information_schema.cardinal_number"),
->            ("interval_type", DomainType "information_schema.character_data"),
->            ("interval_precision",
->             DomainType "information_schema.character_data"),
->            ("udt_catalog", DomainType "information_schema.sql_identifier"),
->            ("udt_schema", DomainType "information_schema.sql_identifier"),
->            ("udt_name", DomainType "information_schema.sql_identifier"),
->            ("scope_catalog", DomainType "information_schema.sql_identifier"),
->            ("scope_schema", DomainType "information_schema.sql_identifier"),
->            ("scope_name", DomainType "information_schema.sql_identifier"),
->            ("maximum_cardinality",
->             DomainType "information_schema.cardinal_number"),
->            ("dtd_identifier",
->             DomainType "information_schema.sql_identifier")],
->         CatCreateView "pg_available_extension_versions"
->           [("name", ScalarType "name"), ("version", ScalarType "text"),
->            ("installed", ScalarType "bool"), ("superuser", ScalarType "bool"),
->            ("relocatable", ScalarType "bool"), ("schema", ScalarType "name"),
->            ("requires", ArrayType (ScalarType "name")),
->            ("comment", ScalarType "text")],
->         CatCreateView "pg_available_extensions"
->           [("name", ScalarType "name"),
->            ("default_version", ScalarType "text"),
->            ("installed_version", ScalarType "text"),
->            ("comment", ScalarType "text")],
->         CatCreateView "pg_cursors"
->           [("name", ScalarType "text"), ("statement", ScalarType "text"),
->            ("is_holdable", ScalarType "bool"),
->            ("is_binary", ScalarType "bool"),
->            ("is_scrollable", ScalarType "bool"),
->            ("creation_time", ScalarType "timestamptz")],
->         CatCreateView "pg_group"
->           [("groname", ScalarType "name"), ("grosysid", ScalarType "oid"),
->            ("grolist", ArrayType (ScalarType "oid"))],
->         CatCreateView "pg_indexes"
->           [("schemaname", ScalarType "name"),
->            ("tablename", ScalarType "name"), ("indexname", ScalarType "name"),
->            ("tablespace", ScalarType "name"),
->            ("indexdef", ScalarType "text")],
->         CatCreateView "pg_locks"
->           [("locktype", ScalarType "text"), ("database", ScalarType "oid"),
->            ("relation", ScalarType "oid"), ("page", ScalarType "int4"),
->            ("tuple", ScalarType "int2"), ("virtualxid", ScalarType "text"),
->            ("transactionid", ScalarType "xid"), ("classid", ScalarType "oid"),
->            ("objid", ScalarType "oid"), ("objsubid", ScalarType "int2"),
->            ("virtualtransaction", ScalarType "text"),
->            ("pid", ScalarType "int4"), ("mode", ScalarType "text"),
->            ("granted", ScalarType "bool")],
->         CatCreateView "pg_prepared_statements"
->           [("name", ScalarType "text"), ("statement", ScalarType "text"),
->            ("prepare_time", ScalarType "timestamptz"),
->            ("parameter_types", ArrayType (ScalarType "regtype")),
->            ("from_sql", ScalarType "bool")],
->         CatCreateView "pg_prepared_xacts"
->           [("transaction", ScalarType "xid"), ("gid", ScalarType "text"),
->            ("prepared", ScalarType "timestamptz"),
->            ("owner", ScalarType "name"), ("database", ScalarType "name")],
->         CatCreateView "pg_roles"
->           [("rolname", ScalarType "name"), ("rolsuper", ScalarType "bool"),
->            ("rolinherit", ScalarType "bool"),
->            ("rolcreaterole", ScalarType "bool"),
->            ("rolcreatedb", ScalarType "bool"),
->            ("rolcatupdate", ScalarType "bool"),
->            ("rolcanlogin", ScalarType "bool"),
->            ("rolreplication", ScalarType "bool"),
->            ("rolconnlimit", ScalarType "int4"),
->            ("rolpassword", ScalarType "text"),
->            ("rolvaliduntil", ScalarType "timestamptz"),
->            ("rolconfig", ArrayType (ScalarType "text")),
->            ("oid", ScalarType "oid")],
->         CatCreateView "pg_rules"
->           [("schemaname", ScalarType "name"),
->            ("tablename", ScalarType "name"), ("rulename", ScalarType "name"),
->            ("definition", ScalarType "text")],
->         CatCreateView "pg_seclabels"
->           [("objoid", ScalarType "oid"), ("classoid", ScalarType "oid"),
->            ("objsubid", ScalarType "int4"), ("objtype", ScalarType "text"),
->            ("objnamespace", ScalarType "oid"), ("objname", ScalarType "text"),
->            ("provider", ScalarType "text"), ("label", ScalarType "text")],
->         CatCreateView "pg_settings"
->           [("name", ScalarType "text"), ("setting", ScalarType "text"),
->            ("unit", ScalarType "text"), ("category", ScalarType "text"),
->            ("short_desc", ScalarType "text"),
->            ("extra_desc", ScalarType "text"), ("context", ScalarType "text"),
->            ("vartype", ScalarType "text"), ("source", ScalarType "text"),
->            ("min_val", ScalarType "text"), ("max_val", ScalarType "text"),
->            ("enumvals", ArrayType (ScalarType "text")),
->            ("boot_val", ScalarType "text"), ("reset_val", ScalarType "text"),
->            ("sourcefile", ScalarType "text"),
->            ("sourceline", ScalarType "int4")],
->         CatCreateView "pg_shadow"
->           [("usename", ScalarType "name"), ("usesysid", ScalarType "oid"),
->            ("usecreatedb", ScalarType "bool"),
->            ("usesuper", ScalarType "bool"), ("usecatupd", ScalarType "bool"),
->            ("userepl", ScalarType "bool"), ("passwd", ScalarType "text"),
->            ("valuntil", ScalarType "abstime"),
->            ("useconfig", ArrayType (ScalarType "text"))],
->         CatCreateView "pg_stat_activity"
->           [("datid", ScalarType "oid"), ("datname", ScalarType "name"),
->            ("procpid", ScalarType "int4"), ("usesysid", ScalarType "oid"),
->            ("usename", ScalarType "name"),
->            ("application_name", ScalarType "text"),
->            ("client_addr", ScalarType "inet"),
->            ("client_hostname", ScalarType "text"),
->            ("client_port", ScalarType "int4"),
->            ("backend_start", ScalarType "timestamptz"),
->            ("xact_start", ScalarType "timestamptz"),
->            ("query_start", ScalarType "timestamptz"),
->            ("waiting", ScalarType "bool"),
->            ("current_query", ScalarType "text")],
->         CatCreateView "pg_stat_all_indexes"
->           [("relid", ScalarType "oid"), ("indexrelid", ScalarType "oid"),
->            ("schemaname", ScalarType "name"), ("relname", ScalarType "name"),
->            ("indexrelname", ScalarType "name"),
->            ("idx_scan", ScalarType "int8"),
->            ("idx_tup_read", ScalarType "int8"),
->            ("idx_tup_fetch", ScalarType "int8")],
->         CatCreateView "pg_stat_all_tables"
->           [("relid", ScalarType "oid"), ("schemaname", ScalarType "name"),
->            ("relname", ScalarType "name"), ("seq_scan", ScalarType "int8"),
->            ("seq_tup_read", ScalarType "int8"),
->            ("idx_scan", ScalarType "int8"),
->            ("idx_tup_fetch", ScalarType "int8"),
->            ("n_tup_ins", ScalarType "int8"), ("n_tup_upd", ScalarType "int8"),
->            ("n_tup_del", ScalarType "int8"),
->            ("n_tup_hot_upd", ScalarType "int8"),
->            ("n_live_tup", ScalarType "int8"),
->            ("n_dead_tup", ScalarType "int8"),
->            ("last_vacuum", ScalarType "timestamptz"),
->            ("last_autovacuum", ScalarType "timestamptz"),
->            ("last_analyze", ScalarType "timestamptz"),
->            ("last_autoanalyze", ScalarType "timestamptz"),
->            ("vacuum_count", ScalarType "int8"),
->            ("autovacuum_count", ScalarType "int8"),
->            ("analyze_count", ScalarType "int8"),
->            ("autoanalyze_count", ScalarType "int8")],
->         CatCreateView "pg_stat_bgwriter"
->           [("checkpoints_timed", ScalarType "int8"),
->            ("checkpoints_req", ScalarType "int8"),
->            ("buffers_checkpoint", ScalarType "int8"),
->            ("buffers_clean", ScalarType "int8"),
->            ("maxwritten_clean", ScalarType "int8"),
->            ("buffers_backend", ScalarType "int8"),
->            ("buffers_backend_fsync", ScalarType "int8"),
->            ("buffers_alloc", ScalarType "int8"),
->            ("stats_reset", ScalarType "timestamptz")],
->         CatCreateView "pg_stat_database"
->           [("datid", ScalarType "oid"), ("datname", ScalarType "name"),
->            ("numbackends", ScalarType "int4"),
->            ("xact_commit", ScalarType "int8"),
->            ("xact_rollback", ScalarType "int8"),
->            ("blks_read", ScalarType "int8"), ("blks_hit", ScalarType "int8"),
->            ("tup_returned", ScalarType "int8"),
->            ("tup_fetched", ScalarType "int8"),
->            ("tup_inserted", ScalarType "int8"),
->            ("tup_updated", ScalarType "int8"),
->            ("tup_deleted", ScalarType "int8"),
->            ("conflicts", ScalarType "int8"),
->            ("stats_reset", ScalarType "timestamptz")],
->         CatCreateView "pg_stat_database_conflicts"
->           [("datid", ScalarType "oid"), ("datname", ScalarType "name"),
->            ("confl_tablespace", ScalarType "int8"),
->            ("confl_lock", ScalarType "int8"),
->            ("confl_snapshot", ScalarType "int8"),
->            ("confl_bufferpin", ScalarType "int8"),
->            ("confl_deadlock", ScalarType "int8")],
->         CatCreateView "pg_stat_replication"
->           [("procpid", ScalarType "int4"), ("usesysid", ScalarType "oid"),
->            ("usename", ScalarType "name"),
->            ("application_name", ScalarType "text"),
->            ("client_addr", ScalarType "inet"),
->            ("client_hostname", ScalarType "text"),
->            ("client_port", ScalarType "int4"),
->            ("backend_start", ScalarType "timestamptz"),
->            ("state", ScalarType "text"), ("sent_location", ScalarType "text"),
->            ("write_location", ScalarType "text"),
->            ("flush_location", ScalarType "text"),
->            ("replay_location", ScalarType "text"),
->            ("sync_priority", ScalarType "int4"),
->            ("sync_state", ScalarType "text")],
->         CatCreateView "pg_stat_sys_indexes"
->           [("relid", ScalarType "oid"), ("indexrelid", ScalarType "oid"),
->            ("schemaname", ScalarType "name"), ("relname", ScalarType "name"),
->            ("indexrelname", ScalarType "name"),
->            ("idx_scan", ScalarType "int8"),
->            ("idx_tup_read", ScalarType "int8"),
->            ("idx_tup_fetch", ScalarType "int8")],
->         CatCreateView "pg_stat_sys_tables"
->           [("relid", ScalarType "oid"), ("schemaname", ScalarType "name"),
->            ("relname", ScalarType "name"), ("seq_scan", ScalarType "int8"),
->            ("seq_tup_read", ScalarType "int8"),
->            ("idx_scan", ScalarType "int8"),
->            ("idx_tup_fetch", ScalarType "int8"),
->            ("n_tup_ins", ScalarType "int8"), ("n_tup_upd", ScalarType "int8"),
->            ("n_tup_del", ScalarType "int8"),
->            ("n_tup_hot_upd", ScalarType "int8"),
->            ("n_live_tup", ScalarType "int8"),
->            ("n_dead_tup", ScalarType "int8"),
->            ("last_vacuum", ScalarType "timestamptz"),
->            ("last_autovacuum", ScalarType "timestamptz"),
->            ("last_analyze", ScalarType "timestamptz"),
->            ("last_autoanalyze", ScalarType "timestamptz"),
->            ("vacuum_count", ScalarType "int8"),
->            ("autovacuum_count", ScalarType "int8"),
->            ("analyze_count", ScalarType "int8"),
->            ("autoanalyze_count", ScalarType "int8")],
->         CatCreateView "pg_stat_user_functions"
->           [("funcid", ScalarType "oid"), ("schemaname", ScalarType "name"),
->            ("funcname", ScalarType "name"), ("calls", ScalarType "int8"),
->            ("total_time", ScalarType "int8"),
->            ("self_time", ScalarType "int8")],
->         CatCreateView "pg_stat_user_indexes"
->           [("relid", ScalarType "oid"), ("indexrelid", ScalarType "oid"),
->            ("schemaname", ScalarType "name"), ("relname", ScalarType "name"),
->            ("indexrelname", ScalarType "name"),
->            ("idx_scan", ScalarType "int8"),
->            ("idx_tup_read", ScalarType "int8"),
->            ("idx_tup_fetch", ScalarType "int8")],
->         CatCreateView "pg_stat_user_tables"
->           [("relid", ScalarType "oid"), ("schemaname", ScalarType "name"),
->            ("relname", ScalarType "name"), ("seq_scan", ScalarType "int8"),
->            ("seq_tup_read", ScalarType "int8"),
->            ("idx_scan", ScalarType "int8"),
->            ("idx_tup_fetch", ScalarType "int8"),
->            ("n_tup_ins", ScalarType "int8"), ("n_tup_upd", ScalarType "int8"),
->            ("n_tup_del", ScalarType "int8"),
->            ("n_tup_hot_upd", ScalarType "int8"),
->            ("n_live_tup", ScalarType "int8"),
->            ("n_dead_tup", ScalarType "int8"),
->            ("last_vacuum", ScalarType "timestamptz"),
->            ("last_autovacuum", ScalarType "timestamptz"),
->            ("last_analyze", ScalarType "timestamptz"),
->            ("last_autoanalyze", ScalarType "timestamptz"),
->            ("vacuum_count", ScalarType "int8"),
->            ("autovacuum_count", ScalarType "int8"),
->            ("analyze_count", ScalarType "int8"),
->            ("autoanalyze_count", ScalarType "int8")],
->         CatCreateView "pg_stat_xact_all_tables"
->           [("relid", ScalarType "oid"), ("schemaname", ScalarType "name"),
->            ("relname", ScalarType "name"), ("seq_scan", ScalarType "int8"),
->            ("seq_tup_read", ScalarType "int8"),
->            ("idx_scan", ScalarType "int8"),
->            ("idx_tup_fetch", ScalarType "int8"),
->            ("n_tup_ins", ScalarType "int8"), ("n_tup_upd", ScalarType "int8"),
->            ("n_tup_del", ScalarType "int8"),
->            ("n_tup_hot_upd", ScalarType "int8")],
->         CatCreateView "pg_stat_xact_sys_tables"
->           [("relid", ScalarType "oid"), ("schemaname", ScalarType "name"),
->            ("relname", ScalarType "name"), ("seq_scan", ScalarType "int8"),
->            ("seq_tup_read", ScalarType "int8"),
->            ("idx_scan", ScalarType "int8"),
->            ("idx_tup_fetch", ScalarType "int8"),
->            ("n_tup_ins", ScalarType "int8"), ("n_tup_upd", ScalarType "int8"),
->            ("n_tup_del", ScalarType "int8"),
->            ("n_tup_hot_upd", ScalarType "int8")],
->         CatCreateView "pg_stat_xact_user_functions"
->           [("funcid", ScalarType "oid"), ("schemaname", ScalarType "name"),
->            ("funcname", ScalarType "name"), ("calls", ScalarType "int8"),
->            ("total_time", ScalarType "int8"),
->            ("self_time", ScalarType "int8")],
->         CatCreateView "pg_stat_xact_user_tables"
->           [("relid", ScalarType "oid"), ("schemaname", ScalarType "name"),
->            ("relname", ScalarType "name"), ("seq_scan", ScalarType "int8"),
->            ("seq_tup_read", ScalarType "int8"),
->            ("idx_scan", ScalarType "int8"),
->            ("idx_tup_fetch", ScalarType "int8"),
->            ("n_tup_ins", ScalarType "int8"), ("n_tup_upd", ScalarType "int8"),
->            ("n_tup_del", ScalarType "int8"),
->            ("n_tup_hot_upd", ScalarType "int8")],
->         CatCreateView "pg_statio_all_indexes"
->           [("relid", ScalarType "oid"), ("indexrelid", ScalarType "oid"),
->            ("schemaname", ScalarType "name"), ("relname", ScalarType "name"),
->            ("indexrelname", ScalarType "name"),
->            ("idx_blks_read", ScalarType "int8"),
->            ("idx_blks_hit", ScalarType "int8")],
->         CatCreateView "pg_statio_all_sequences"
->           [("relid", ScalarType "oid"), ("schemaname", ScalarType "name"),
->            ("relname", ScalarType "name"), ("blks_read", ScalarType "int8"),
->            ("blks_hit", ScalarType "int8")],
->         CatCreateView "pg_statio_all_tables"
->           [("relid", ScalarType "oid"), ("schemaname", ScalarType "name"),
->            ("relname", ScalarType "name"),
->            ("heap_blks_read", ScalarType "int8"),
->            ("heap_blks_hit", ScalarType "int8"),
->            ("idx_blks_read", ScalarType "int8"),
->            ("idx_blks_hit", ScalarType "int8"),
->            ("toast_blks_read", ScalarType "int8"),
->            ("toast_blks_hit", ScalarType "int8"),
->            ("tidx_blks_read", ScalarType "int8"),
->            ("tidx_blks_hit", ScalarType "int8")],
->         CatCreateView "pg_statio_sys_indexes"
->           [("relid", ScalarType "oid"), ("indexrelid", ScalarType "oid"),
->            ("schemaname", ScalarType "name"), ("relname", ScalarType "name"),
->            ("indexrelname", ScalarType "name"),
->            ("idx_blks_read", ScalarType "int8"),
->            ("idx_blks_hit", ScalarType "int8")],
->         CatCreateView "pg_statio_sys_sequences"
->           [("relid", ScalarType "oid"), ("schemaname", ScalarType "name"),
->            ("relname", ScalarType "name"), ("blks_read", ScalarType "int8"),
->            ("blks_hit", ScalarType "int8")],
->         CatCreateView "pg_statio_sys_tables"
->           [("relid", ScalarType "oid"), ("schemaname", ScalarType "name"),
->            ("relname", ScalarType "name"),
->            ("heap_blks_read", ScalarType "int8"),
->            ("heap_blks_hit", ScalarType "int8"),
->            ("idx_blks_read", ScalarType "int8"),
->            ("idx_blks_hit", ScalarType "int8"),
->            ("toast_blks_read", ScalarType "int8"),
->            ("toast_blks_hit", ScalarType "int8"),
->            ("tidx_blks_read", ScalarType "int8"),
->            ("tidx_blks_hit", ScalarType "int8")],
->         CatCreateView "pg_statio_user_indexes"
->           [("relid", ScalarType "oid"), ("indexrelid", ScalarType "oid"),
->            ("schemaname", ScalarType "name"), ("relname", ScalarType "name"),
->            ("indexrelname", ScalarType "name"),
->            ("idx_blks_read", ScalarType "int8"),
->            ("idx_blks_hit", ScalarType "int8")],
->         CatCreateView "pg_statio_user_sequences"
->           [("relid", ScalarType "oid"), ("schemaname", ScalarType "name"),
->            ("relname", ScalarType "name"), ("blks_read", ScalarType "int8"),
->            ("blks_hit", ScalarType "int8")],
->         CatCreateView "pg_statio_user_tables"
->           [("relid", ScalarType "oid"), ("schemaname", ScalarType "name"),
->            ("relname", ScalarType "name"),
->            ("heap_blks_read", ScalarType "int8"),
->            ("heap_blks_hit", ScalarType "int8"),
->            ("idx_blks_read", ScalarType "int8"),
->            ("idx_blks_hit", ScalarType "int8"),
->            ("toast_blks_read", ScalarType "int8"),
->            ("toast_blks_hit", ScalarType "int8"),
->            ("tidx_blks_read", ScalarType "int8"),
->            ("tidx_blks_hit", ScalarType "int8")],
->         CatCreateView "pg_stats"
->           [("schemaname", ScalarType "name"),
->            ("tablename", ScalarType "name"), ("attname", ScalarType "name"),
->            ("inherited", ScalarType "bool"),
->            ("null_frac", ScalarType "float4"),
->            ("avg_width", ScalarType "int4"),
->            ("n_distinct", ScalarType "float4"),
->            ("most_common_vals", Pseudo AnyArray),
->            ("most_common_freqs", ArrayType (ScalarType "float4")),
->            ("histogram_bounds", Pseudo AnyArray),
->            ("correlation", ScalarType "float4")],
->         CatCreateView "pg_tables"
->           [("schemaname", ScalarType "name"),
->            ("tablename", ScalarType "name"),
->            ("tableowner", ScalarType "name"),
->            ("tablespace", ScalarType "name"),
->            ("hasindexes", ScalarType "bool"), ("hasrules", ScalarType "bool"),
->            ("hastriggers", ScalarType "bool")],
->         CatCreateView "pg_timezone_abbrevs"
->           [("abbrev", ScalarType "text"),
->            ("utc_offset", ScalarType "interval"),
->            ("is_dst", ScalarType "bool")],
->         CatCreateView "pg_timezone_names"
->           [("name", ScalarType "text"), ("abbrev", ScalarType "text"),
->            ("utc_offset", ScalarType "interval"),
->            ("is_dst", ScalarType "bool")],
->         CatCreateView "pg_user"
->           [("usename", ScalarType "name"), ("usesysid", ScalarType "oid"),
->            ("usecreatedb", ScalarType "bool"),
->            ("usesuper", ScalarType "bool"), ("usecatupd", ScalarType "bool"),
->            ("userepl", ScalarType "bool"), ("passwd", ScalarType "text"),
->            ("valuntil", ScalarType "abstime"),
->            ("useconfig", ArrayType (ScalarType "text"))],
->         CatCreateView "pg_user_mappings"
->           [("umid", ScalarType "oid"), ("srvid", ScalarType "oid"),
->            ("srvname", ScalarType "name"), ("umuser", ScalarType "oid"),
->            ("usename", ScalarType "name"),
->            ("umoptions", ArrayType (ScalarType "text"))],
->         CatCreateView "pg_views"
->           [("schemaname", ScalarType "name"),
->            ("viewname", ScalarType "name"), ("viewowner", ScalarType "name"),
->            ("definition", ScalarType "text")],
->         CatCreateView "information_schema.referential_constraints"
->           [("constraint_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("constraint_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("constraint_name",
->             DomainType "information_schema.sql_identifier"),
->            ("unique_constraint_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("unique_constraint_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("unique_constraint_name",
->             DomainType "information_schema.sql_identifier"),
->            ("match_option", DomainType "information_schema.character_data"),
->            ("update_rule", DomainType "information_schema.character_data"),
->            ("delete_rule", DomainType "information_schema.character_data")],
->         CatCreateView "information_schema.role_column_grants"
->           [("grantor", DomainType "information_schema.sql_identifier"),
->            ("grantee", DomainType "information_schema.sql_identifier"),
->            ("table_catalog", DomainType "information_schema.sql_identifier"),
->            ("table_schema", DomainType "information_schema.sql_identifier"),
->            ("table_name", DomainType "information_schema.sql_identifier"),
->            ("column_name", DomainType "information_schema.sql_identifier"),
->            ("privilege_type", DomainType "information_schema.character_data"),
->            ("is_grantable", DomainType "information_schema.yes_or_no")],
->         CatCreateView "information_schema.role_routine_grants"
->           [("grantor", DomainType "information_schema.sql_identifier"),
->            ("grantee", DomainType "information_schema.sql_identifier"),
->            ("specific_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("specific_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("specific_name", DomainType "information_schema.sql_identifier"),
->            ("routine_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("routine_schema", DomainType "information_schema.sql_identifier"),
->            ("routine_name", DomainType "information_schema.sql_identifier"),
->            ("privilege_type", DomainType "information_schema.character_data"),
->            ("is_grantable", DomainType "information_schema.yes_or_no")],
->         CatCreateView "information_schema.role_table_grants"
->           [("grantor", DomainType "information_schema.sql_identifier"),
->            ("grantee", DomainType "information_schema.sql_identifier"),
->            ("table_catalog", DomainType "information_schema.sql_identifier"),
->            ("table_schema", DomainType "information_schema.sql_identifier"),
->            ("table_name", DomainType "information_schema.sql_identifier"),
->            ("privilege_type", DomainType "information_schema.character_data"),
->            ("is_grantable", DomainType "information_schema.yes_or_no"),
->            ("with_hierarchy", DomainType "information_schema.yes_or_no")],
->         CatCreateView "information_schema.role_usage_grants"
->           [("grantor", DomainType "information_schema.sql_identifier"),
->            ("grantee", DomainType "information_schema.sql_identifier"),
->            ("object_catalog", DomainType "information_schema.sql_identifier"),
->            ("object_schema", DomainType "information_schema.sql_identifier"),
->            ("object_name", DomainType "information_schema.sql_identifier"),
->            ("object_type", DomainType "information_schema.character_data"),
->            ("privilege_type", DomainType "information_schema.character_data"),
->            ("is_grantable", DomainType "information_schema.yes_or_no")],
->         CatCreateView "information_schema.routine_privileges"
->           [("grantor", DomainType "information_schema.sql_identifier"),
->            ("grantee", DomainType "information_schema.sql_identifier"),
->            ("specific_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("specific_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("specific_name", DomainType "information_schema.sql_identifier"),
->            ("routine_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("routine_schema", DomainType "information_schema.sql_identifier"),
->            ("routine_name", DomainType "information_schema.sql_identifier"),
->            ("privilege_type", DomainType "information_schema.character_data"),
->            ("is_grantable", DomainType "information_schema.yes_or_no")],
->         CatCreateView "information_schema.routines"
->           [("specific_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("specific_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("specific_name", DomainType "information_schema.sql_identifier"),
->            ("routine_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("routine_schema", DomainType "information_schema.sql_identifier"),
->            ("routine_name", DomainType "information_schema.sql_identifier"),
->            ("routine_type", DomainType "information_schema.character_data"),
->            ("module_catalog", DomainType "information_schema.sql_identifier"),
->            ("module_schema", DomainType "information_schema.sql_identifier"),
->            ("module_name", DomainType "information_schema.sql_identifier"),
->            ("udt_catalog", DomainType "information_schema.sql_identifier"),
->            ("udt_schema", DomainType "information_schema.sql_identifier"),
->            ("udt_name", DomainType "information_schema.sql_identifier"),
->            ("data_type", DomainType "information_schema.character_data"),
->            ("character_maximum_length",
->             DomainType "information_schema.cardinal_number"),
->            ("character_octet_length",
->             DomainType "information_schema.cardinal_number"),
->            ("character_set_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("character_set_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("character_set_name",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("collation_name", DomainType "information_schema.sql_identifier"),
->            ("numeric_precision",
->             DomainType "information_schema.cardinal_number"),
->            ("numeric_precision_radix",
->             DomainType "information_schema.cardinal_number"),
->            ("numeric_scale", DomainType "information_schema.cardinal_number"),
->            ("datetime_precision",
->             DomainType "information_schema.cardinal_number"),
->            ("interval_type", DomainType "information_schema.character_data"),
->            ("interval_precision",
->             DomainType "information_schema.character_data"),
->            ("type_udt_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("type_udt_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("type_udt_name", DomainType "information_schema.sql_identifier"),
->            ("scope_catalog", DomainType "information_schema.sql_identifier"),
->            ("scope_schema", DomainType "information_schema.sql_identifier"),
->            ("scope_name", DomainType "information_schema.sql_identifier"),
->            ("maximum_cardinality",
->             DomainType "information_schema.cardinal_number"),
->            ("dtd_identifier", DomainType "information_schema.sql_identifier"),
->            ("routine_body", DomainType "information_schema.character_data"),
->            ("routine_definition",
->             DomainType "information_schema.character_data"),
->            ("external_name", DomainType "information_schema.character_data"),
->            ("external_language",
->             DomainType "information_schema.character_data"),
->            ("parameter_style",
->             DomainType "information_schema.character_data"),
->            ("is_deterministic", DomainType "information_schema.yes_or_no"),
->            ("sql_data_access",
->             DomainType "information_schema.character_data"),
->            ("is_null_call", DomainType "information_schema.yes_or_no"),
->            ("sql_path", DomainType "information_schema.character_data"),
->            ("schema_level_routine",
->             DomainType "information_schema.yes_or_no"),
->            ("max_dynamic_result_sets",
->             DomainType "information_schema.cardinal_number"),
->            ("is_user_defined_cast",
->             DomainType "information_schema.yes_or_no"),
->            ("is_implicitly_invocable",
->             DomainType "information_schema.yes_or_no"),
->            ("security_type", DomainType "information_schema.character_data"),
->            ("to_sql_specific_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("to_sql_specific_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("to_sql_specific_name",
->             DomainType "information_schema.sql_identifier"),
->            ("as_locator", DomainType "information_schema.yes_or_no"),
->            ("created", DomainType "information_schema.time_stamp"),
->            ("last_altered", DomainType "information_schema.time_stamp"),
->            ("new_savepoint_level", DomainType "information_schema.yes_or_no"),
->            ("is_udt_dependent", DomainType "information_schema.yes_or_no"),
->            ("result_cast_from_data_type",
->             DomainType "information_schema.character_data"),
->            ("result_cast_as_locator",
->             DomainType "information_schema.yes_or_no"),
->            ("result_cast_char_max_length",
->             DomainType "information_schema.cardinal_number"),
->            ("result_cast_char_octet_length",
->             DomainType "information_schema.cardinal_number"),
->            ("result_cast_char_set_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("result_cast_char_set_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("result_cast_character_set_name",
->             DomainType "information_schema.sql_identifier"),
->            ("result_cast_collation_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("result_cast_collation_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("result_cast_collation_name",
->             DomainType "information_schema.sql_identifier"),
->            ("result_cast_numeric_precision",
->             DomainType "information_schema.cardinal_number"),
->            ("result_cast_numeric_precision_radix",
->             DomainType "information_schema.cardinal_number"),
->            ("result_cast_numeric_scale",
->             DomainType "information_schema.cardinal_number"),
->            ("result_cast_datetime_precision",
->             DomainType "information_schema.cardinal_number"),
->            ("result_cast_interval_type",
->             DomainType "information_schema.character_data"),
->            ("result_cast_interval_precision",
->             DomainType "information_schema.character_data"),
->            ("result_cast_type_udt_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("result_cast_type_udt_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("result_cast_type_udt_name",
->             DomainType "information_schema.sql_identifier"),
->            ("result_cast_scope_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("result_cast_scope_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("result_cast_scope_name",
->             DomainType "information_schema.sql_identifier"),
->            ("result_cast_maximum_cardinality",
->             DomainType "information_schema.cardinal_number"),
->            ("result_cast_dtd_identifier",
->             DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.schemata"
->           [("catalog_name", DomainType "information_schema.sql_identifier"),
->            ("schema_name", DomainType "information_schema.sql_identifier"),
->            ("schema_owner", DomainType "information_schema.sql_identifier"),
->            ("default_character_set_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("default_character_set_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("default_character_set_name",
->             DomainType "information_schema.sql_identifier"),
->            ("sql_path", DomainType "information_schema.character_data")],
->         CatCreateView "information_schema.sequences"
->           [("sequence_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("sequence_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("sequence_name", DomainType "information_schema.sql_identifier"),
->            ("data_type", DomainType "information_schema.character_data"),
->            ("numeric_precision",
->             DomainType "information_schema.cardinal_number"),
->            ("numeric_precision_radix",
->             DomainType "information_schema.cardinal_number"),
->            ("numeric_scale", DomainType "information_schema.cardinal_number"),
->            ("start_value", DomainType "information_schema.character_data"),
->            ("minimum_value", DomainType "information_schema.character_data"),
->            ("maximum_value", DomainType "information_schema.character_data"),
->            ("increment", DomainType "information_schema.character_data"),
->            ("cycle_option", DomainType "information_schema.yes_or_no")],
->         CatCreateView "information_schema.table_constraints"
->           [("constraint_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("constraint_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("constraint_name",
->             DomainType "information_schema.sql_identifier"),
->            ("table_catalog", DomainType "information_schema.sql_identifier"),
->            ("table_schema", DomainType "information_schema.sql_identifier"),
->            ("table_name", DomainType "information_schema.sql_identifier"),
->            ("constraint_type",
->             DomainType "information_schema.character_data"),
->            ("is_deferrable", DomainType "information_schema.yes_or_no"),
->            ("initially_deferred", DomainType "information_schema.yes_or_no")],
->         CatCreateView "information_schema.table_privileges"
->           [("grantor", DomainType "information_schema.sql_identifier"),
->            ("grantee", DomainType "information_schema.sql_identifier"),
->            ("table_catalog", DomainType "information_schema.sql_identifier"),
->            ("table_schema", DomainType "information_schema.sql_identifier"),
->            ("table_name", DomainType "information_schema.sql_identifier"),
->            ("privilege_type", DomainType "information_schema.character_data"),
->            ("is_grantable", DomainType "information_schema.yes_or_no"),
->            ("with_hierarchy", DomainType "information_schema.yes_or_no")],
->         CatCreateView "information_schema.tables"
->           [("table_catalog", DomainType "information_schema.sql_identifier"),
->            ("table_schema", DomainType "information_schema.sql_identifier"),
->            ("table_name", DomainType "information_schema.sql_identifier"),
->            ("table_type", DomainType "information_schema.character_data"),
->            ("self_referencing_column_name",
->             DomainType "information_schema.sql_identifier"),
->            ("reference_generation",
->             DomainType "information_schema.character_data"),
->            ("user_defined_type_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("user_defined_type_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("user_defined_type_name",
->             DomainType "information_schema.sql_identifier"),
->            ("is_insertable_into", DomainType "information_schema.yes_or_no"),
->            ("is_typed", DomainType "information_schema.yes_or_no"),
->            ("commit_action", DomainType "information_schema.character_data")],
->         CatCreateView "information_schema.triggered_update_columns"
->           [("trigger_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("trigger_schema", DomainType "information_schema.sql_identifier"),
->            ("trigger_name", DomainType "information_schema.sql_identifier"),
->            ("event_object_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("event_object_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("event_object_table",
->             DomainType "information_schema.sql_identifier"),
->            ("event_object_column",
->             DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.triggers"
->           [("trigger_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("trigger_schema", DomainType "information_schema.sql_identifier"),
->            ("trigger_name", DomainType "information_schema.sql_identifier"),
->            ("event_manipulation",
->             DomainType "information_schema.character_data"),
->            ("event_object_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("event_object_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("event_object_table",
->             DomainType "information_schema.sql_identifier"),
->            ("action_order", DomainType "information_schema.cardinal_number"),
->            ("action_condition",
->             DomainType "information_schema.character_data"),
->            ("action_statement",
->             DomainType "information_schema.character_data"),
->            ("action_orientation",
->             DomainType "information_schema.character_data"),
->            ("action_timing", DomainType "information_schema.character_data"),
->            ("action_reference_old_table",
->             DomainType "information_schema.sql_identifier"),
->            ("action_reference_new_table",
->             DomainType "information_schema.sql_identifier"),
->            ("action_reference_old_row",
->             DomainType "information_schema.sql_identifier"),
->            ("action_reference_new_row",
->             DomainType "information_schema.sql_identifier"),
->            ("created", DomainType "information_schema.time_stamp")],
->         CatCreateView "information_schema.usage_privileges"
->           [("grantor", DomainType "information_schema.sql_identifier"),
->            ("grantee", DomainType "information_schema.sql_identifier"),
->            ("object_catalog", DomainType "information_schema.sql_identifier"),
->            ("object_schema", DomainType "information_schema.sql_identifier"),
->            ("object_name", DomainType "information_schema.sql_identifier"),
->            ("object_type", DomainType "information_schema.character_data"),
->            ("privilege_type", DomainType "information_schema.character_data"),
->            ("is_grantable", DomainType "information_schema.yes_or_no")],
->         CatCreateView "information_schema.user_mapping_options"
->           [("authorization_identifier",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_server_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_server_name",
->             DomainType "information_schema.sql_identifier"),
->            ("option_name", DomainType "information_schema.sql_identifier"),
->            ("option_value", DomainType "information_schema.character_data")],
->         CatCreateView "information_schema.user_mappings"
->           [("authorization_identifier",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_server_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("foreign_server_name",
->             DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.view_column_usage"
->           [("view_catalog", DomainType "information_schema.sql_identifier"),
->            ("view_schema", DomainType "information_schema.sql_identifier"),
->            ("view_name", DomainType "information_schema.sql_identifier"),
->            ("table_catalog", DomainType "information_schema.sql_identifier"),
->            ("table_schema", DomainType "information_schema.sql_identifier"),
->            ("table_name", DomainType "information_schema.sql_identifier"),
->            ("column_name", DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.view_routine_usage"
->           [("table_catalog", DomainType "information_schema.sql_identifier"),
->            ("table_schema", DomainType "information_schema.sql_identifier"),
->            ("table_name", DomainType "information_schema.sql_identifier"),
->            ("specific_catalog",
->             DomainType "information_schema.sql_identifier"),
->            ("specific_schema",
->             DomainType "information_schema.sql_identifier"),
->            ("specific_name", DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.view_table_usage"
->           [("view_catalog", DomainType "information_schema.sql_identifier"),
->            ("view_schema", DomainType "information_schema.sql_identifier"),
->            ("view_name", DomainType "information_schema.sql_identifier"),
->            ("table_catalog", DomainType "information_schema.sql_identifier"),
->            ("table_schema", DomainType "information_schema.sql_identifier"),
->            ("table_name", DomainType "information_schema.sql_identifier")],
->         CatCreateView "information_schema.views"
->           [("table_catalog", DomainType "information_schema.sql_identifier"),
->            ("table_schema", DomainType "information_schema.sql_identifier"),
->            ("table_name", DomainType "information_schema.sql_identifier"),
->            ("view_definition",
->             DomainType "information_schema.character_data"),
->            ("check_option", DomainType "information_schema.character_data"),
->            ("is_updatable", DomainType "information_schema.yes_or_no"),
->            ("is_insertable_into", DomainType "information_schema.yes_or_no"),
->            ("is_trigger_updatable",
->             DomainType "information_schema.yes_or_no"),
->            ("is_trigger_deletable",
->             DomainType "information_schema.yes_or_no"),
->            ("is_trigger_insertable_into",
->             DomainType "information_schema.yes_or_no")]]
-
diff --git a/src/Database/HsSqlPpp/Internals/Dialect.lhs b/src/Database/HsSqlPpp/Internals/Dialect.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/Dialect.lhs
@@ -0,0 +1,174 @@
+
+
+New approach to dialacts, more rule driven so all the options for a
+dialect can appear here.
+
+It would be nice to make the dialects completely rule driven, but I
+think this is much less maintainable than making them mainly rule
+driven (primarily via the catalogs), but with some special cases
+scattered in the source code.
+
+The dialect contains:
+the name of the dialect
+some parsing options about what syntax is supported
+some options about typechecking support
+
+flags to control the details of the dialect (for instance, some
+dialects have additional options to specify which kinds of string
+literal escapes are valid, so this is like subdialect
+
+stuff about types:
+
+canonical names of types with multiple names (these are only the
+built in types, user/catalog driven type aliases are not covered here)
+the built in text types
+the built in datetime types
+
+default catalog for this dialect
+
+
+then supplied with hssqlppp are:
+base dialect with minimal stuff in it
+ansi2011 dialect
+recent-ish postgresql dialect
+recent-ish sql server dialect
+recent-ish oracle dialect
+
+the idea is that if you have one of these dialects, you can start here
+then add your own catalog entries and use it as is. If your dialect is
+not here, and is it similar enough to an existing dialect, you can
+take that dialect and
+    a) modify some of the dialect options
+    b) modify the default catalog
+    and you will get something useful
+
+if the dialect is too different, then you will have to edit the
+hssqlppp source.
+
+> {-# LANGUAGE DeriveDataTypeable #-}
+> module Database.HsSqlPpp.Internals.Dialect
+>     (Dialect(..)
+>     ,SyntaxFlavour(..)
+>     ,canonicalizeTypeName
+>     ,ansiTypeNameToDialect) where
+
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+> import Data.Data
+> import Data.Text (Text)
+> import qualified Data.Text as T
+> import Data.List (find)
+> import Data.Char (toLower)
+
+> data Dialect = Dialect
+>      {diName :: String
+
+represent the syntax variations with a crude enum. Later, can make
+this more rule driven.
+
+>      ,diSyntaxFlavour :: SyntaxFlavour
+
+map from alternative names to the canonical name of built in
+types. This is used e.g. because in ansi the canonical name of boolean
+type is 'boolean', and in postgresql the canonical name of this type
+is 'bool'.
+These should all be in lower case
+
+>      ,diCanonicalTypeNames :: [(Text,[Text])]
+
+the names of the built in text types. This is used to help type check
+built in functions like substring?
+
+>      ,diTextTypes :: [Text] -- names of the text types (canonical names must be used)
+
+used to typecheck things like extract
+
+todo: create a single function which takes the ansi name of a type and
+returns the dialect specific name (as a maybe) - then don't have to
+have a huge number of functions here.
+
+Also, these functions should be -TypeName not -Type.
+
+>      ,diDatetimeTypes :: [Text]
+>      ,diNumberTypes :: [Text] -- names of the number types (canonical names must be used)
+>      -- this is a map from the canonical ansi name (in hssqlppp)
+>      -- to the canonical name in the dialect
+>      -- if there is no entry, then it means that type isn't
+>      -- supported in this dialect
+
+todo: make a list of exactly what type names are needed in the type
+checker and why. This should only be used for the type checker
+internally, and not anywhere else. Should do the same for the
+other fields above
+
+>      ,namesForAnsiTypes :: [(Text,Text)]
+
+A small issue with having the default catalog like this is that we can
+make a programming error where we have a function which takes the
+dialect and a catalog, and we use this default catalog instead of the
+supplied updated catalog.
+
+>      ,diDefaultCatalog :: Catalog
+>      } deriving (Eq,Show,Data,Typeable)
+
+> data SyntaxFlavour = Ansi | Postgres | SqlServer | Oracle
+>                      deriving (Eq,Show,Data,Typeable)
+
+> ansiTypeNameToDialect :: Dialect -> Text -> Maybe Text
+> ansiTypeNameToDialect d n = lookup n (namesForAnsiTypes d)
+
+> canonicalizeTypeName :: Dialect -> Text -> Text
+> canonicalizeTypeName d s =
+>     let m = diCanonicalTypeNames d
+>     in ct m s
+>   where
+>     hasType t p = let t' = T.map toLower t
+>                   in t' `elem` snd p
+>     ct m tn = maybe tn fst
+>               $ find (hasType tn) m
+
+TODO:
+modify the catalog:
+  when adding a type flags to say:
+    if this type is a text or datetime or number type
+    if it is built in
+    if it is undroppable
+    if it has a list of builtin aliases
+    what the ansi equivalent type name is
+
+this will get rid of most of the fields in the dialect and make it
+much easier to keep everything consistent and maintainable
+
+start adding flags for which bits of syntax to support instead of
+using the syntax flavour thing
+there will be flags like this for typechecking also
+
+support functions to help create minimal dialects
+  e.g. take ansi, and safely remove a bunch of types and functions
+
+write the default catalogs and dialects all in one file
+  (they are split into two at the moment)
+
+export the ansidialect every module that exposes something with a
+dialect (function or data type) - parse, pretty, lex, typecheck, etc.
+
+then you only need to import the dialects module to get the other
+dialects
+
+consider how the catalog in the dialect can help with parsing
+operators
+
+minimal dialects:
+mainly missing types then following through on implications:
+no text types
+only one text type covering char,varchar,nclob, etc.
+no numeric or decimal
+on decimal for all integers and precise decimals
+no date or time types
+
+
+Types:
+typeextra: needs fixing
+how to represent e.g. 'varchar' without precision
+
+invent some sort of concrete syntax (which is parseable) to
+represent implicit casts (cast implicit x as varchar)?
diff --git a/src/Database/HsSqlPpp/Internals/LexInternal.lhs b/src/Database/HsSqlPpp/Internals/LexInternal.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/LexInternal.lhs
@@ -0,0 +1,552 @@
+
+> {-# LANGUAGE TupleSections,OverloadedStrings #-}
+> module Database.HsSqlPpp.Internals.LexInternal
+>     (Token(..)
+>     ,prettyToken
+>     ,lexToken
+>     ,lexTokens
+>     ) where
+
+> --import qualified Data.Text as T
+> import qualified Data.Text.Lazy as LT
+> import Text.Parsec
+> --Cimport Text.Parsec.String hdi
+> import Text.Parsec.Text.Lazy
+> import Control.Applicative hiding ((<|>), many)
+> import Data.Char
+> import Database.HsSqlPpp.Internals.Dialect
+> import Control.Monad
+> import Prelude hiding (takeWhile)
+> import Data.Maybe
+
+> -- | Represents a lexed token
+> data Token
+>     -- | a symbol in postgresql dialect is one of the following:
+>     --
+>     -- * one of the characters (),;[]{}  (the {} is for odbc)
+>     --
+>     -- * \'..\' or \':=\' or \'.\' or \':\'
+>     --
+>     -- * a compound symbol, which starts with one of \'*\/\<>=~!\@#%^&|\`?+-' and follows with 0 or more of '*\/<>=~!\@#%^&|\`?'
+>     --
+>     -- things that are not lexed as symbols:
+>     --
+>     -- * [] used in quoted identifiers, prefix \@,#,: used in identifiers
+>     --
+>     -- * $n positional arg
+>     --
+>     = Symbol String
+>
+>     -- | This is an identifier or keyword.
+>     --
+>     -- The 'Maybe (Char,Char)' selects the quoted style - 'Nothing' means the
+>     -- identifier was unquoted
+>     -- otherwise the two characters are the start and end quote.
+>     --
+>     -- \'\"\' is used to quote identifiers in standard sql, sql server also uses [brackets]
+>     -- to quote identifiers.
+>     --
+>     -- The identifier also includes the \'variable marker prefix\'
+>     -- used in sql server (e.g. \@identifier, #identifier), and oracle
+>     -- (e.g. :identifier)
+>     | Identifier (Maybe (String,String)) String
+>
+>     --  | This is a prefixed variable symbol, such as :var, @var or #var
+>     -- (only :var is used in ansi dialect)
+>     | PrefixedVariable Char String
+>
+>     -- | a postgresql positional arg, e.g. $1
+>     | PositionalArg Int
+>
+>     -- | This is a string literal.
+>     --
+>     -- The first field is the quotes used: single quote (\')
+>     -- for normal strings, E' for escape supporting strings,
+>     -- and $$ delimiter for postgresql dollar quoted strings.
+>     --
+>     -- The lexer doesn't process the escapes in strings, but passes
+>     -- on the literal source e.g. E\'\\n\' parses to SqlString \"E\'\" \"\\n\"
+>     -- with the literal characters \'\\\' and \'n\' in the string, not a newline character.
+>     -- quotes within a string (\'\') or escaped string (\'\' or \\\') are passed through unchanged
+>     | SqlString String String String
+>
+>     -- | a number literal (integral or otherwise), stored in original format
+>     -- unchanged
+>     | SqlNumber String
+>
+>     -- | non-significant whitespace (space, tab, newline) (strictly speaking,
+>     -- it is up to the client to decide whether the whitespace is significant
+>     -- or not)
+>     | Whitespace String
+>
+>     -- | a commented line using --, contains every character starting with the
+>     -- \'--\' and including the terminating newline character if there is one
+>     -- - this will be missing if the last line in the source is a line comment
+>     -- with no trailing newline
+>     | LineComment String
+>
+>     -- | a block comment, \/* stuff *\/, includes the comment delimiters
+>     | BlockComment String
+>
+>     -- | an antiquotation splice, e.g. $x(stuff)
+>     | Splice Char String
+>
+>     -- | the copy data in a copy from stdin
+>     | CopyPayload String
+>       deriving (Eq,Show)
+
+> -- | Accurate pretty printing, if you lex a bunch of tokens,
+> -- then pretty print them, should should get back exactly the
+> -- same string
+> prettyToken :: Dialect -> Token -> String
+> prettyToken _ (Symbol s) = s
+> prettyToken _ (Identifier Nothing t) = t
+> prettyToken _ (Identifier (Just (a,b)) t) = a ++ t ++ b
+> prettyToken _ (PrefixedVariable c s) = c:s
+> prettyToken _ (SqlString q r t) = q ++ t ++ r
+> prettyToken _ (SqlNumber r) = r
+> prettyToken _ (Whitespace t) = t
+> prettyToken _ (PositionalArg n) = '$':show n
+> prettyToken _ (LineComment l) = l
+> prettyToken _ (BlockComment c) = c
+> prettyToken _ (Splice c t) = '$':c:'(':t ++ ")"
+> prettyToken _ (CopyPayload s) = s ++ "\\.\n"
+
+
+not sure how to get the position information in the parse errors
+
+TODO: try to make all parsers applicative only
+investigate what is missing for postgresql
+investigate differences for sql server, oracle, maybe db2 and mysql
+  also
+
+> lexTokens :: Dialect -> FilePath -> Maybe (Int,Int) -> LT.Text -> Either ParseError [((FilePath,Int,Int),Token)]
+> lexTokens dialect fn' mp txt =
+>     let (l',c') = fromMaybe (1,1) mp
+>     in runParser (setPos (fn',l',c') *> many_p <* eof) () "" txt
+>   where
+
+pretty hacky, want to switch to a different lexer for copy from stdin
+statements
+
+if we see 'from stdin;' then try to lex a copy payload
+
+>      many_p = some_p `mplus` return []
+>      some_p = do
+>        tok <- lexToken dialect
+>        case tok of
+>          (_, Identifier Nothing t) | map toLower t == "from" -> (tok:) <$> seeStdin
+>          _ -> (tok:) <$> many_p
+>      seeStdin = do
+>        tok <- lexToken dialect
+>        case tok of
+>          (_,Identifier Nothing t) | map toLower t == "stdin" -> (tok:) <$> seeColon
+>          (_,x) | isWs x -> (tok:) <$> seeStdin
+>          _ -> (tok:) <$> many_p
+>      seeColon = do
+>        tok <- lexToken dialect
+>        case tok of
+>          (_,Symbol ";") -> (tok:) <$> copyPayload
+>          _ -> (tok:) <$> many_p
+>      copyPayload = do
+>        p' <- getPosition
+>        let pos = (sourceName p',sourceLine p', sourceColumn p')
+>        tok <- char '\n' *>
+>             ((\x -> (pos, CopyPayload $ x ++ "\n"))
+>              <$> manyTill anyChar (try $ string "\n\\.\n"))
+>        --let (_,CopyPayload t) = tok
+>        --trace ("payload is '" ++ T.unpack t ++ "'") $ return ()
+>        (tok:) <$> many_p
+>      setPos (fn,l,c) = do
+>         fmap (flip setSourceName fn
+>                . flip setSourceLine l
+>                . flip setSourceColumn c) getPosition
+>           >>= setPosition
+>      isWs :: Token -> Bool
+>      isWs (Whitespace {}) = True
+>      isWs (BlockComment {}) = True
+>      isWs (LineComment {}) = True
+>      isWs _ = False
+
+> -- | parser for a sql token
+> lexToken :: Dialect -> Parser ((FilePath,Int,Int),Token)
+> lexToken d = do
+>     p' <- getPosition
+>     let p = (sourceName p',sourceLine p', sourceColumn p')
+>     (p,) <$> choice [sqlString d
+>                     ,identifier d
+>                     ,lineComment d
+>                     ,blockComment d
+>                     ,sqlNumber d
+>                     ,positionalArg d
+>                     ,dontParseEndBlockComment d
+>                     ,prefixedVariable d
+>                     ,symbol d
+>                     ,sqlWhitespace d
+>                     ,splice d]
+
+Parses identifiers:
+
+simple_identifier_23
+u&"unicode quoted identifier"
+"quoted identifier"
+"quoted identifier "" with double quote char"
+`mysql quoted identifier`
+
+> identifier :: Dialect -> Parser Token
+> identifier d =
+>     choice
+>     [Identifier (Just ("\"","\"")) <$> qiden
+>      -- try is used here to avoid a conflict with identifiers
+>      -- and quoted strings which also start with a 'u'
+>     ,Identifier (Just ("u&\"","\"")) <$> (try (string "u&") *> qiden)
+>     ,Identifier (Just ("U&\"","\"")) <$> (try (string "U&") *> qiden)
+>     ,Identifier Nothing <$> identifierString
+>      -- todo: dialect protection
+>     -- Identifier (Just ("`","`"))
+>     -- <$> (char '`' *> takeWhile1 (/='`') <* char '`')
+>     ,guard (diSyntaxFlavour d == SqlServer) >>
+>      Identifier (Just ("[","]"))
+>      <$> (char '[' *> takeWhile1 (`notElem` ("[]"::String)) <* char ']')
+>     ]
+>   where
+>     qiden = char '"' *> qidenSuffix ""
+>     qidenSuffix t = do
+>         s <- takeTill (=='"')
+>         void $ char '"'
+>         -- deal with "" as literal double quote character
+>         choice [do
+>                 void $ char '"'
+>                 qidenSuffix $ concat [t,s,"\"\""]
+>                ,return $ concat [t,s]]
+
+
+This parses a valid identifier without quotes.
+
+> identifierString :: Parser String
+> identifierString =
+>     startsWith (\c -> c == '_' || isAlpha c) isIdentifierChar
+
+this can be moved to the dialect at some point
+
+> isIdentifierChar :: Char -> Bool
+> isIdentifierChar c = c == '_' || isAlphaNum c
+
+> prefixedVariable :: Dialect -> Parser Token
+> prefixedVariable  d = try $ choice
+>     [PrefixedVariable <$> char ':' <*> identifierString
+>     ,guard (diSyntaxFlavour d == SqlServer) >>
+>      PrefixedVariable <$> char '@' <*> identifierString
+>     ,guard (diSyntaxFlavour d `elem` [Oracle,SqlServer]) >>
+>      PrefixedVariable <$> char '#' <*> identifierString
+>     ]
+
+
+> positionalArg :: Dialect -> Parser Token
+> -- uses try so we don't get confused with $splices
+> positionalArg d =
+>     guard (diSyntaxFlavour d == Postgres) >>
+>     PositionalArg <$> try (char '$' *> (read <$> many1 digit))
+
+
+Strings in sql:
+postgresql dialect:
+strings delimited with single quotes
+a literal quote is written ''
+the lexer leaves the double quote in the string in the ast
+strings can also be written like this:
+E'string with quotes in \n \t'
+the \n and \t are escape sequences. The lexer passes these through unchanged.
+an 'E' escaped string can also contain \' for a literal single quote.
+this are also passed into the ast unchanged
+strings can be dollar quoted:
+$$string$$
+the dollar quote can contain an optional tag:
+$tag$string$tag$
+which allows nesting of dollar quoted strings with different tags
+
+Not sure what behaviour in sql server and oracle, pretty sure they
+don't have dollar quoting, but I think they have the other two
+variants.
+
+> sqlString :: Dialect -> Parser Token
+> sqlString d = dollarString <|> csString <|> normalString
+>   where
+>     dollarString = do
+>         -- need a solution for the dialect for quasi quotes
+>         --guard $ diSyntaxFlavour d == Postgres
+>         delim <- (\x -> concat ["$",x,"$"])
+>                  <$> try (char '$' *> option "" identifierString <* char '$')
+>         SqlString delim delim  <$> manyTill anyChar (try $ string delim)
+>     normalString = SqlString "'" "'" <$> (char '\'' *> normalStringSuffix False "")
+>     normalStringSuffix allowBackslash t = do
+>         s <- takeTill $ if allowBackslash
+>                         then (`elem` ("'\\"::String))
+>                         else (== '\'')
+>         -- deal with '' or \' as literal quote character
+>         choice [do
+>                 ctu <- choice ["''" <$ try (string "''")
+>                               ,"\\'" <$ try (string "\\'")
+>                               ,"\\" <$ char '\\']
+>                 normalStringSuffix allowBackslash $ concat [t,s,ctu]
+>                ,concat [t,s] <$ char '\'']
+>     -- try is used to to avoid conflicts with
+>     -- identifiers which can start with n,b,x,u
+>     -- once we read the quote type and the starting '
+>     -- then we commit to a string
+>     -- it's possible that this will reject some valid syntax
+>     -- but only pathalogical stuff, and I think the improved
+>     -- error messages and user predictability make it a good
+>     -- pragmatic choice
+>     csString
+>       | diSyntaxFlavour d == Postgres =
+>         choice [SqlString <$> try (string "e'" <|> string "E'")
+>                           <*> return "'" <*> normalStringSuffix True ""
+>                ,csString']
+>       | otherwise = csString'
+>     csString' = SqlString
+>                 <$> try cs
+>                 <*> return "'"
+>                 <*> normalStringSuffix False ""
+>     csPrefixes = "nNbBxX"
+>     cs = choice $ (map (\x -> string ([x] ++ "'")) csPrefixes)
+>                   ++ [string "u&'"
+>                      ,string "U&'"]
+
+postgresql number parsing
+
+digits
+digits.[digits][e[+-]digits]
+[digits].digits[e[+-]digits]
+digitse[+-]digits
+where digits is one or more decimal digits (0 through 9). At least one digit must be before or after the decimal point, if one is used. At least one digit must follow the exponent marker (e), if one is present. There cannot be any spaces or other characters embedded in the constant. Note that any leading plus or minus sign is not actually considered part of the constant; it is an operator applied to the constant.
+
+> sqlNumber :: Dialect -> Parser Token
+> sqlNumber _ =
+>     SqlNumber <$> completeNumber
+>     -- this is for definitely avoiding possibly ambiguous source
+>     -- with a special exception for a .. operator
+>     <* choice
+>        [void $ lookAhead (string "..")
+>        ,void $ notFollowedBy (oneOf "eE.")
+>        ]
+>   where
+>     completeNumber =
+>       (int <??> (pp dot <??.> pp int)
+>       -- try is used in case we read a dot
+>       -- and it isn't part of a number
+>       -- if there are any following digits, then we commit
+>       -- to it being a number and not something else
+>       <|> try ((++) <$> dot <*> int))
+>       <??> pp expon
+
+>     int = many1 digit
+>     -- if we see two dots together, leave them
+>     -- so we can parse things like 1..2 (used in postgres)
+>     dot = try (string "." <* notFollowedBy (char '.'))
+>     expon = (:) <$> oneOf "eE" <*> sInt
+>     sInt = (++) <$> option "" (string "+" <|> string "-") <*> int
+>     pp = (<$$> (++))
+
+> (<??>) :: Parser a -> Parser (a -> a) -> Parser a
+> p <??> q = p <**> option id q
+
+> (<??.>) :: Parser (a -> a) -> Parser (a -> a) -> Parser (a -> a)
+> (<??.>) pa pb = (.) `c` pa <*> option id pb
+>   -- todo: fix this mess
+>   where c = (<$>) . flip
+
+> (<$$>) :: Applicative f =>
+>       f b -> (a -> b -> c) -> f (a -> c)
+> (<$$>) pa c = pa <**> pure (flip c)
+
+A symbol is one of the two character symbols, or one of the single
+character symbols in the two lists below.
+
+> symbol :: Dialect -> Parser Token
+> symbol d | diSyntaxFlavour d == Postgres =
+>     Symbol <$> choice (otherSymbol ++ [singlePlusMinus,opMoreChars])
+
+rules
+
+An operator name is a sequence of up to NAMEDATALEN-1 (63 by default) characters from the following list:
+
++ - * / < > = ~ ! @ # % ^ & | ` ?
+
+There are a few restrictions on operator names, however:
+-- and /* cannot appear anywhere in an operator name, since they will be taken as the start of a comment.
+
+A multiple-character operator name cannot end in + or -, unless the name also contains at least one of these characters:
+
+~ ! @ # % ^ & | ` ?
+
+>   where
+>     -- other symbols are all the tokens which parse as symbols in
+>     -- this lexer which aren't considered operators in postgresql
+>     -- a single ? is parsed as a operator here instead of an other
+>     -- symbol because this is the least complex way to do it
+>     otherSymbol = many1 (char '.') :
+>                   try (string ":=") :
+>                   -- parse :: and : and avoid allowing ::: or more
+>                   try (string "::" <* notFollowedBy (char ':')) :
+>                   try (string ":" <* notFollowedBy (char ':')) :
+>                   (map (string . (:[])) "[],;()"
+>                    ++ if True -- allowOdbc d
+>                       then [string "{", string "}"]
+>                       else []
+>                   )
+
+exception char is one of:
+~ ! @ # % ^ & | ` ?
+which allows the last character of a multi character symbol to be + or
+-
+
+>     allOpSymbols = "+-*/<>=~!@#%^&|`?"
+>     -- these are the symbols when if part of a multi character
+>     -- operator permit the operator to end with a + or - symbol
+>     exceptionOpSymbols = "~!@#%^&|`?"
+
+>     -- special case for parsing a single + or - symbol
+>     singlePlusMinus = try $ do
+>       c <- oneOf "+-"
+>       notFollowedBy $ oneOf allOpSymbols
+>       return [c]
+
+>     -- this is used when we are parsing a potentially multi symbol
+>     -- operator and we have alread seen one of the 'exception chars'
+>     -- and so we can end with a + or -
+>     moreOpCharsException = do
+>        c <- oneOf (filter (`notElem` ("-/*"::String)) allOpSymbols)
+>             -- make sure we don't parse a comment starting token
+>             -- as part of an operator
+>             <|> try (char '/' <* notFollowedBy (char '*'))
+>             <|> try (char '-' <* notFollowedBy (char '-'))
+>             -- and make sure we don't parse a block comment end
+>             -- as part of another symbol
+>             <|> try (char '*' <* notFollowedBy (char '/'))
+>        (c:) <$> option [] moreOpCharsException
+
+>     opMoreChars = choice
+>        [-- parse an exception char, now we can finish with a + -
+>         (:)
+>         <$> oneOf exceptionOpSymbols
+>         <*> option [] moreOpCharsException
+>        ,(:)
+>         <$> (-- parse +, make sure it isn't the last symbol
+>              try (char '+' <* lookAhead (oneOf allOpSymbols))
+>              <|> -- parse -, make sure it isn't the last symbol
+>                  -- or the start of a -- comment
+>              try (char '-'
+>                   <* notFollowedBy (char '-')
+>                   <* lookAhead (oneOf allOpSymbols))
+>              <|> -- parse / check it isn't the start of a /* comment
+>              try (char '/' <* notFollowedBy (char '*'))
+>              <|> -- make sure we don't parse */ as part of a symbol
+>              try (char '*' <* notFollowedBy (char '/'))
+>              <|> -- any other ansi operator symbol
+>              oneOf "<>=")
+>         <*> option [] opMoreChars
+>        ]
+
+> symbol d | diSyntaxFlavour d == SqlServer =
+>    Symbol <$> choice (otherSymbol ++ regularOp)
+>  where
+>    otherSymbol = string "." :
+>                  (map (string . (:[])) ",;():?"
+>                   ++ if True -- allowOdbc d
+>                      then [string "{", string "}"]
+>                      else [])
+
+try is used because most of the first characters of the two character
+symbols can also be part of a single character symbol
+
+>    regularOp = map (try . string) [">=","<=","!=","<>"]
+>                ++ map (string . (:[])) "+-^*/%~&<>="
+>                ++ [char '|' *>
+>                    choice ["||" <$ char '|' <* notFollowedBy (char '|')
+>                           ,return "|"]]
+
+> symbol _d =
+>    Symbol <$> choice (otherSymbol ++ regularOp)
+>  where
+>    otherSymbol = many1 (char '.') :
+>                  (map (string . (:[])) "[],;():?"
+>                   ++ if True -- allowOdbc d
+>                      then [string "{", string "}"]
+>                      else [])
+
+try is used because most of the first characters of the two character
+symbols can also be part of a single character symbol
+
+>    regularOp = map (try . string) [">=","<=","!=","<>"]
+>                ++ map (string . (:[])) "+-^*/%~&<>=[]"
+>                ++ [char '|' *>
+>                    choice ["||" <$ char '|' <* notFollowedBy (char '|')
+>                           ,return "|"]]
+
+
+> sqlWhitespace :: Dialect -> Parser Token
+> sqlWhitespace _ = Whitespace <$> many1 (satisfy isSpace)
+
+> lineComment :: Dialect -> Parser Token
+> lineComment _ =
+>     (\s -> LineComment $ concat ["--",s]) <$>
+>     -- try is used here in case we see a - symbol
+>     -- once we read two -- then we commit to the comment token
+>     (try (string "--") *> (
+>      conc <$> manyTill anyChar (lookAhead lineCommentEnd) <*> lineCommentEnd))
+>   where
+>     conc a Nothing = a
+>     conc a (Just b) = a ++ b
+>     lineCommentEnd = Just "\n" <$ char '\n' <|> Nothing <$ eof
+
+> blockComment :: Dialect -> Parser Token
+> blockComment _ =
+>     (\s -> BlockComment $ concat ["/*",s]) <$>
+>     (try (string "/*") *> commentSuffix 0)
+>   where
+>     commentSuffix :: Int -> Parser String
+>     commentSuffix n = do
+>       -- read until a possible end comment or nested comment
+>       x <- takeWhile (\e -> e /= '/' && e /= '*')
+>       choice [-- close comment: if the nesting is 0, done
+>               -- otherwise recurse on commentSuffix
+>               try (string "*/") *> let t = concat [x,"*/"]
+>                                    in if n == 0
+>                                       then return t
+>                                       else (\s -> concat [t,s]) <$> commentSuffix (n - 1)
+>               -- nested comment, recurse
+>              ,try (string "/*") *> ((\s -> concat [x,"/*",s]) <$> commentSuffix (n + 1))
+>               -- not an end comment or nested comment, continue
+>              ,(\c s -> concat [x, [c], s]) <$> anyChar <*> commentSuffix n]
+
+> dontParseEndBlockComment :: Dialect -> Parser Token
+> dontParseEndBlockComment _ =
+>     -- don't use try, then it should commit to the error
+>     try (string "*/") *> fail "comment end without comment start"
+
+> splice :: Dialect -> Parser Token
+> splice _ = do
+>   Splice
+>   <$> (char '$' *> letter)
+>   <*> (char '(' *> identifierString <* char ')')
+
+> startsWith :: (Char -> Bool) -> (Char -> Bool) -> Parser String
+> startsWith p ps = do
+>   c <- satisfy p
+>   choice [(c:) <$> (takeWhile1 ps)
+>          ,return [c]]
+
+> takeWhile1 :: (Char -> Bool) -> Parser String
+> takeWhile1 p = many1 (satisfy p)
+
+> takeWhile :: (Char -> Bool) -> Parser String
+> takeWhile p = many (satisfy p)
+
+> takeTill :: (Char -> Bool) -> Parser String
+> takeTill p =
+>     manyTill anyChar (peekSatisfy p)
+
+> peekSatisfy :: (Char -> Bool) -> Parser ()
+> peekSatisfy p = do
+>     void $ lookAhead (satisfy p)
diff --git a/src/Database/HsSqlPpp/Internals/ParseErrors.lhs b/src/Database/HsSqlPpp/Internals/ParseErrors.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/ParseErrors.lhs
@@ -0,0 +1,71 @@
+
+convert error messages to show source text fragment with little hat,
+plus output error location in emacs friendly format.
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Internals.ParseErrors
+>     (toParseErrorExtra
+>     ,ParseErrorExtra(..)) where
+>
+> import Text.Parsec
+> import qualified Data.Text.Lazy as L
+>
+> showPE :: ParseError -> Maybe (Int,Int) -> L.Text -> String
+> showPE pe sp src = show pe ++ "\n" ++ pePosToEmacs pe
+>                       ++ "\n" ++ peToContext pe sp src
+>
+> pePosToEmacs :: ParseError -> String
+> pePosToEmacs pe = let p = errorPos pe
+>                       f = sourceName p
+>                       l = sourceLine p
+>                       c = sourceColumn p
+>                   in f ++ ":" ++ show l ++ ":" ++ show c ++ ":"
+>
+> peToContext :: ParseError -> Maybe (Int,Int) -> L.Text -> String
+> peToContext pe sp src =
+>      let ls = L.lines src
+>          line = safeGet ls (lineNo - 1)
+>          prelines = map (safeGet ls) [(lineNo - 5) .. (lineNo - 2)]
+>          postlines = map (safeGet ls) [lineNo .. (lineNo + 5)]
+>          caretLine = L.pack (replicate (colNo - 1) ' ' ++ "^")
+>          erLine = let s = "ERROR HERE"
+>                   in L.pack (replicate (colNo - 1 - (length s `div` 2)) ' ' ++ s)
+>          errorHighlightText = prelines
+>                               ++ [line, caretLine, erLine]
+>                               ++ postlines
+>     in "\nContext:\n"
+>        ++ L.unpack (L.unlines (trimLines errorHighlightText)) ++ "\n"
+>     where
+>       safeGet a i = if i < 0 || i >= length a
+>                       then ""
+>                       else a !! i
+>       trimLines = trimStartLines . reverse . trimStartLines . reverse
+>       trimStartLines = dropWhile (=="")
+>       pos = errorPos pe
+>       lineNo = sourceLine pos - adjLine
+>       colNo = sourceColumn pos
+>       adjLine = case sp of
+>                         Just (l, _) -> l - 1
+>                         Nothing -> 0
+>
+> -- | Simple wrapper to allow showing the source context of a ParseError
+> data ParseErrorExtra =
+>        ParseErrorExtra {
+>                        -- | wrapped error
+>                        parseErrorError :: ParseError
+>                        -- | source position
+>                        -- adjustment to get the
+>                        -- context bit in error
+>                        -- messages right - this is
+>                        -- the same as what is passed
+>                        -- into parseSqlWithPosition
+>                        ,parseErrorPosition :: Maybe (Int, Int)
+>                        -- | sql source
+>                        ,parseErrorSqlSource :: L.Text
+>                        }
+>
+> instance Show ParseErrorExtra where
+>     show (ParseErrorExtra pe sp src) = showPE pe sp src
+>
+> toParseErrorExtra :: L.Text -> Maybe (Int,Int) -> ParseError -> ParseErrorExtra
+> toParseErrorExtra src sp e = ParseErrorExtra e sp src
diff --git a/src/Database/HsSqlPpp/Internals/ParseInternal.lhs b/src/Database/HsSqlPpp/Internals/ParseInternal.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/ParseInternal.lhs
@@ -0,0 +1,2708 @@
+
+The main file for parsing sql, uses parsec. Not sure if parsec is the
+right choice, but it seems to do the job pretty well at the moment.
+
+> {-# LANGUAGE FlexibleContexts,ExplicitForAll,TupleSections,
+>              NoMonomorphismRestriction,OverloadedStrings #-}
+> -- | Functions to parse SQL.
+> module Database.HsSqlPpp.Internals.ParseInternal
+>     (-- * Main
+>      parseStatements
+>     ,parseQueryExpr
+>     ,parseScalarExpr
+>     ,parseProcSQL
+>      -- * parsing flags
+>     ,ParseFlags(..)
+>     --,Dialect(..)
+>     --,ansiDialect
+>      -- * errors
+>     --,ParseErrorExtra(..)
+>      -- other helpers for internal use
+>     ,tableAttribute
+>     ,keyword
+>     ,parens
+>     ,symbol
+>     ,idString
+>     ,commaSep1
+>     ,commaSep
+>     ,parseName
+>     ,parseNameComponent
+>     ) where
+>
+> import Text.Parsec hiding (label) -- many, optional, (<|>), string,
+> import Text.Parsec.Expr
+> import Text.Parsec.String
+> import Text.Parsec.Perm
+> import Text.Parsec.Pos
+>
+> import Control.Applicative hiding (many,optional,(<|>))
+> import Control.Monad.Identity
+> --import Control.Monad
+>
+> import Data.Maybe
+> import Data.Char hiding (Format)
+>
+> import Data.Generics.Uniplate.Data
+> import Data.Data hiding (Prefix,Infix)
+>
+> import qualified Database.HsSqlPpp.Internals.LexInternal as Lex
+> import Database.HsSqlPpp.Internals.ParseErrors
+> import Database.HsSqlPpp.Internals.AstInternal
+> --import Database.HsSqlPpp.Annotation as A
+> import Database.HsSqlPpp.Internals.Utils
+> import Database.HsSqlPpp.Internals.Dialect
+> import Data.Text (Text)
+> import qualified Data.Text as T
+> --import qualified Data.Text.Lazy as LT
+> import Text.Parsec.Text ()
+> --import Database.HsSqlPpp.Catalog
+
+> import qualified Data.Text.Lazy as L
+> --import Database.HsSqlPpp.Internals.StringLike
+
+  import Debug.Trace
+
+--------------------------------------------------------------------------------
+
+Top level parsing functions
+===========================
+
+> -- | Parse a list of statements
+> parseStatements :: ParseFlags -- ^ parse options
+>                 -> FilePath -- ^ filename to use in errors
+>                 -> Maybe (Int,Int) -- ^ set the line number and column number
+>                                    -- of the first char in the source (used in annotation)
+>                 -> L.Text -- ^ a string containing the sql to parse
+>                 -> Either ParseErrorExtra [Statement]
+> parseStatements = parseIt' sqlStatements
+
+> -- | Parse a single query expr
+> parseQueryExpr :: ParseFlags -- ^ parse options
+>                -> FilePath -- ^ filename to use in errors
+>                -> Maybe (Int,Int) -- ^ set the line number and column number
+>                -> L.Text -- ^ a string containing the sql to parse
+>                -> Either ParseErrorExtra QueryExpr
+> parseQueryExpr =
+>   parseIt' $ pQueryExpr <* optional (symbol ";") <* eof
+
+> -- | Parse a single scalar expr
+> parseScalarExpr :: ParseFlags -- ^ parse options
+>                 -> FilePath -- ^ filename to use in errors
+>                 -> Maybe (Int,Int) -- ^ set the line number and column number
+>                 -> L.Text -- ^ a string containing the sql to parse
+>                 -> Either ParseErrorExtra ScalarExpr
+> parseScalarExpr = parseIt' $ expr <* eof
+
+> -- | Parse a list of procedural sql statements
+> parseProcSQL :: ParseFlags -- ^ parse options
+>              -> FilePath -- ^ filename to use in errors
+>              -> Maybe (Int,Int) -- ^ set the line number and column number
+>              -> L.Text -- ^ a string containing the sql to parse
+>              -> Either ParseErrorExtra [Statement]
+> parseProcSQL = parseIt' $ many plPgsqlStatement <* eof
+
+> parseIt' :: Data a =>
+>             SParser a
+>          -> ParseFlags
+>          -> FilePath
+>          -> Maybe (Int,Int)
+>          -> L.Text
+>          -> Either ParseErrorExtra a
+> parseIt' ps flg fn sp src = do
+>   lxd <- lexem (pfDialect flg) fn sp src
+>   psd <- either (\e -> Left $ ParseErrorExtra e sp src) Right
+>          $ runParser ps flg fn lxd
+>   return $ fixupTree psd
+
+> lexem :: Dialect
+>        -> FilePath
+>        -> Maybe (Int,Int)
+>        -> L.Text
+>        -> Either ParseErrorExtra [Token]
+> lexem d fn sp src =
+>   let ts :: Either ParseErrorExtra [Token]
+>       ts = either (\e -> Left $ ParseErrorExtra e sp src) Right
+>             $ Lex.lexTokens d fn sp src
+>   in --trace ((\(Right r) -> intercalate "\n" $ map show r) ts) $
+>      filter keep `fmap` ts
+>   where
+>     keep (_,Lex.Whitespace {}) = False
+>     keep (_,Lex.LineComment {}) = False
+>     keep (_,Lex.BlockComment {}) = False
+>     keep _ = True
+
+Parse state used for parse flags. Might be better to use a readerT
+somehow, but I'm not smart enough to work out how to do this. This
+state is never updated during parsing
+
+> -- | Settings to influence the parsing
+> data ParseFlags = ParseFlags
+>     {pfDialect :: Dialect
+>     }
+>     deriving (Show,Eq)
+
+> type ParseState = ParseFlags
+
+> isSqlServer :: SParser Bool
+> isSqlServer = do
+>   ParseFlags {pfDialect = d} <- getState
+>   return $ diSyntaxFlavour d == SqlServer
+
+> isOracle :: SParser Bool
+> isOracle = do
+>   ParseFlags {pfDialect = d} <- getState
+>   return $ diSyntaxFlavour d == Oracle
+
+couple of wrapper functions for the quoting
+
+> parseName :: ParseFlags
+>           -> FilePath
+>           -> Maybe (Int,Int)
+>           -> L.Text
+>           -> Either ParseErrorExtra Name
+> parseName = parseIt' $ name <* eof
+
+> parseNameComponent :: ParseFlags
+>                    -> FilePath
+>                    -> Maybe (Int,Int)
+>                    -> L.Text
+>                    -> Either ParseErrorExtra NameComponent
+> parseNameComponent = parseIt' $ nameComponent <* eof
+
+
+--------------------------------------------------------------------------------
+
+
+> type Token = ((FilePath,Int,Int),Lex.Token)
+
+> type SParser =  GenParser Token ParseState
+
+Parsing top level statements
+============================
+
+> sqlStatements :: SParser [Statement]
+> sqlStatements = many (sqlStatement True) <* eof
+>
+> sqlStatement :: Bool -> SParser Statement
+> sqlStatement reqSemi =
+>    (choice [
+>      antiStatement
+>     ,queryStatement
+>     ,insert
+>     ,update
+>     ,delete
+>     ,truncateSt
+>     ,copy
+>     ,--do
+>      --not <$> isSqlServer >>= guard
+>      set
+>     ,notify
+>     ,keyword "create" *>
+>              choice [
+>                -- todo: this is bad
+>                -- why do we have create outside
+>                -- but then have 'or replace' inside the
+>                -- invididual parsers, making it impossible
+>                -- to get rid of the try here?
+>                 try createTable
+>                ,createSequence
+>                ,createType
+>                ,createFunction
+>                ,createView
+>                ,createDomain
+>                ,createDatabase
+>                ,createLanguage
+>                ,createTrigger
+>                ,createIndex
+>                ,createLogin
+>                ,createUser
+>                ,createSchema]
+>     ,keyword "alter" *>
+>              choice [
+>                 alterSequence
+>                ,alterTable
+>                ,alterDatabase
+>                ,alterLogin
+>                ,alterUser
+>                ,alterView
+>                ,alterSchema]
+>     ,keyword "drop" *>
+>              choice [
+>                 dropSomething
+>                ,dropFunction
+>                ,dropTrigger]]
+>     <* stmtEnd (not reqSemi))
+>    <|> copyData
+
+--------------------------------------------------------------------------------
+
+statement flavour parsers
+=========================
+
+top level/sql statements first
+
+query expr
+
+> queryStatement :: SParser Statement
+> queryStatement = QueryStatement <$> pos <*> pQueryExpr
+
+this is the plpgsql into
+
+> into :: SParser (Statement -> Statement)
+> into = do
+>   p <- pos <* keyword "into"
+>   st <- option False (True <$ keyword "strict")
+>   is <- commaSep1 name
+>   return $ \s -> Into p st is s
+
+> intoQueryStatement :: SParser Statement
+> intoQueryStatement = do
+>   (i,_) <- pQueryExprX True
+>   case i of
+>     Nothing -> fail "not into"
+>     Just s -> return s
+
+> pQueryExpr :: SParser QueryExpr
+> pQueryExpr = snd <$> pQueryExprX False
+
+bit convoluted to parse the into part
+TODO: used to parse the into in the select list parser,
+maybe it should still do this since it would probably be a lot clearer
+
+
+> pQueryExprX :: Bool -> SParser (Maybe Statement, QueryExpr)
+> pQueryExprX allowInto =
+>   ((Nothing,) <$> with)
+>   <|>  buildExpressionParser combTable selFactor
+>   where
+>         selFactor = choice [try ((Nothing,) <$> parens pQueryExpr)
+>                            ,selQuerySpec
+>                            ,(Nothing,) <$> values]
+>         with = WithQueryExpr <$> (pos <* keyword "with")
+>                              <*> commaSep1 withQuery
+>                              <*> pQueryExpr
+>         withQuery = WithQuery <$> pos
+>                               <*> nameComponent
+>                               <*> tryOptionMaybe (parens $ commaSep nameComponent)
+>                               <*> (keyword "as" *> parens pQueryExpr)
+>         combTable =
+>            [map makeOp [(Except, keyword "except")
+>                        ,(Intersect, keyword "intersect")
+>                        ,(UnionAll, try (keyword "union" *> keyword "all"))
+>                        ,(Union, keyword "union")]]
+>         makeOp (c,p) =
+>            Infix (do
+>                   cmb <- CombineQueryExpr
+>                          <$> pos
+>                          <*> (c <$ p)
+>                   return $ \s0 s1 -> (Nothing, cmb (snd s0) (snd s1))
+>                  ) AssocLeft
+>         selQuerySpec = do
+>           p <- pos <* keyword "select"
+>           -- todo: support explicit all
+>           d <- option All (Distinct <$ distinctKeyword)
+>           -- hacky parsing of sql server 'top n' style select
+>           -- quiz: what happens when you use top n and limit at the same time?
+>           tp <- choice
+>                 [do
+>                  isSqlServer >>= guard
+>                  optionMaybe $ try
+>                      (keyword "top" *>
+>                       choice [parens expr
+>                              -- not sure why you can't write expr without parens
+>                              -- but it doesn't work TODO: fix this
+>                              -- the current hack only allows a single number
+>                              -- if you don't also use parens
+>                              ,NumberLit <$> pos <*> (show <$> integer)])
+>                 ,return Nothing]
+>           -- todo: work out how to make this work properly - need to return
+>           -- the into
+>           (sl,intoBit) <- if allowInto
+>                           then permute ((,)
+>                                         <$$> try selectList
+>                                         <|?> (Nothing, Just <$> into))
+>                           else (,Nothing) <$> selectList
+>           s <- Select p d sl
+>                    <$> option [] from
+>                    <*> optionMaybe whereClause
+>                    <*> option [] groupBy
+>                    <*> optionMaybe having
+>                    <*> orderBy
+>                    <*> option tp (Just <$> limit)
+>                    <*> optionMaybe offset
+>                    <*> option [] hints
+>           return (case intoBit of
+>                       Just f -> Just $ f $ QueryStatement p s
+>                       Nothing -> Nothing
+>                  ,s)
+>         from = keyword "from" *> commaSep1 tableRef
+>         groupBy = keyword "group" *> keyword "by"
+>                   *> commaSep1 expr
+>         having = keyword "having" *> expr
+>         limit = keyword "limit" *> expr
+>         offset = keyword "offset" *> expr
+>         values = Values <$> (pos <* keyword "values")
+>                         <*> commaSep1 (parens $ commaSep1 expr)
+>         hints = keyword "option" *> (parens $ commaSep1 queryHint)
+
+
+> distinctKeyword :: SParser ()
+> distinctKeyword =
+>     choice
+>     [do
+>      isOracle >>= guard
+>      keyword "unique"
+>      return ()
+>     ,keyword "distinct"]
+
+> queryHint :: SParser QueryHint
+> queryHint = choice
+>             [QueryHintPartitionGroup <$ keyword "partition" <* keyword "group"
+>             ,QueryHintColumnarHostGroup <$ keyword "columnar" <* keyword "host" <* keyword "group"]
+
+> orderBy :: SParser [(ScalarExpr,Direction, NullsOrder)]
+> orderBy = option []
+>             (keyword "order" *> keyword "by"
+>                              *> commaSep1 oneOrder)
+
+>           where
+>             oneOrder = (,,) <$> expr <*> direction <*> nullsOrder
+>             direction = option Asc (choice [
+>                                        Asc <$ keyword "asc"
+>                                       ,Desc <$ keyword "desc"])
+>             nullsOrder = option NullsDefault (keyword "nulls" >> choice [
+>                                         NullsFirst <$ keyword "first"
+>                                        ,NullsLast  <$ keyword "last"])
+
+table refs
+
+only way of combining them is joins which parse left associative which
+makes it easy
+
+> tableRef :: SParser TableRef
+> tableRef = nonJoin >>= optionalJoinSuffix
+>   where
+>     nonJoin = do
+>               -- read parens and a subquery or tableref
+>               -- or a funtref or just a tref
+>               t <- choice
+>                    [do
+>                     p <- pos
+>                     parens $ choice [try $ SubTref p <$> pQueryExpr
+>                                     ,TableRefParens p <$> tableRef]
+>                     -- should combine the funtref and tref parsing
+>                    ,try $ FunTref <$> pos
+>                                   <*> (identifier >>= functionCallSuffix)
+>                    ,OdbcTableRef <$> (pos <* symbol "{" <* keyword "oj")
+>                                  <*> (tableRef <* symbol "}")
+>                    ,Tref <$> pos <*> name]
+>               optionalAlias t
+>     optionalAlias t = do
+>               -- try and read an alias
+>               a <- optionMaybe $ try alias
+>               -- ignore an optional hint if this is sql server
+>               _ <- choice [do isSqlServer >>= guard
+>                               _ <- try $ optional tableHint
+>                               return ()
+>                           ,return ()]
+>               -- wrap the tref from before with the alias
+>               -- if got one
+>               return $ maybe t (\f -> f t) a
+
+>     alias :: SParser (TableRef -> TableRef)
+>     alias = do
+>             p <- pos
+>             optionalSuffix
+>                  (TableAlias p) (optional (keyword "as") *> nameComponent)
+>                  (FullAlias p) (parens $ commaSep1 nameComponent)
+>     optionalJoinSuffix tr =
+>       choice [try (joinSuffix tr)
+>               >>= optionalAlias
+>               >>= optionalJoinSuffix
+>              ,return tr]
+>     joinSuffix tr = do
+>       let p = getAnnotation tr
+>       (nat,hint,jt) <- joinKw
+>       JoinTref p tr nat jt hint
+>           <$> nonJoin
+>           <*> onExpr
+>     joinKw = do
+>              --look for the join flavour first
+>              n <- option Unnatural (Natural <$ keyword "natural")
+>              jt <- choice [
+>                     LeftOuter <$ try (keyword "left"
+>                                       *> optional (keyword "outer"))
+>                    ,RightOuter <$ try (keyword "right"
+>                                        *> optional (keyword "outer"))
+>                    ,FullOuter <$ try (keyword "full"
+>                                       *> optional (keyword "outer"))
+>                    ,Cross <$ keyword "cross"
+>                    ,Inner <$ optional (keyword "inner")]
+>              hint <- option Nothing (Just <$> choice [Merge <$ keyword "merge"
+>                                                      ,Loop <$ keyword "loop"
+>                                                      ,Hash <$ keyword "hash"])
+>              keyword "join"
+>              return (n,hint,jt)
+>     onExpr = choice
+>              [Just <$> (JoinOn <$> pos <*> (keyword "on" *> expr))
+>              ,Just <$> (JoinUsing <$> pos
+>                                   <*> (keyword "using" *> columnNameList))
+>              ,return Nothing]
+
+>     tableHint = do
+
+just acts as an incomplete recogniser for table hints:
+it doesn't accept all valid table hints
+and doesn't reject all invalid table hints
+and it doesn't return anything in the ast
+but allows you to parse some queries containing with hints and get
+everything else
+
+>           try $ keyword "with"
+>           -- just allows any list of identifiers
+>           _ <- parens $ commaSep1 idString
+>           return ()
+>
+> optParens :: SParser a
+>           -> SParser a
+> optParens p = try (parens p) <|> p
+
+
+insert, update and delete
+-------------------------
+
+insert statement: supports option column name list,
+multiple rows to insert and insert from select statements
+
+> insert :: SParser Statement
+> insert = Insert
+>          <$> pos <* keyword "insert" <* keyword "into"
+>          <*> name
+>          <*> option [] (try columnNameList)
+>          <*> pQueryExpr
+>          <*> tryOptionMaybe returning
+>
+> update :: SParser Statement
+> update = Update
+>          <$> pos <* keyword "update"
+>          <*> name
+>          <*> (keyword "set" *> commaSep1 setClause)
+>          <*> option [] (keyword "from" *> commaSep1 tableRef)
+>          <*> tryOptionMaybe whereClause
+>          <*> tryOptionMaybe returning
+>     where
+>       setClause =
+>         choice [do
+>           p <- pos
+>           l <- parens (commaSep1 nameComponent)
+>           symbol "="
+>           r <- parens (commaSep1 expr)
+>           return $ MultiSetClause p l $ SpecialOp p (nm p "rowctor") r
+>         ,do
+>           p <- pos
+>           l <- nameComponent
+>           symbol "="
+>           r <- expr
+>           return $ SetClause p l r]
+
+> nm :: Annotation -> Text -> Name
+> nm a s = Name a [Nmc $ T.unpack s]
+
+> delete :: SParser Statement
+> delete = Delete
+>          <$> pos <* keyword "delete" <* keyword "from"
+>          <*> name
+>          <*> option [] (keyword "using" *> commaSep1 tableRef)
+>          <*> tryOptionMaybe whereClause
+>          <*> tryOptionMaybe returning
+>
+
+other dml-type stuff
+--------------------
+
+> truncateSt :: SParser Statement
+> truncateSt =
+>            Truncate
+>            <$> pos <* keyword "truncate" <* optional (keyword "table")
+>            <*> commaSep1 name
+>            <*> option ContinueIdentity (choice [
+>                                 ContinueIdentity <$ (keyword "continue"
+>                                                      <* keyword "identity")
+>                                ,RestartIdentity <$ (keyword "restart"
+>                                                     <* keyword "identity")])
+>            <*> cascade
+>
+> copy :: SParser Statement
+> copy = do
+>        p <- pos
+>        keyword "copy"
+>        -- todo: factor this a bit better
+
+>        choice -- left factoring to preserve error messages
+>          [ parens pQueryExpr >>= to p . CopyQuery
+>          , do (tblName, cols) <- liftA2 (,) name (option [] (parens $ commaSep1 nameComponent))
+>               choice
+>                 [ from p tblName cols
+>                 , to p (CopyTable tblName cols)
+>                 ]
+>          ]
+
+>   where
+>     from p tableName cols = do
+>        keyword "from"
+>        src <- choice [
+>                CopyFilename <$> extrStr <$> stringLit
+>               ,Stdin <$ keyword "stdin"]
+>        opts <- option [] $ do
+>                  keyword "with" *> copyFromOptions
+>        return $ CopyFrom p tableName cols src opts
+>     to p src = do
+>        keyword "to"
+>        fn <- extrStr <$> stringLit
+>        opts <- option [] $ do
+>                  keyword "with" *> copyToOptions
+>        return $ CopyTo p src fn opts
+
+>     copyToOptions = do
+>       (a,b,c,d) <- permute ((,,,)
+>                             <$?> (Nothing,Just <$> CopyToFormat <$>
+>                                              (keyword "format" *> idString))
+>                             <|?> (Nothing,Just <$> CopyToDelimiter <$>
+>                                              (keyword "delimiter" *> stringN))
+>                             <|?> (Nothing,Just <$> CopyToErrorLog <$>
+>                                              (keyword "error_log" *> stringN))
+>                             <|?> (Nothing,Just <$> CopyToErrorVerbosity <$>
+>                                              (keyword "error_verbosity" *> (fromIntegral <$> integer)))
+>                            )
+>       return $ catMaybes [a,b,c,d]
+
+>     copyFromOptions = do
+>       (a,b,c,d,e,f,g,h,i,j) <- permute ((,,,,,,,,,)
+>                          <$?> (Nothing,Just <$> CopyFromFormat <$>
+>                                           (keyword "format" *> idString))
+>                          <|?> (Nothing,Just <$> CopyFromDelimiter <$>
+>                                           (keyword "delimiter" *> stringN))
+>                          <|?> (Nothing,Just <$> CopyFromErrorLog <$>
+>                                           (keyword "error_log" *> (stringN <?> "path wrapped in apostrophes. for example: 'file.csv'.")))
+>                          <|?> (Nothing,Just <$> CopyFromErrorVerbosity <$>
+>                                           (keyword "error_verbosity" *> (fromIntegral <$> integer)))
+>                          <|?> (Nothing,Just <$> CopyFromParsers <$>
+>                                           (keyword "parsers" *> stringN) <?> "list of parsers")
+>                          <|?> (Nothing,Just <$> (CopyFromDirectory <$ keyword "directory"))
+>                          <|?> (Nothing,Just <$> CopyFromOffset <$>
+>                                           (keyword "offset" *> (integer <?> "positive integer")) <?> "offset with integer")
+>                          <|?> (Nothing,Just <$> CopyFromLimit <$>
+>                                           (keyword "limit" *> (integer <?> "positive integer")) <?> "limit with integer")
+>                          <|?> (Nothing,Just <$> CopyFromErrorThreshold <$>
+>                                           (keyword "stop" *> keyword "after" *> (fromIntegral <$> (integer <?> "positive integer")) <* keyword "errors"))
+>                          <|?> (Nothing,Just <$> CopyFromNewlineFormat <$>
+>                                           (keyword "record" *> keyword "delimiter" *> stringN))
+>                          )
+>       return $ catMaybes [a,b,c,d,e,f,g,h,i,j]
+
+> copyData :: SParser Statement
+> copyData = CopyData <$> pos <*> mytoken (\tok ->
+>                                         case tok of
+>                                                  Lex.CopyPayload n -> Just n
+>                                                  _ -> Nothing)
+>
+
+--------------------------------------------------------------------------------
+
+misc
+====
+
+> set :: SParser Statement
+> set = Set <$> pos
+>       <*> (keyword "set" *> idString)
+>       <*> ((keyword "to" <|> symbol "=") *>
+>            commaSep1 sv)
+>   where
+>         sv = choice [
+>               SetStr <$> pos <*> stringN
+>              ,SetId <$> pos <*> idString
+>              ,SetNum <$> pos <*> (try (fromInteger <$> integer)
+>                                   <|> (read <$> numString))]
+>
+> notify :: SParser Statement
+> notify = Notify <$> pos
+>                 <*> (keyword "notify" *> idString)
+
+--------------------------------------------------------------------------------
+ 
+ddl
+===
+
+> createTable :: SParser Statement
+> createTable = do
+>   p <- pos
+>   rep <- choice [NoReplace <$ keyword "table"
+>                 ,Replace <$ mapM_ keyword ["or", "replace", "table"]
+>                 ] 
+>   tname <- name
+>   choice [
+>      CreateTableAs p tname rep <$> (keyword "as" *> pQueryExpr)
+>                            
+>     ,do
+>      (atts,cons) <- readAttsAndCons
+>      pdata <- readPartition
+>      return $ CreateTable p tname atts cons pdata rep
+>     ]
+>   where
+>     --parse the unordered list of attribute defs or constraints, for
+>     --each line want to try the constraint parser first, then the
+>     --attribute parser, so you need the swap to feed them in the
+>     --right order into createtable
+>     readAttsAndCons =
+>               parens (swap <$> multiPerm
+>                                  (try tableConstraint)
+>                                  tableAttribute
+>                                  (symbol ","))
+>               where swap (a,b) = (b,a)
+>     readPartition = tryOptionMaybe (tablePartition)
+
+>
+> tableAttribute :: SParser AttributeDef
+> tableAttribute = AttributeDef
+>                <$> pos
+>                <*> nameComponent
+>                <*> typeName
+>                <*> tryOptionMaybe (keyword "default" *> expr)
+>                <*> many rowConstraint
+>   where
+>     rowConstraint = do
+>        p <- pos
+>        cn <- option "" (keyword "constraint" *> idString)
+>        choice [
+>           RowUniqueConstraint p cn <$ keyword "unique"
+>          ,RowPrimaryKeyConstraint p cn <$ keyword "primary" <* keyword "key"
+>          ,RowCheckConstraint p cn <$> (keyword "check" *> parens expr)
+>          ,NullConstraint p cn <$ keyword "null"
+>          ,NotNullConstraint p cn <$ (keyword "not" <* keyword "null")
+>          ,IdentityConstraint p cn <$> (keyword "identity" *>
+>                                        tryOptionMaybe (parens $ (,) <$>
+>                                          signedInteger <*> (symbol "," *> signedInteger)))
+>          ,RowReferenceConstraint p cn
+>          <$> (keyword "references" *> name)
+>          <*> option Nothing (try $ parens $ Just <$> nameComponent)
+>          <*> onDelete
+>          <*> onUpdate
+>          ]
+>
+
+> tablePartition :: SParser TablePartitionDef
+> tablePartition = do
+>         p <- pos
+>          -- partition by range (<col name>) ( every 5 minutes )
+>         cn <- (keyword "partition" *> keyword "by" *> keyword "range" *> (parens nameComponent))
+>         (a,b) <- parens $ keyword "every" *> try ((,) <$>
+>                                         (option 1 integer) <*> timeframe)
+>         return $ TablePartitionDef p cn a b
+>   where
+>     timeframe =
+>       choice [Year <$ keyword "years"
+>              ,Year <$ keyword "year"
+>              ,Month <$ keyword "months"
+>              ,Month <$ keyword "month"
+>              ,Day <$ keyword "days"
+>              ,Day <$ keyword "day"
+>              ,Hour <$ keyword "hours"
+>              ,Hour <$ keyword "hour"
+>              ,Minute <$ keyword "minutes"
+>              ,Minute <$ keyword "minute"
+>              ,Second <$ keyword "seconds"
+>              ,Second <$ keyword "second"
+>              ,Millisecond <$ keyword "milliseconds"
+>              ,Millisecond <$ keyword "millisecond"
+>              ]
+>
+> onDelete,onUpdate :: SParser Cascade
+> onDelete = onSomething "delete"
+> onUpdate = onSomething "update"
+>
+> onSomething :: Text -> SParser Cascade
+> onSomething k = option Restrict $ try $ keyword "on"
+>                 *> keyword k *> cascade
+>
+> tableConstraint :: SParser Constraint
+> tableConstraint = do
+>                 p <- pos
+>                 cn <- option "" (keyword "constraint" *> option "" conName)
+>                 choice [
+>                    UniqueConstraint p cn
+>                    <$> try (keyword "unique" *> optParens columnNameList)
+>                    ,PrimaryKeyConstraint p cn
+>                    <$> try (keyword "primary" *> keyword "key"
+>                                     *> choice [
+>                                             (:[]) <$> nameComponent
+>                                            ,parens (commaSep1 nameComponent)])
+>                    ,CheckConstraint p cn
+>                    <$>try (keyword "check" *> parens expr)
+>                    ,ReferenceConstraint p cn
+>                    <$> try (keyword "foreign" *> keyword "key"
+>                             *> parens (commaSep1 nameComponent))
+>                    <*> (keyword "references" *> name)
+>                    <*> option [] (parens $ commaSep1 nameComponent)
+>                    <*> onUpdate
+>                    <*> onDelete]
+>                 where
+>                   conName = try $ do
+>                             x <- idString
+>                             if map toLower x `elem` [
+>                                     "unique"
+>                                    ,"primary"
+>                                    ,"check"
+>                                    ,"foreign"
+>                                    ,"references"]
+>                               then fail $ "not keyword (constraint name): " ++ x
+>                               else return x
+>
+> alterDatabase :: SParser Statement
+> alterDatabase = AlterDatabase
+>                  <$> (pos <* keyword "database")
+>                     <*> name
+>                     <*> operation
+>  where
+>   operation = try renameDatabase
+>   renameDatabase = RenameDatabase
+>                      <$> (pos <* keyword "rename" <* keyword "to")
+>                      <*> name
+> alterTable :: SParser Statement
+> alterTable = AlterTable <$> (pos <* keyword "table"
+>                              <* optional (keyword "only"))
+>                         <*> name
+>                         <*> operation
+>              where
+>                operation = choice [try renameTable,try renameColumn,actions]
+>                renameTable = RenameTable
+>                              <$> (pos <* keyword "rename" <* keyword "to")
+>                              <*> name
+>                renameColumn = RenameColumn
+>                               <$> (pos <* keyword "rename" <* keyword "column")
+>                               <*> nameComponent
+>                               <*> (keyword "to" *> nameComponent)
+>                actions = AlterTableActions <$> pos <*> commaSep1 action
+>                action = choice [try addColumn
+>                                ,try dropColumn
+>                                ,try alterColumn
+>                                ,addConstraint]
+>                addColumn = AddColumn
+>                            <$> pos
+>                            <*> (keyword "add" *> keyword "column" *> tableAttribute)
+>                dropColumn = DropColumn
+>                             <$> pos
+>                             <*> (keyword "drop" *> keyword "column" *> nameComponent)
+>                alterColumn = AlterColumn
+>                              <$> (pos <* keyword "alter" <* keyword "column")
+>                              <*> nameComponent
+>                              <*> alterColumnAction
+>                alterColumnAction = choice [try alterType
+>                                           ,try setNotNull
+>                                           ,try dropNotNull
+>                                           ,try setDefault
+>                                           ,dropDefault]
+>                alterType = SetDataType
+>                            <$> pos
+>                            <*> (keyword "set" *> keyword "data" *> keyword "type" *> typeName)
+>                setNotNull = SetNotNull
+>                             <$> (pos <* keyword "set" <* keyword "not" <* keyword "null")
+>                dropNotNull = DropNotNull
+>                              <$> (pos <* keyword "drop" <* keyword "not" <* keyword "null")
+>                setDefault = SetDefault
+>                             <$> pos
+>                             <*> (keyword "set" *> keyword "default" *> expr)
+>                dropDefault = DropDefault
+>                              <$> (pos <* keyword "drop" <* keyword "default")
+>                addConstraint = AddConstraint
+>                                <$> (pos <* keyword "add")
+>                                <*> tableConstraint
+> createType :: SParser Statement
+> createType = CreateType
+>              <$> pos <* keyword "type"
+>              <*> name
+>              <*> (keyword "as" *> parens (commaSep1 typeAtt))
+>   where
+>     typeAtt = TypeAttDef <$> pos <*> nameComponent <*> typeName
+>
+> createSequence :: SParser Statement
+> createSequence = do
+>   p <- pos
+>   keyword "sequence"
+>   snm <- name
+>   (stw, incr, mn, mx, c) <-
+>      permute ((,,,,) <$?> (1,startWith)
+>                      <|?> (1,increment)
+>                      <|?> (Nothing, sequenceMinValue)
+>                      <|?> (Nothing, sequenceMaxValue)
+>                      <|?> (1, cache))
+>   return $ CreateSequence p snm incr mn mx stw c
+>   where
+>     startWith = keyword "start" *> optional (keyword "with") *> integer
+>     increment = keyword "increment" *> optional (keyword "by") *> integer
+>     cache = keyword "cache" *> integer
+>
+> alterSequence :: SParser Statement
+> alterSequence = AlterSequence <$> pos
+>                               <*> (keyword "sequence" *> name)
+>                               <*> operation
+>   where
+>     operation = choice [try renameSequence,try changeOwner,actions]
+>     renameSequence = AlterSequenceRename <$> (pos <* keyword "rename" <* keyword "to") <*> name
+>     changeOwner  = AlterSequenceOwned <$> (pos <* keyword "owned" <* keyword "by") <*> name
+>     actions = AlterSequenceActions <$> pos <*> many1 action
+>     action = choice [try alterIncrement
+>                     ,try alterMin
+>                     ,try alterMax
+>                     ,try alterStart
+>                     ,try alterRestart
+>                     ,alterCache]
+>     alterIncrement = AlterSequenceIncrement <$> (pos <* keyword "increment" <* optional (keyword "by")) <*> integer
+>     alterMin = AlterSequenceMin <$> pos <*> sequenceMinValue
+>     alterMax = AlterSequenceMax <$> pos <*> sequenceMaxValue
+>     alterStart = AlterSequenceStart <$> (pos <* keyword "start" <* optional (keyword "with")) <*> integer
+>     alterRestart = AlterSequenceRestart <$> (pos <* keyword "restart")
+>                                         <*> optionMaybe (optional (keyword "with") *> integer)
+>     alterCache = AlterSequenceCache <$> (pos <* keyword "cache") <*> integer
+
+> sequenceMinValue :: SParser (Maybe Integer)
+> sequenceMinValue = choice [try (Nothing <$ keyword "no" <* keyword "minvalue")
+>                           ,Just <$> (keyword "minvalue" *> integer)]
+
+> sequenceMaxValue :: SParser (Maybe Integer)
+> sequenceMaxValue = choice [try (Nothing <$ keyword "no" <* keyword "maxvalue")
+>                           ,Just <$> (keyword "maxvalue" *> integer)]
+
+
+
+
+create function, support sql functions and plpgsql functions. Parses
+the body in both cases and provides a statement list for the body
+rather than just a string. TODO: maybe support other languages by
+returning the function body just as a string instead of attempting to
+parse it
+
+> createFunction :: SParser Statement
+> createFunction = do
+>   p <- pos
+>   rep <- choice [NoReplace <$ keyword "function"
+>                 ,Replace <$ mapM_ keyword ["or", "replace", "function"]
+>                 ]
+>   fnName <- name
+>   params <- parens $ commaSep param
+>   retType <- keyword "returns" *> typeName
+>   ((bodypos,body), lang,vol) <-
+>     permute ((,,) <$$> parseAs
+>                   <||> readLang
+>                   <|?> (Volatile,pVol))
+>   flg <- getState
+>   case parseBody flg lang body bodypos of
+>        Left er -> fail er
+>        Right b ->
+>          return $ CreateFunction p fnName params retType rep lang b vol
+>     where
+>         parseAs = do
+>                    keyword "as"
+>                    bodypos <- toMySp <$> getPosition
+>                    body <- stringLit
+>                    return (bodypos,body)
+>         pVol = matchAKeyword [("volatile", Volatile)
+>                              ,("stable", Stable)
+>                              ,("immutable", Immutable)]
+>         readLang = keyword "language" *> matchAKeyword [("plpgsql", Plpgsql)
+>                                                        ,("sql",Sql)]
+>         parseBody :: ParseFlags -> Language -> ScalarExpr -> MySourcePos
+>                   -> Either String FnBody
+>         parseBody flg lang body (fileName,line,col) =
+>             case parseIt'
+>                   (functionBody lang)
+>                   flg
+>                   fileName
+>                   (Just (line,col))
+>                   (L.fromChunks [T.pack $ extrStr body]) of
+>                      Left er@(ParseErrorExtra {}) -> Left $ show er
+>                      Right body' -> Right body'
+>         -- sql function is just a list of statements, the last one
+>         -- has the trailing semicolon optional
+>         functionBody Sql = do
+>            p <- pos
+>            a <- many (try $ sqlStatement True)
+>            -- this makes my head hurt, should probably write out
+>            -- more longhand
+>            SqlFnBody p <$> option a (((a++) . (:[])) <$> sqlStatement False)
+>         -- plpgsql function has an optional declare section, plus
+>         -- the statements are enclosed in begin ... end; (semi colon
+>         -- after end is optional)
+>         functionBody Plpgsql =
+>             PlpgsqlFnBody <$> pos <*> do
+>                    p <- pos
+>                    l <- label
+>                    block p l <* optional (symbol ";") <* eof
+
+params to a function
+
+> param :: SParser ParamDef
+> param = choice [
+>          try (ParamDef <$> pos <*> nameComponent <*> typeName)
+>         ,ParamDefTp <$> pos <*> typeName]
+
+variable declarations in a plpgsql function
+
+> varDef :: SParser VarDef
+> varDef = do
+>   p <- pos
+>   a <- nameComponent
+>   choice [do
+>           keyword "alias"
+>           keyword "for"
+>           choice [
+>             VarAlias p a <$> name
+>            ,ParamAlias p a <$> liftPositionalArgTok]
+>          ,VarDef p a
+>           <$> typeName
+>           <*> tryOptionMaybe ((symbol ":=" <|> symbol "=")*> expr)
+>           ]
+>     <* symbol ";"
+>
+> createView :: SParser Statement
+> createView = CreateView
+>              <$> pos <* keyword "view"
+>              <*> name
+>              <*> tryOptionMaybe (parens $ commaSep nameComponent)
+>              <*> (keyword "as" *> pQueryExpr)
+
+> alterView :: SParser Statement
+> alterView = AlterView
+>              <$> pos <* keyword "view"
+>              <*> name
+>              <*> tryOptionMaybe (parens $ commaSep nameComponent)
+>              <*> (keyword "as" *> pQueryExpr)
+
+> alterSchema :: SParser Statement
+> alterSchema = AlterSchema
+>                <$> pos <* keyword "schema"
+>                <*> nameComponent
+>                <*> operation
+>             where
+>                operation = choice [try changeOwner, renameSchema]
+>                renameSchema = AlterSchemaName
+>                              <$> (pos <* keyword "rename" <* keyword "to")
+>                              <*> nameComponent
+>                changeOwner  = AlterSchemaOwner
+>                              <$> (pos <* keyword "owner" <* keyword "to")
+>                              <*> name
+
+>
+> createDomain :: SParser Statement
+> createDomain = CreateDomain
+>                <$> pos <* keyword "domain"
+>                <*> name
+>                <*> (tryOptionMaybe (keyword "as") *> typeName)
+>                <*> option "" (keyword "constraint" *> idString)
+>                <*> tryOptionMaybe (keyword "check" *> parens expr)
+
+> createDatabase :: SParser Statement
+> createDatabase = CreateDatabase
+>                <$> pos <* keyword "database"
+>                <*> name
+>
+
+> createSchema :: SParser Statement
+> createSchema = CreateSchema
+>                <$> pos <* keyword "schema"
+>                <*> nameComponent
+>                <*> tryOptionMaybe (keyword "authorization" *> name)
+
+> dropSomething :: SParser Statement
+> dropSomething = do
+>   p <- pos
+>   x <- try (choice [
+>                  Domain <$ keyword "domain"
+>                 ,Type <$ keyword "type"
+>                 ,Table <$ keyword "table"
+>                 ,View <$ keyword "view"
+>                 ,Database <$ keyword "database"
+>                 ,User <$ keyword "user"
+>                 ,Login <$ keyword "login"
+>                 ,Schema <$ keyword "schema"
+>             ])
+>   (i,e,r) <- parseDrop name
+>   return $ DropSomething p x i e r
+>
+> dropTrigger :: SParser Statement
+> dropTrigger = do
+>   p <- pos
+>   _ <- keyword "trigger"
+>   (i,e,t,r) <- parseDrop' nameComponent name
+>   return $ DropTrigger p i e t r
+>
+> dropFunction :: SParser Statement
+> dropFunction = do
+>                p <- pos
+>                keyword "function"
+>                (i,e,r) <- parseDrop pFun
+>                return $ DropFunction p i e r
+>                where
+>                  pFun = (,) <$> name
+>                             <*> parens (commaSep typeName)
+
+> parseDrop :: SParser a
+>           -> SParser (IfExists, [a], Cascade)
+> parseDrop p = (,,)
+>               <$> ifExists
+>               <*> commaSep1 p
+>               <*> cascade
+>     where
+>       ifExists = option Require
+>                  (try $ IfExists <$ (keyword "if"
+>                                      *> keyword "exists"))
+>
+> parseDrop' :: SParser a
+>            -> SParser b
+>            -> SParser (IfExists, a, b, Cascade)
+> parseDrop' p q = (,,,)
+>                  <$> ifExists
+>                  <*> p
+>                  <*> (keyword "on" *> q)
+>                  <*> cascade
+>     where
+>       ifExists = option Require
+>                  (try $ IfExists <$ (keyword "if"
+>                                      *> keyword "exists"))
+>
+> createLanguage :: SParser Statement
+> createLanguage =
+>   CreateLanguage <$> pos
+>                  <*> (optional (keyword "procedural") *>
+>                       keyword "language" *>
+>                       idString)
+>
+> createTrigger :: SParser Statement
+> createTrigger =
+>   CreateTrigger <$> pos
+>                 <*> (keyword "trigger" *> nameComponent)
+>                 <*> twhen
+>                 <*> tevents
+>                 <*> (keyword "on" *> name)
+>                 <*> tfiring
+>                 <*> (keyword "execute" *> keyword "procedure"
+>                      *> name)
+>                 <*> parens (commaSep expr)
+>   where
+>     twhen = choice [TriggerBefore <$ keyword "before"
+>                    ,TriggerAfter <$ keyword "after"]
+>     tevents :: SParser [TriggerEvent]
+>     tevents = sepBy1 (choice [
+>                          AntiTriggerEvent <$> splice 't'
+>                         ,TInsert <$ keyword "insert"
+>                         ,TUpdate <$ keyword "update"
+>                         ,TDelete <$ keyword "delete"]) (keyword "or")
+>     tfiring = option EachStatement
+>                 (keyword "for" *> optional (keyword "each") *>
+>                 choice [
+>                   EachRow <$ keyword "row"
+>                  ,EachStatement <$ keyword "statement"])
+
+> createAlterLoginUser :: (Annotation -> Name -> String -> Statement) -> Text -> SParser Statement
+> createAlterLoginUser ctor k = ctor
+>                             <$> pos <* keyword k
+>                             <*> name
+>                             <*> (keyword "with" *> keyword "password" *> symbol "=" *> (extrStr <$> stringLit))
+
+> createLogin :: SParser Statement
+> createLogin = createAlterLoginUser CreateLogin "login"
+> createUser :: SParser Statement
+> createUser = createAlterLoginUser CreateUser "user"
+> alterLogin :: SParser Statement
+> alterLogin = createAlterLoginUser AlterLogin "login"
+> alterUser :: SParser Statement
+> alterUser = createAlterLoginUser AlterUser "user"
+
+
+anti statement
+--------------
+
+> antiStatement :: SParser Statement
+> antiStatement = AntiStatement <$> splice 's'
+
+--------------------------------------------------------------------------------
+
+component parsers for sql statements
+====================================
+
+> whereClause :: SParser ScalarExpr
+> whereClause = keyword "where" *> expr
+
+selectlist and selectitem: the bit between select and from
+check for into either before the whole list of select columns
+or after the whole list
+
+> selectList :: SParser SelectList
+> selectList = SelectList <$> pos
+>              <*> itemList
+>   where
+>     itemList = commaSep1 selectItem
+>     selectItem = pos >>= \p ->
+>                  optionalSuffix
+>                    (SelExp p) (starExpr <|> expr)
+>                    (SelectItem p) (optional (keyword "as") *> asAlias)
+
+should try to factor this into the standard expr parse (use a flag) so
+that can left factor the 'name component . '  part and avoid the try
+
+> starExpr :: SParser ScalarExpr
+> starExpr = choice [Star <$> pos <* symbol "*"
+>                   ,try $ do
+>                          p <- pos
+>                          nc <- nameComponent
+>                          symbol "."
+>                          symbol "*"
+>                          return $ QStar p nc]
+
+>
+> returning :: SParser SelectList
+> returning = keyword "returning" *> selectList
+>
+> columnNameList :: SParser [NameComponent]
+> columnNameList = parens $ commaSep1 nameComponent
+>
+> typeName :: SParser TypeName
+> typeName =
+>   choice [
+>      SetOfTypeName <$> pos <*> (keyword "setof" *> typeName)
+>     ,otherTypeName]
+>   where
+>     otherTypeName = do
+>        p <- pos
+>        s <- pTypeNameString
+>        choice [try (Prec2TypeName p s
+>                     <$> (symbol "(" *> integer)
+>                     <*> (symbol "," *> integer <* symbol ")"))
+>               ,PrecTypeName p s <$> parens integer
+>               ,arrayTypeName p s
+>               ,return $ SimpleTypeName p s]
+>     arrayTypeName p s = ArrayTypeName p (SimpleTypeName p s)
+>                         <$ symbol "[" <* symbol "]"
+>     pTypeNameString :: SParser Name
+>     pTypeNameString = (Name <$> pos
+>                        <*> choice [[Nmc "double precision"]
+>                                    <$ try (keyword "double"
+>                                            <* keyword "precision")
+>                                   ,[Nmc "character varying"]
+>                                    <$ try (keyword "character"
+>                                            <* keyword "varying")])
+>                       <|> name
+>
+> cascade :: SParser Cascade
+> cascade = option Restrict (choice [
+>                             Restrict <$ keyword "restrict"
+>                            ,Cascade <$ keyword "cascade"])
+
+> stmtEnd :: Bool -> SParser ()
+> stmtEnd alwaysOptional = do
+>   ss <- isSqlServer
+>   if alwaysOptional || ss
+>     then optional (symbol ";") >>= \_ -> return ()
+>     else symbol ";" >>= \_ -> return ()
+
+--------------------------------------------------------------------------------
+
+plpgsql statements
+==================
+
+> plPgsqlStatement :: SParser Statement
+> plPgsqlStatement =
+>    choice [
+>      -- modified sql statements
+>      choice [
+>         try intoQueryStatement
+>        ,choice [insert
+>                ,update
+>                ,delete] >>= intoSuffix
+>        ] <* stmtEnd False
+>     -- regular sql statements
+>     ,sqlStatement True
+>     -- regular plpgsql statements
+>     ,choice [
+>           declareStatement
+>          ,setAssign
+>          ,continue
+>          ,execute >>= intoSuffix
+>          ,caseStatement
+>          ,assignment
+>          ,ifStatement
+>          ,returnSt
+>          ,raise
+>          ,perform
+>          ,labelPrefixed
+>          ,nullStatement
+>          ,exitStatement]
+>          <* stmtEnd False
+>     ]
+>    where
+>      intoSuffix e =
+>        option e (try $ do
+>                  i <- into
+>                  return $ i e)
+>      labelPrefixed = do
+>        p <- pos
+>        l <- label
+>        choice [block p l
+>               ,forStatement p l
+>               ,whileStatement p l
+>               ,loopStatement p l]
+
+> label :: SParser (Maybe String)
+> label = optionMaybe (symbol "<<" *> idString <* symbol ">>")
+>
+> block :: Annotation -> Maybe String -> SParser Statement
+> block p l = Block p l
+>             <$> option [] declarePart
+>             <*> statementPart
+>         where
+>           statementPart = keyword "begin"
+>                     *> many plPgsqlStatement
+>                     <* keyword "end"
+>           declarePart = keyword "declare"
+>                         *> manyTill (try varDef) (lookAhead $ keyword "begin")
+>
+>
+> nullStatement :: SParser Statement
+> nullStatement = NullStatement <$> (pos <* keyword "null")
+>
+> exitStatement :: SParser Statement
+> exitStatement = ExitStatement <$> (pos <* keyword "exit")
+>                               <*> optionMaybe idString
+>
+>
+> continue :: SParser Statement
+> continue = ContinueStatement <$> (pos <* keyword "continue")
+>                              <*> optionMaybe idString
+>
+> perform :: SParser Statement
+> perform = Perform <$> (pos <* keyword "perform") <*> expr
+>
+
+> execute :: SParser Statement
+> execute =
+>   choice
+>   [do
+>    isSqlServer >>= guard
+>    _ <- keyword "exec" <|> keyword "execute"
+>    ExecStatement <$> pos
+>      <*> name
+>      <*> commaSep expr
+>   ,Execute <$> (pos <* keyword "execute")
+>            <*> expr]
+>
+> assignment :: SParser Statement
+> assignment = Assignment
+>              <$> pos
+>              -- put the := in the first try to attempt to get a
+>              -- better error if the code looks like malformed
+>              -- assignment statement
+>              <*> try (name <* (symbol ":=" <|> symbol "="))
+>              <*> expr
+
+> setAssign :: SParser Statement
+> setAssign = do
+>   isSqlServer >>= guard
+>   Assignment <$> (pos <* keyword "set")
+>              <*> name
+>              <*> (symbol "=" *> expr)
+
+>
+> returnSt :: SParser Statement
+> returnSt = pos >>= \p -> keyword "return" >>
+>            choice [
+>             ReturnNext p <$> (keyword "next" *> expr)
+>            ,ReturnQuery p <$> (keyword "query" *> pQueryExpr)
+>            ,Return p <$> tryOptionMaybe expr]
+>
+> raise :: SParser Statement
+> raise = pos >>= \p -> keyword "raise" >>
+>         Raise p
+>         <$> raiseType
+>         <*> (extrStr <$> stringLit)
+>         <*> option [] (symbol "," *> commaSep1 expr)
+>         where
+>           raiseType = matchAKeyword [("notice", RNotice)
+>                                      ,("exception", RException)
+>                                      ,("error", RError)]
+>
+> forStatement :: Annotation -> Maybe String -> SParser Statement
+> forStatement p l = do
+>                keyword "for"
+>                start <- nameComponent
+>                keyword "in"
+>                choice [ForQueryStatement p l start
+>                        <$> try pQueryExpr <*> theRest
+>                       ,ForIntegerStatement p l start
+>                               <$> expr
+>                               <*> (symbol ".." *> expr)
+>                               <*> theRest]
+>   where
+>     theRest = keyword "loop" *> many plPgsqlStatement
+>               <* keyword "end" <* keyword "loop"
+>
+> whileStatement :: Annotation -> Maybe String -> SParser Statement
+> whileStatement p l = WhileStatement p l
+>                      <$> (keyword "while" *> expr <* keyword "loop")
+>                      <*> many plPgsqlStatement <* keyword "end" <* keyword "loop"
+> loopStatement :: Annotation -> Maybe String -> SParser Statement
+> loopStatement p l = LoopStatement p l
+>                     <$> (keyword "loop" *> many plPgsqlStatement <* keyword "end" <* keyword "loop")
+>
+
+>
+> ifStatement :: SParser Statement
+> ifStatement = do
+>   ss <- isSqlServer
+>   if ss
+>     -- no else if in sql server
+>     -- no end if in sql server
+>     then If
+>          <$> (pos <* keyword "if")
+>          <*> ((:[]) <$> (expr <.> someStatements ss))
+>          <*> elsePart ss
+>     else If
+>          <$> (pos <* keyword "if")
+>          <*> (ifPart ss <:> elseifParts ss)
+>          <*> (elsePart ss <* endIf)
+>   where
+>     ifPart ss =
+>       if ss
+>       -- no then keyword in tsql
+>       then expr <.> someStatements ss
+>       else expr <.> (thn *> someStatements ss)
+>     elseifParts ss = many ((elseif *> expr) <.> (thn *> someStatements ss))
+>     elsePart ss = option [] (keyword "else" *> someStatements ss)
+>     endIf = keyword "end" <* keyword "if"
+>     thn = keyword "then"
+>     elseif = keyword "elseif" <|> keyword "elsif"
+>     (<.>) a b = (,) <$> a <*> b
+>     someStatements ss =
+>       if ss
+>       then
+>           -- sql server only allows multiple statements if wrapped
+>           -- in a begin end block
+>           choice [keyword "begin"
+>                   *> many plPgsqlStatement
+>                   <* keyword "end"
+>                  ,(:[]) <$> plPgsqlStatement]
+>       else many plPgsqlStatement
+
+> caseStatement :: SParser Statement
+> caseStatement = do
+>     p <- pos
+>     keyword "case"
+>     choice [try (CaseStatementSimple p
+>                  <$> expr
+>                  <*> many whenSt
+>                  <*> option [] (keyword "else" *> many plPgsqlStatement)
+>                         <* keyword "end" <* keyword "case")
+>            ,CaseStatement p
+>                  <$> many whenSt
+>                  <*> option [] (keyword "else" *> many plPgsqlStatement)
+>                         <* keyword "end" <* keyword "case"]
+>     where
+>       whenSt = keyword "when" >>
+>                (,) <$> commaSep1 expr
+>                    <*> (keyword "then" *> many plPgsqlStatement)
+
+> declareStatement :: SParser Statement
+> declareStatement = do
+>   isSqlServer >>= guard
+>   DeclareStatement
+>     <$> pos
+>     <*> (keyword "declare"
+>          *> commaSep1 de)
+>   where
+>     de = (,,) <$> localVarName
+>               <*> typeName
+>               <*> optionMaybe (symbol "=" *> expr)
+>     localVarName = do
+>       i <- idString
+>       guard (head i == '@')
+>       return i
+
+
+only limited support for tsql create index atm
+
+> createIndex :: SParser Statement
+> createIndex =
+>   CreateIndexTSQL
+>   <$> try (pos <* flavs <* keyword "index")
+>   <*> nameComponent
+>   <*> (keyword "on" *> name)
+>   <*> parens (commaSep1 nameComponent) <* opts
+>   where
+>     flavs = do
+>       _ <- optional $ keyword "unique"
+>       _ <- optional (keyword "clustered" <|> keyword "nonclustered")
+>       return ()
+>     opts = do
+>       _ <- optional $ do
+>              _ <- keyword "include"
+>              _ <- parens (commaSep1 nameComponent)
+>              return ()
+>       return ()
+
+--------------------------------------------------------------------------------
+
+expressions
+===========
+
+This is the bit that makes it the most obvious that I don't really
+know haskell, parsing theory or parsec ... robbed a parsing example
+from haskell-cafe and mainly just kept changing it until it seemed to
+work
+
+> expr :: SParser ScalarExpr
+> expr = do
+>   ParseFlags {pfDialect = d} <- getState
+>   buildExpressionParser (table d) factor
+>        <?> "expression"
+
+>
+> factor :: SParser ScalarExpr
+> factor =
+
+First job is to take care of forms which start like a vanilla
+expression, and then add a suffix on
+
+>   fct >>= tryExprSuffix
+>   where
+>     tryExprSuffix e =
+>       option e (choice (map (\f -> try $ f e) -- Try added because betweenSuffix may eat up "not" in betweenSuffix
+>                                  [inPredicateSuffix
+>                                  ,functionCallSuffix
+>                                  ,windowFnSuffix
+>                                  ,castSuffix
+>                                  ,betweenSuffix
+>                                  ,arraySubSuffix
+>                                  ,qualIdSuffix])
+>                 >>= tryExprSuffix)
+>     fct = choice [
+
+order these so the ones which can be valid prefixes of others appear
+further down the list (used to be a lot more important when there
+wasn't a separate lexer), probably want to refactor this to use the
+optionalsuffix parsers to improve speed.
+
+start with the factors which start with parens - eliminate scalar
+subqueries since they're efficient to distinguish from the others
+using try, then parse an expression in parens which can either be the
+start of a row constructor or just a parenthesized expression. This is
+left factored because using try with the rowctor version first leads
+to exponential backtracking for nested parenthesized expressions which
+is very slow.
+
+>        parens (scalarSubQuery <|> exprInParens)
+
+try a few random things which can't start a different expression
+
+>       ,positionalArg
+>       ,placeholder
+>       ,stringLit
+>       ,numberLit
+
+put the factors which start with keywords before the ones which start
+with a function, so you don't try an parse a keyword as a function name
+
+>       ,rowCtor
+>       ,caseScalarExpr
+>       ,exists
+>       ,booleanLit
+>       ,nullLit
+>       ,arrayLit
+>       ,castKeyword
+>       ,try substring -- use try cos there is also a regular function called substring
+>       ,extract
+>       ,odbcExpr
+
+>       ,try interval
+>       ,try typedStringLit
+>       ,antiScalarExpr
+>       ,sqlServerConvert
+>       ,keywordFunction
+>       ,identifier
+>       ,Identifier <$> pos <*> (AntiName <$> splice 'n')
+>       ]
+
+operator table
+--------------
+
+proper hacky, but sort of does the job
+the 'missing' notes refer to pg operators which aren't yet supported,
+or supported in a different way (e.g. cast uses the type name parser
+for one of it's argument, not the expression parser - I don't know if
+there is a better way of doing this but there usually is in parsec)
+
+pg's operator table is on this page:
+http://www.postgresql.org/docs/8.4/interactive/sql-syntax-lexical.html#SQL-SYNTAX-OPERATORS
+
+will probably need something more custom to handle full range of sql
+syntactical novelty, in particular the precedence rules mix these
+operators up with irregular syntax operators, you can create new
+operators during parsing, and some operators are prefix/postfix or
+binary depending on the types of their operands
+
+The full list of operators from a standard template1 database should
+be used here.
+
+TODO: handle the completely different list of sql server operators a
+bit better
+
+TODO: this follows the old, incorrect postgresql precedence, update to
+the 9.5 behaviour which is much more in line with ansi sql and other
+sql dbmss.
+
+> tableAB :: Dialect
+>         -> Bool
+>         -> [[Operator [Token] ParseState Identity ScalarExpr]]
+> tableAB d isB = [[{-binary "." AssocLeft-}]
+>          --[binary "::" (BinOpCall Cast) AssocLeft]
+>          --missing [] for array element select
+>         ,[prefix "+" "+"] -- Unary plus - Exists in pgsql 9.4
+
+>         ,[prefix "-" "-"] -- Unary minus
+
+>         ,[binary "^" AssocLeft] -- Exponent
+
+>         ,[binary "*" AssocLeft
+>          ,idHackBinary "*" AssocLeft
+>          ,binary "/" AssocLeft
+>          ,binary "%" AssocLeft]
+
+>         ,[binary "+" AssocLeft
+>          ,binary "-" AssocLeft]
+
+>          ------- All custom operators must go here:
+>          --other operators all added in this list according to the pg docs:
+>         ,[prefix "~" "~"
+>          ,binary "|" AssocLeft
+>          ,binary "&" AssocLeft
+>          ,binary "#" AssocLeft
+>          ,binary "<<" AssocLeft
+>          ,binary ">>" AssocLeft
+>          ,binary "<->" AssocNone
+>          ,binary "||" AssocLeft]
+>          ++ [prefix "@" "@" | diSyntaxFlavour d == Postgres]
+>          -- Stop custom operators.
+>          --in should be here, but is treated as a factor instead
+>          --between
+>          --overlaps
+
+>         ,[binaryk "like" "like" AssocNone
+>          ,binaryk "rlike" "rlike" AssocNone
+>          ,binaryks ["not","like"] "notlike" AssocNone]
+
+>         ,[binary "<" AssocNone
+>          ,binary ">" AssocNone
+>          --(also ilike similar)
+>          ,binary "=" AssocRight
+>          ,binary "<=" AssocRight
+>          ,binary ">=" AssocRight
+>          ,binary "<>" AssocRight
+>          ,binarycust (symbol "!=") "<>" AssocRight]
+
+>         ,[postfixks ["is", "not", "null"] "isnotnull"
+>          ,postfixks ["is", "null"] "isnull"]
+
+>         ,[notNot
+>          ,prefixk "not" "not"
+>          ]
+
+>         ,if isB
+>          then []
+>          else [binaryk "and" "and" AssocLeft]
+
+>         ,[binaryk "or" "or" AssocLeft]
+>         ]
+>     where
+>       binary s = binarycust (symbol s) s
+>       -- '*' is lexed as an id token rather than a symbol token, so
+>       -- work around here
+>       idHackBinary s = binarycust (keyword s) s
+>       binaryk = binarycust . keyword
+>       binaryks = binarycust . mapM_ keyword
+>       prefix = prefCust Prefix . symbol
+>       prefixk = prefCust Prefix . keyword
+>       postfixks = postCust Postfix . mapM_ keyword
+>       binarycust opParse t =
+>         Infix $ try $
+>           BinaryOp <$> pos <*> (nm emptyAnnotation t <$ opParse)
+>       prefCust ctor opParse t =
+>         ctor $ try $
+>           PrefixOp <$> pos <*> (nm emptyAnnotation t <$ opParse)
+>       postCust ctor opParse t =
+>         ctor $ try $
+>           PostfixOp <$> pos <*> (nm emptyAnnotation t <$ opParse)
+>       -- hack - haven't worked out why parsec buildexpression parser won't
+>       -- parse something like "not not EXPR" without parens so hack here
+>       notNot =
+>         Prefix $ try $ do
+>                       p1 <- pos
+>                       keyword "not"
+>                       p2 <- pos
+>                       keyword "not"
+>                       return $ PrefixOp p1 (nm p1 "not")
+>                                . PrefixOp p2 (nm p2 "not")
+
+From postgresql src/backend/parser/gram.y
+
+~~~~~
+
+ * We have two expression types: a_expr is the unrestricted kind, and
+ * b_expr is a subset that must be used in some places to avoid shift/reduce
+ * conflicts.  For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
+ * because that use of AND conflicts with AND as a boolean operator.  So,
+ * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
+ *
+ * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
+ * always be used by surrounding it with parens.
+
+~~~~~
+
+> table :: Dialect -> [[Operator [Token] ParseState Identity ScalarExpr]]
+> table d = tableAB d False
+
+> tableB :: Dialect -> [[Operator [Token] ParseState Identity ScalarExpr]]
+> tableB d = tableAB d True
+
+use the same factors
+
+> b_expr :: SParser ScalarExpr
+> b_expr = do
+>          ParseFlags {pfDialect = d} <- getState
+>          buildExpressionParser (tableB d) factor
+>          <?> "expression"
+>
+
+factor parsers
+--------------
+
+I think the lookahead is used in an attempt to help the error messages.
+
+> scalarSubQuery :: SParser ScalarExpr
+> scalarSubQuery = ScalarSubQuery
+>                  <$> pos
+>                  <*> pQueryExpr
+
+in predicate - an identifier or row constructor followed by 'in'
+then a list of expressions or a subselect
+
+> inPredicateSuffix :: ScalarExpr -> SParser ScalarExpr
+> inPredicateSuffix e = try $
+>   InPredicate
+>   <$> pos
+>   <*> return e
+>   <*> option True (False <$ keyword "not")
+>   <*> (keyword "in" *> parens ((InQueryExpr <$> pos <*> pQueryExpr)
+>                                <|>
+>                                (InList <$> pos <*> commaSep1 expr)))
+
+row ctor: one of
+
+* row ()
+* row (expr)
+* row (expr, expr1, ...)
+* (expr, expr2,...) [implicit (no row keyword) version, at least two elements
+                   must be present]
+
+(expr) parses to just expr rather than row(expr)
+and () is a syntax error.
+
+the rowCtor parses a ctor with the row keyword exprInParens parses
+either a rowCtor without the row keyword (there must be more than one
+comma separated expression, or it parses a parens expr).
+
+> rowCtor :: SParser ScalarExpr
+> rowCtor = SpecialOp
+>           <$> pos
+>           <*> (nm <$> pos <*> return "rowctor")
+>           <*> (keyword "row" *> parens (commaSep expr))
+
+question: is a parenthesized expression different to a single element
+row?
+
+> exprInParens :: SParser ScalarExpr
+> exprInParens = do
+>     p <- pos
+>     e1 <- expr
+>     choice [do
+>             void $ symbol ","
+>             es <- commaSep1 expr
+>             return $ SpecialOp p (nm p "rowctor") (e1:es)
+>            ,return $ Parens p e1]
+
+>
+> numberLit :: SParser ScalarExpr
+> numberLit = NumberLit <$> pos <*> numString
+>
+
+> integer :: SParser Integer
+> integer = do
+>   l <- numString
+>   guard (all (`elem` digChars) l)
+>   return $ read l
+>   where
+>     digChars = concatMap show [(0::Int)..9]
+
+> signedInteger :: SParser Integer
+> signedInteger = choice [try $ negate <$> (symbol "-" *> integer)
+>                        ,integer]
+
+
+>
+> caseScalarExpr :: SParser ScalarExpr
+> caseScalarExpr = do
+>   p <- pos
+>   keyword "case"
+>   choice [
+>              try $ CaseSimple p <$> expr
+>                                 <*> many whenParse
+>                                 <*> tryOptionMaybe (keyword "else" *> expr)
+>                                         <* keyword "end"
+>             ,Case p <$> many whenParse
+>                     <*> tryOptionMaybe (keyword "else" *> expr)
+>                             <* keyword "end"]
+>   where
+>     whenParse = (,) <$> (keyword "when" *> commaSep1 expr)
+>                     <*> (keyword "then" *> expr)
+>
+> exists :: SParser ScalarExpr
+> exists = Exists <$> pos <* keyword "exists" <*> parens pQueryExpr
+>
+
+> booleanLit :: SParser ScalarExpr
+> booleanLit = BooleanLit <$> pos <*> (True <$ keyword "true"
+>                                      <|> False <$ keyword "false")
+
+>
+> nullLit :: SParser ScalarExpr
+> nullLit = NullLit <$> pos <* keyword "null"
+>
+> arrayLit :: SParser ScalarExpr
+> arrayLit = SpecialOp <$> pos <* keyword "array"
+>                    <*> (nm <$> pos <*> return "arrayctor")
+>                    <*> squares (commaSep expr)
+>
+> arraySubSuffix :: ScalarExpr -> SParser ScalarExpr
+> arraySubSuffix e = SpecialOp <$> pos
+>                    <*> (nm <$> pos <*> return "arraysub")
+>                    <*> ((e:) <$> squares (commaSep1 expr))
+>
+> windowFnSuffix :: ScalarExpr -> SParser ScalarExpr
+> windowFnSuffix e = WindowApp <$> pos <*> return e
+>                    <*> (keyword "over"
+>                         *> (symbol "(" *> option [] partitionBy))
+>                    <*> orderBy
+>                    <*> frm
+>                    <* symbol ")"
+>   where
+>     partitionBy = keyword "partition" *> keyword "by" *> commaSep1 expr
+>     frm = optionMaybe $ choice $ map (\(a,b) -> a <$ try (ks b)) [
+>            (FrameUnboundedPreceding, ["range","unbounded","preceding"])
+>           ,(FrameUnboundedPreceding, ["range"
+>                                      ,"between"
+>                                      ,"unbounded"
+>                                      ,"preceding"
+>                                      ,"and"
+>                                      ,"current"
+>                                      ,"row"])
+>           ,(FrameUnboundedFull, ["range"
+>                                 ,"between"
+>                                 ,"unbounded"
+>                                 ,"preceding"
+>                                 ,"and"
+>                                 ,"unbounded"
+>                                 ,"following"])
+>           ,(FrameUnboundedFull, ["rows"
+>                                 ,"between"
+>                                 ,"unbounded"
+>                                 ,"preceding"
+>                                 ,"and"
+>                                 ,"unbounded"
+>                                 ,"following"])
+>           ,(FrameRowsUnboundedPreceding, ["rows","unbounded","preceding"])
+>           ,(FrameRowsUnboundedPreceding, ["rows"
+>                                          ,"between"
+>                                          ,"unbounded"
+>                                          ,"preceding"
+>                                          ,"and"
+>                                          ,"current"
+>                                          ,"row"])]
+>     ks = mapM keyword
+>
+> betweenSuffix :: ScalarExpr -> SParser ScalarExpr
+> betweenSuffix a = try $ do
+>   p <- pos
+>   opname <- option "between" ("notbetween" <$ keyword "not") -- Discern between `between` and `not between`
+>   keyword "between"
+>   b <- b_expr
+>   keyword "and"
+>   c <- b_expr
+>   return $ SpecialOp p (nm p opname) [a,b,c]
+
+handles aggregate business as well
+
+can use a * in aggregate calls and in window functions.  This
+represents a call to an aggregate which has no parameters, so count(*)
+actually means count():
+
+select count() from pg_attrdef;
+ERROR:  count(*) must be used to call a parameterless aggregate function
+LINE 1: select count() from pg_attrdef;
+
+But you can't write it as count() ... ?
+
+You cannot use * together with either distinct or order by, and it
+cannot be qualified.
+
+This parser is used as the prefix of the window function parser so
+both are handled here. This will parse non aggregate calls containing
+a single * argument without error - this will have to be caught during
+typechecking. It also parses the aggregate extras (distinct and order
+by) for non aggregate calls without error, so this also will need to
+be caught during typechecking. The typechecker doesn't really do much
+checking with aggregates at the moment so should fix it all together.
+
+> functionCallSuffix :: ScalarExpr -> SParser ScalarExpr
+> functionCallSuffix ex =
+>  -- bit hacky, if exp is a identifier or qualified, then
+>  -- convert to function, also support antiquote for function name
+>    case ex of
+>      Identifier _ nm' -> fn nm'
+>      s -> fail $ "cannot make functioncall from " ++ show s
+>    where
+>      fn :: Name -> SParser ScalarExpr
+>      fn fnName = do
+>        p <- pos
+>        (di,as,ob) <- parens
+>                      $ choice [ -- handle a single *
+>                                (Nothing,,[]) <$> ((:[]) <$> (Star <$> pos <* symbol "*"))
+>                               ,(,,)
+>                                <$> optionMaybe
+>                                     (choice [Distinct <$ distinctKeyword
+>                                             ,All <$ keyword "all"])
+>                                <*> commaSep expr
+>                                <*> orderBy]
+>        return $ case (di,ob) of
+>          (Nothing,[]) -> App p fnName as
+>          (d,o) -> AggregateApp p (fromMaybe All d) (App p fnName as) o
+
+these won't parse as normal functions because they use keywords so do
+a special case for them
+
+> keywordFunction :: SParser ScalarExpr
+> keywordFunction = try $ do
+>   p <- pos
+>   i <- nameComponentAllows kfs
+>   guard (iskfs i)
+>   functionCallSuffix (Identifier p (Name p [i]))
+>   where
+>     kfs = ["any","all","isnull","left","right","convert"]
+>     iskfs (Nmc n) | map toLower n `elem` kfs = True
+>     iskfs _ = False
+
+>
+> castKeyword :: SParser ScalarExpr
+> castKeyword =
+>     Cast
+>     <$> pos <* keyword "cast" <* symbol "("
+>     <*> expr
+>     <*> (keyword "as" *> typeName <* symbol ")")
+
+parse both odbc style convert:
+      convert(expr, type name) -- type name is an identifier
+      and sql server
+      convert(type name, expr [,style]) -- the type name is a normal sql type name
+
+the style is ignored
+the first form is represented as a function called convert (App ctor)
+the second form is represented as Cast ctor for now
+
+it needs fixing: at least add a specific ctor for the second form
+plus review use of try
+
+> sqlServerConvert :: SParser ScalarExpr
+> sqlServerConvert = try $ do
+>     isSqlServer >>= guard
+>     p <- pos
+>     _ <- keyword "convert" <* symbol "("
+>     choice [try $ do
+>             ex <- expr
+>             _ <- symbol ","
+>             ex1 <- expr
+>             _ <- symbol ")"
+>             return $ App p (Name p [Nmc "convert"]) [ex, ex1]
+>            ,do
+>             tn <- typeName
+>             _ <- symbol ","
+>             e <- expr
+>             -- ignores the style
+>             _ <- optional $ symbol "," *> integer
+>             _ <- symbol ")"
+>             return $ Cast p e tn
+>            ]
+
+> castSuffix :: ScalarExpr -> SParser ScalarExpr
+> castSuffix ex = pos >>= \p -> Cast p ex <$> (symbol "::" *> typeName)
+
+> typedStringLit :: SParser ScalarExpr
+> typedStringLit = TypedStringLit
+>                  <$> pos
+>                  <*> typeName
+>                  <*> (extrStr <$> stringLit)
+
+> extract :: SParser ScalarExpr
+> extract = try $ do
+>   p <- pos
+>   _ <- keyword "extract"
+>   _ <- symbol "("
+>   f <- extractField
+>   _ <- keyword "from"
+>   e <- expr
+>   _ <- symbol ")"
+>   return $ Extract p f e
+>   where
+>     extractField =
+>       choice [ExtractCentury <$ keyword "century"
+>              ,ExtractDay <$ keyword "day"
+>              ,ExtractDecade <$ keyword "decade"
+>              ,ExtractDow <$ keyword "dow"
+>              ,ExtractDoy <$ keyword "doy"
+>              ,ExtractEpoch <$ keyword "epoch"
+>              ,ExtractHour <$ keyword "hour"
+>              ,ExtractIsodow <$ keyword "isodow"
+>              ,ExtractIsoyear <$ keyword "isoyear"
+>              ,ExtractMicroseconds <$ keyword "microseconds"
+>              ,ExtractMillennium <$ keyword "millennium"
+>              ,ExtractMilliseconds <$ keyword "milliseconds"
+>              ,ExtractMinute <$ keyword "minute"
+>              ,ExtractMonth <$ keyword "month"
+>              ,ExtractQuarter <$ keyword "quarter"
+>              ,ExtractSecond <$ keyword "second"
+>              ,ExtractTimezone <$ keyword "timezone"
+>              ,ExtractTimezoneHour <$ keyword "timezone_hour"
+>              ,ExtractTimezoneMinute <$ keyword "timezone_minute"
+>              ,ExtractWeek <$ keyword "week"
+>              ,ExtractYear <$ keyword "year"]
+
+> interval :: SParser ScalarExpr
+> interval = Interval
+>            <$> pos
+>            <*> (keyword "interval" *> (extrStr <$> stringLit))
+>            <*> intervalField
+>            <*> tryOptionMaybe (parens (fromInteger <$> integer))
+>   where
+>     intervalField =
+>         choice [IntervalYear <$ keyword "year"
+>                ,IntervalMonth <$ keyword "month"
+>                ,IntervalDay <$ keyword "day"
+>                ,IntervalHour <$ keyword "hour"
+>                ,IntervalMinute <$ keyword "minute"
+>                ,IntervalSecond <$ keyword "second"
+>                {-,IntervalYearToMonth <$ keyword "day"
+>                ,IntervalDayToHour <$ keyword "day"
+>                ,IntervalDayToMinute <$ keyword "day"
+>                ,IntervalDayToSecond <$ keyword "day"
+>                ,IntervalHourToMinute <$ keyword "day"
+>                ,IntervalHourToSecond <$ keyword "day"
+>                ,IntervalMinuteToSecond <$ keyword "day"-}]
+>
+> substring :: SParser ScalarExpr
+> substring = do
+>             p <- pos
+>             keyword "substring"
+>             symbol "("
+>             a <- expr
+>             keyword "from"
+>             b <- expr
+>             keyword "for"
+>             c <- expr
+>             symbol ")"
+>             return $ SpecialOp p (nm p "substring") [a,b,c]
+>
+
+odbc
+
+date, time, and timestamp literals, and scalar function calls
+
+> odbcExpr :: SParser ScalarExpr
+> odbcExpr = between (symbol "{") (symbol "}")
+>            (odbcTimeLit <|> odbcFunc <|> odbcInterval)
+>   where
+>     odbcTimeLit =
+>         OdbcLiteral <$> pos
+>                     <*> choice [OLDate <$ keyword "d"
+>                                ,OLTime <$ keyword "t"
+>                                ,OLTimestamp <$ keyword "ts"]
+>                     <*> stringN
+>     odbcFunc = OdbcFunc
+>                <$> pos
+>                <*> (keyword "fn" *> expr) -- TODO: should limit this to function call or extract
+>     odbcInterval = interval
+
+
+
+------------------------------------------------------------
+
+identifier parsing, quite a few variations ...
+
+parse x.y, x.y.z, etc.
+
+> qualIdSuffix :: ScalarExpr -> SParser ScalarExpr
+> qualIdSuffix (Identifier _p (Name _ is)) =
+>   qualIdX is
+
+> qualIdSuffix e = do
+>     p <- pos
+>     i1 <- symbol "." *> nameComponent
+>     return $ BinaryOp p (nm p ".") e (Identifier p (Name p [i1]))
+
+> qualIdX :: [NameComponent] -> SParser ScalarExpr
+> qualIdX is = do
+>   ss <- isSqlServer
+>   if ss
+>     then sqls
+>     else regular
+>   where
+>     regular = do
+>               p <- pos
+>               i1 <- symbol "." *> nameComponent
+>               return $ Identifier p (Name p (is ++ [i1]))
+>     sqls = do
+>            p <- pos
+>            numDots <- readNDots
+>            let eis = replicate (numDots - 1) (Nmc "")
+>            i1 <- nameComponent
+>            return $ Identifier p (Name p (is ++ eis ++ [i1]))
+
+the cranky lexer lexes lots of dots ......
+as mixtures of symbol "." and symbol ".."
+we just want to know how many dots in a row there are
+
+> readNDots :: SParser Int
+> readNDots = sum <$> many1 (choice [1 <$ symbol "."
+>                                   ,2 <$ symbol ".."])
+
+
+
+> identifier :: SParser ScalarExpr
+> identifier = Identifier <$> pos <*> name
+
+see sql-keywords appendix in pg manual
+
+doesn't deal with non-reserved, and reserved with qualifications yet
+(e.g. the may be function or type catagory), and other categories
+
+I think the categories should be:
+reserved
+reserved but can be function or type
+not reserved but cannot be function or type
+
+these categories affect the parser and typechecker differently
+
+(the parser has to parse some reserved and 'not reserved but cannot be
+function or type' keywords as function names, maybe there are others)
+
+> reservedWords :: SParser [String]
+> reservedWords = do
+>   ss <- isSqlServer
+>   if not ss
+>     then return
+>        ["all"
+>        ,"analyse"
+>        ,"analyze"
+>        ,"and"
+>        ,"any"
+>        ,"array"
+>        ,"as"
+>        ,"asc"
+>        ,"symmetric"
+>        ,"authorization"
+>        ,"binary"
+>        ,"both"
+>        ,"case"
+>        ,"cast"
+>        ,"check"
+>        ,"collate"
+>        ,"column"
+>        ,"concurrently"
+>        ,"constraint"
+>        ,"create"
+>        ,"cross"
+>        ,"current_catalog"
+>        ,"current_role"
+>        ,"current_time"
+>        ,"current_user"
+>        ,"default"
+>        ,"deferrable"
+>        ,"desc"
+>        ,"distinct"
+>        ,"do"
+>        ,"else"
+>        ,"end"
+>        ,"except"
+>        ,"false"
+>        ,"fetch"
+>        ,"for"
+>        ,"freeze"
+>        ,"from"
+>        ,"full"
+>        ,"grant"
+>        ,"group"
+>        ,"having"
+>        ,"ilike"
+>        ,"in"
+>        ,"initially"
+>        ,"inner"
+>        ,"intersect"
+>        ,"into"
+>        ,"is"
+>        ,"isnull"
+>        ,"join"
+>        ,"leading"
+>        ,"left"
+>        ,"like"
+>        ,"limit"
+>        ,"localtime"
+>        ,"localtimestamp"
+>        ,"natural"
+>        ,"not"
+>        ,"notnull"
+>        ,"null"
+>        ,"offset"
+>        ,"on"
+>        ,"only"
+>        ,"option"
+>        ,"or"
+>        ,"order"
+>        ,"outer"
+>        ,"over"
+>        ,"overlaps"
+>        ,"placing"
+>        ,"primary"
+>        ,"references"
+>        ,"returning"
+>        ,"right"
+>        ,"rlike"
+>        ,"select"
+>        ,"session_user"
+>        ,"similar"
+>        ,"some"
+>        ,"symmetric"
+>        ,"table"
+>        ,"then"
+>        ,"to"
+>        ,"trailing"
+>        ,"true"
+>        ,"union"
+>        ,"unique"
+>        ,"user"
+>        ,"using"
+>        ,"variadic"
+>        ,"verbose"
+>        ,"when"
+>        ,"where"
+>        ,"window"
+>        ,"with"
+>        --extras for hssqlppp: Todo: fix this
+>        ,"loop","merge","hash"]
+
+sql server keywords from this page:
+http://msdn.microsoft.com/en-us/library/ms189822.aspx
+(this is the list for 2008 R2)
+
+>     else return
+>        ["add"
+>        ,"all"
+>        ,"alter"
+>        ,"and"
+>        ,"any"
+>        ,"as"
+>        ,"asc"
+>        ,"authorization"
+>        ,"backup"
+>        ,"begin"
+>        ,"between"
+>        ,"break"
+>        ,"browse"
+>        ,"bulk"
+>        ,"by"
+>        ,"cascade"
+>        ,"case"
+>        ,"check"
+>        ,"checkpoint"
+>        ,"close"
+>        ,"clustered"
+>        --,"coalesce"
+>        ,"collate"
+>        ,"column"
+>        ,"commit"
+>        ,"compute"
+>        ,"constraint"
+>        -- ,"contains" todo: fix properly, oracle has function called contains
+>        ,"containstable"
+>        ,"continue"
+>        ,"convert"
+>        ,"create"
+>        ,"cross"
+>        ,"current"
+>        ,"current_time"
+>        ,"current_user"
+>        ,"cursor"
+>        ,"database"
+>        ,"dbcc"
+>        ,"deallocate"
+>        ,"declare"
+>        ,"default"
+>        ,"delete"
+>        ,"deny"
+>        ,"desc"
+>        ,"disk"
+>        ,"distinct"
+>        ,"distributed"
+>        --,"double"
+>        ,"drop"
+>        ,"dump"
+>        ,"else"
+>        ,"end"
+>        ,"errlvl"
+>        ,"escape"
+>        ,"except"
+>        ,"exec"
+>        ,"execute"
+>        ,"exists"
+>        ,"exit"
+>        ,"external"
+>        ,"fetch"
+>        ,"file"
+>        ,"fillfactor"
+>        ,"for"
+>        ,"foreign"
+>        ,"freetext"
+>        ,"freetexttable"
+>        ,"from"
+>        ,"full"
+>        ,"function"
+>        ,"goto"
+>        ,"grant"
+>        ,"group"
+>        ,"hash"
+>        ,"having"
+>        ,"holdlock"
+>        ,"identity"
+>        ,"identity_insert"
+>        ,"identitycol"
+>        ,"if"
+>        ,"in"
+>        ,"index"
+>        ,"inner"
+>        ,"insert"
+>        ,"intersect"
+>        ,"into"
+>        ,"is"
+>        ,"join"
+>        ,"key"
+>        ,"kill"
+>        ,"left"
+>        ,"like"
+>        ,"lineno"
+>        ,"load"
+>        ,"loop"
+>        ,"merge"
+>        ,"national"
+>        ,"natural"
+>        ,"nocheck"
+>        ,"nonclustered"
+>        ,"not"
+>        ,"null"
+>        ,"nullif"
+>        ,"of"
+>        ,"off"
+>        ,"offsets"
+>        ,"on"
+>        ,"open"
+>        ,"opendatasource"
+>        ,"openquery"
+>        ,"openrowset"
+>        ,"openxml"
+>        ,"option"
+>        ,"or"
+>        ,"order"
+>        ,"outer"
+>        ,"over"
+>        ,"percent"
+>        ,"pivot"
+>        -- ,"plan" -- temporarily unkeyword this
+>        ,"precision"
+>        ,"primary"
+>        ,"print"
+>        ,"proc"
+>        ,"procedure"
+>        -- ,"public"
+>        ,"raiserror"
+>        ,"read"
+>        ,"readtext"
+>        ,"reconfigure"
+>        ,"references"
+>        ,"replication"
+>        ,"restore"
+>        ,"restrict"
+>        ,"return"
+>        ,"revert"
+>        ,"revoke"
+>        ,"right"
+>        ,"rollback"
+>        ,"rowcount"
+>        ,"rowguidcol"
+>        ,"rule"
+>        ,"save"
+>        ,"schema"
+>        ,"securityaudit"
+>        ,"select"
+>        ,"session_user"
+>        ,"set"
+>        ,"setuser"
+>        ,"shutdown"
+>        ,"some"
+>        ,"statistics"
+>        ,"system_user"
+>        ,"table"
+>        ,"tablesample"
+>        ,"textsize"
+>        ,"then"
+>        ,"to"
+>        ,"top"
+>        ,"tran"
+>        ,"transaction"
+>        ,"trigger"
+>        ,"truncate"
+>        ,"tsequal"
+>        ,"union"
+>        ,"unique"
+>        ,"unpivot"
+>        ,"update"
+>        ,"updatetext"
+>        ,"use"
+>        ,"user"
+>        ,"values"
+>        ,"varying"
+>        ,"view"
+>        ,"waitfor"
+>        ,"when"
+>        ,"where"
+>        ,"while"
+>        ,"with"
+>        ,"writetext"]
+
+> ncs :: SParser [NameComponent]
+> ncs = do
+>   ss <- isSqlServer
+>   if ss
+>     then do
+>       -- what a mess
+>       let another = do
+>             numDots <- readNDots
+>             let empties = replicate (numDots - 1) (Nmc "")
+>             nc <- nameComponent
+>             suf <- choice [another
+>                           ,return []]
+>             return $ empties ++ [nc] ++ suf
+>       i <- nameComponent
+>       suf <- choice [another
+>                     ,return []]
+>       return (i:suf)
+>     else
+>       sepBy1 nameComponent (symbol ".")
+
+parse a complete name
+
+> name :: SParser Name
+> name = choice [AntiName <$> splice 'n'
+>               ,Name <$> pos <*> ncs
+>               ]
+
+> nameComponent :: SParser NameComponent
+> nameComponent = nameComponentAllows []
+
+parser for a name component where you supply the exceptions to the
+reserved identifier list to say you want these to parse successfully
+instead of failing with a no keyword error
+
+> nameComponentAllows :: [String] -> SParser NameComponent
+> nameComponentAllows allows = do
+>   p <- pos
+>   x <- unrestrictedNameComponent
+>   rw <- reservedWords
+>   case x of
+>     Nmc n | map toLower n `elem` allows -> return x
+>           | map toLower n `elem` rw ->
+>               fail $ "no keywords " ++ show p ++ " " ++ n
+>     _ -> return x
+
+ignore reserved keywords completely
+
+> unrestrictedNameComponent :: SParser NameComponent
+> unrestrictedNameComponent =
+>   choice [Nmc <$> idString
+>          ,QNmc <$> qidString
+>          ,AntiNameComponent <$> splice 'm']
+
+quick hack to support identifiers like this: 'test' for sql server
+
+not sure how to do this properly, you must not be able to write
+strings in sql server using single quotes.
+
+> asAlias :: SParser NameComponent
+> asAlias = do
+>   ss <- isSqlServer
+>   if ss
+>     then choice [nameComponent
+>                 ,do
+>                  s <- stringN
+>                  return $ QNmc s]
+>     else nameComponent
+
+--------------------------------------------------------------------------------
+
+Utility parsers
+===============
+
+> keyword :: Text -> SParser ()
+> keyword k = mytoken (\tok -> case tok of
+>                                Lex.Identifier Nothing i | lcase (T.unpack k) == lcase i -> Just ()
+>                                _ -> Nothing)
+>                       where
+>                         lcase = map toLower
+
+>
+> idString :: SParser String
+> idString = mytoken (\tok -> case tok of
+>                                      Lex.Identifier Nothing i -> Just  i
+>                                      Lex.PrefixedVariable c s -> Just (c : s)
+>                                      _ -> Nothing)
+> qidString :: SParser String
+> qidString = mytoken (\tok -> case tok of
+>                                      Lex.Identifier _ i -> Just i
+>                                      _ -> Nothing)
+
+> splice :: Char -> SParser String
+> splice c = mytoken (\tok -> case tok of
+>                                Lex.Splice c' i | c == c' -> Just i
+>                                _ -> Nothing)
+
+>
+> symbol :: Text -> SParser ()
+> symbol c = mytoken (\tok -> case tok of
+>                                    Lex.Symbol s | T.unpack c==s -> Just ()
+>                                    _           -> Nothing)
+>
+> liftPositionalArgTok :: SParser Integer
+> liftPositionalArgTok =
+>   mytoken (\tok -> case tok of
+>                    Lex.PositionalArg n -> Just $ fromIntegral n
+>                    _ -> Nothing)
+
+> positionalArg :: SParser ScalarExpr
+> positionalArg = PositionalArg <$> pos <*> liftPositionalArgTok
+>
+> antiScalarExpr :: SParser ScalarExpr
+> antiScalarExpr = AntiScalarExpr <$> splice 'e'
+>
+> placeholder :: SParser ScalarExpr
+> placeholder = (Placeholder <$> pos) <* symbol "?"
+>
+> numString :: SParser String
+> numString = mytoken (\tok -> case tok of
+>                                     Lex.SqlNumber n -> Just n
+>                                     _ -> Nothing)
+
+>
+> liftStringTok :: SParser String
+> liftStringTok = mytoken (\tok ->
+>                   case tok of
+>                            Lex.SqlString _ _ s ->
+>                               -- bit hacky, the lexer doesn't process quotes
+>                               -- but the parser expects them to have been replaced
+>                               Just $ T.unpack $ T.replace "''" "'" $ T.replace "\'" "'" $ T.pack s
+>                            _ -> Nothing)
+
+> stringLit :: SParser ScalarExpr
+> stringLit = choice
+>             [StringLit <$> pos <*> liftStringTok
+>              -- bit crap at the moment, not sure how to fix without
+>              -- mangling the ast types
+>             ,StringLit <$> pos <*> ((\s -> concat ["$s(",s,")"]) <$> splice 's')
+>             ]
+>
+> stringN :: SParser String
+> stringN = mytoken (\tok ->
+>                   case tok of
+>                            Lex.SqlString _ _ s -> Just s
+>                            _ -> Nothing)
+
+> extrStr :: ScalarExpr -> String
+> extrStr (StringLit _ s) = s
+> extrStr x =
+>   error $ "internal error: extrStr not supported for this type " ++ show x
+
+== combinatory things
+
+> parens :: SParser a
+>        -> SParser a
+> parens = between (symbol "(") (symbol ")")
+>
+> squares :: SParser a
+>        -> SParser a
+> squares = between (symbol "[") (symbol "]")
+>
+> tryOptionMaybe :: (Stream s m t) =>
+>              ParsecT s u m a -> ParsecT s u m (Maybe a)
+> tryOptionMaybe p = try (optionMaybe p) <|> return Nothing
+>
+> {-commaSep2 :: SParser a
+>           -> SParser [a]
+> commaSep2 p = sepBy2 p (symbol ",")
+>
+> sepBy2 :: (Stream s m t) =>
+>           ParsecT s u m a -> ParsecT s u m b -> ParsecT s u m [a]
+> sepBy2 p sep = (p <* sep) <:> sepBy1 p sep-}
+>
+> commaSep :: SParser a
+>          -> SParser [a]
+> commaSep p = sepBy p (symbol ",")
+>
+> commaSep1 :: SParser a
+>           -> SParser [a]
+> commaSep1 p = sepBy1 p (symbol ",")
+
+pass a list of pairs of strings and values
+try each pair k,v in turn,
+if keyword k matches then return v
+doesn't really add a lot of value
+
+> matchAKeyword :: [(Text, a)] -> SParser a
+> matchAKeyword [] = fail "no matches"
+> matchAKeyword ((k,v):kvs) = v <$ keyword k <|> matchAKeyword kvs
+
+optionalSuffix
+
+parse the start of something -> parseResultA,
+then parse an optional suffix -> parseResultB
+if this second parser succeeds, return fn2 parseResultA parseResultB
+else return fn1 parseResultA
+
+e.g.
+parsing an identifier in a select list can be
+fieldName
+or
+fieldName as alias
+so you can pass
+* IdentifierCtor
+* identifier (returns aval)
+* AliasedIdentifierCtor
+* parser for (as b) (returns bval)
+as the args, which I like to ident like:
+parseOptionalSuffix
+  IdentifierCtor identifierParser
+  AliasedIdentifierCtor () asAliasParser
+and you get either
+* IdentifierCtor identifierValue
+or
+* AliasedIdentifierCtor identifierValue aliasValue
+as the result depending on whether the asAliasParser
+succeeds or not.
+
+there must be a standard way of writing this
+
+> optionalSuffix :: (Stream s m t2) =>
+>                   (t1 -> b)
+>                -> ParsecT s u m t1
+>                -> (t1 -> a -> b)
+>                -> ParsecT s u m a
+>                -> ParsecT s u m b
+> optionalSuffix c1 p1 c2 p2 = do
+>   x <- p1
+>   option (c1 x) (c2 x <$> try p2)
+
+
+couldn't work how to to perms so just did this hack instead
+e.g.
+a1,a2,b1,b2,a2,b3,b4 parses to ([a1,a2,a3],[b1,b2,b3,b4])
+
+> multiPerm :: (Stream s m t) =>
+>                ParsecT s u m a1
+>             -> ParsecT s u m a
+>             -> ParsecT s u m sep
+>             -> ParsecT s u m ([a1], [a])
+>
+> multiPerm p1 p2 sep = do
+>   (r1, r2) <- unzip <$> sepBy1 parseAorB sep
+>   return (catMaybes r1, catMaybes r2)
+>   where
+>     parseAorB = choice [
+>                   (\x -> (Just x, Nothing)) <$> p1
+>                  ,(\y -> (Nothing, Just y)) <$> p2]
+
+== position stuff
+
+wrapper for parsec source positions, probably not really useful
+
+> type MySourcePos = (String,Int,Int)
+>
+> toMySp :: SourcePos -> MySourcePos
+> toMySp sp = (sourceName sp,sourceLine sp,sourceColumn sp)
+
+parser combinator to return the current position as an ast annotation
+
+> pos :: SParser Annotation
+> pos =
+>   (\a -> emptyAnnotation {anSrc = Just a}) <$> toMySp <$> getPosition
+
+== lexer stuff
+
+> mytoken :: (Lex.Token -> Maybe a) -> SParser a
+> mytoken test
+>   = token showToken posToken testToken
+>   where
+>   showToken (_,tok)   = show tok
+>   posToken  ((a,b,c),_)  = newPos a b c
+>   testToken (_,tok)   = test tok
+
+--------------------------------------------------------------------------------
+
+= fixup tree
+
+this is where some generics code is used to transform the parse trees
+to alter the nodes used where it's too difficult to do whilst
+parsing. The only item at the moment that needs this treatment is the
+any/some/all construct which looks like this:
+expr operator [any|some|all] (expr)
+
+This gets parsed as
+binop operator [expr1,app [any|some|all] [expr2,...]]
+
+and we want to transform it to
+liftoperator operator any|some|all [expr1, expr2,...]
+not doing anything if the funcall name isn't any,some,all
+any other checks are left to the type checking stage
+(e.g. there can only be one expression in the expr2 part, and it must
+be an array or subselect, etc)
+
+> fixupTree :: Data a => a -> a
+> fixupTree =
+>     transformBi $ \x ->
+>       case x of
+>              BinaryOp an op expr1 (App _ fn (expr2s:expr3s))
+>                | Name _ [Nmc fnm] <- fn
+>                , Just flav <- case map toLower fnm of
+>                                  "any" -> Just LiftAny
+>                                  "some" -> Just LiftAny
+>                                  "all" -> Just LiftAll
+>                                  _ -> Nothing
+>                -> LiftApp an op flav ([expr1,expr2s] ++ expr3s)
+>              x1 -> x1
diff --git a/src/Database/HsSqlPpp/Internals/PrettyInternal.lhs b/src/Database/HsSqlPpp/Internals/PrettyInternal.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/PrettyInternal.lhs
@@ -0,0 +1,1251 @@
+
+
+> {- | Functions to convert sql asts to valid SQL source code.
+>
+>    Some effort is made produce human readable output.
+> -}
+> {-# LANGUAGE PatternGuards,OverloadedStrings,TypeSynonymInstances,FlexibleInstances #-}
+> module Database.HsSqlPpp.Internals.PrettyInternal
+>     (--convert a sql ast to text
+>      prettyStatements
+>     --,printStatementsAnn
+>     ,prettyQueryExpr
+>      --convert a single expression parse node to text
+>     ,prettyScalarExpr
+>     ,PrettyFlags(..)
+>     )
+>     where
+>
+> import Text.PrettyPrint
+> import Data.Maybe
+>
+> import Database.HsSqlPpp.Syntax hiding (ann)
+> import Database.HsSqlPpp.Internals.AstInternal (
+>     Annotation(..)
+>    ,emptyAnnotation)
+> --import Database.HsSqlPpp.Utils.Utils
+
+> import Database.HsSqlPpp.Internals.Dialect
+
+todo: get rid of the types internal
+the ImplicitCast ctor uses Type instead of syntax only, this should be
+changed and then this import can be removed
+
+> import Database.HsSqlPpp.Internals.TypesInternal
+> --import Database.HsSqlPpp.Internals.StringLike
+> import qualified Data.Text as T
+> import qualified Data.Text.Lazy as L
+> import Database.HsSqlPpp.Internals.Utils
+
+--------------------------------------------------------------------------------
+
+Public functions
+
+> data PrettyFlags =
+>   PrettyFlags
+
+todo: actually use the dialect. this will forced when the parser is
+adjusted to reject postgres only syntax when in sql server dialect
+
+>   {ppDialect :: Dialect
+>   }
+>   deriving (Show,Eq)
+
+> -- | Convert an ast back to valid SQL source.
+> prettyStatements :: PrettyFlags -> [Statement] -> L.Text
+> prettyStatements f = prettyStatementsAnn f (const "")
+>
+> -- | Convert the ast back to valid source, and convert any annotations to
+> -- text using the function provided and interpolate the output of
+> -- this function (inside comments) with the SQL source.
+
+this needs some work
+
+> prettyStatementsAnn :: PrettyFlags -> (Annotation -> String) -> [Statement] -> L.Text
+> prettyStatementsAnn flg f ast =
+>   renderText $ vcat (map (statement flg True f) ast) <> text "\n"
+
+> -- | pretty print a query expression
+> prettyQueryExpr :: PrettyFlags -> QueryExpr -> L.Text
+> prettyQueryExpr f ast = renderText (queryExpr f True True Nothing ast <> statementEnd True)
+
+> -- | pretty print a scalar expression
+> prettyScalarExpr :: PrettyFlags -> ScalarExpr -> L.Text
+> prettyScalarExpr f = renderText . scalExpr f
+
+direct = true means attempt to pretty print straight to text
+direct = false means pretty print to string then pack to text
+no idea which is better, since pretty printing to text directly uses a
+ lot of Text.cons which might be pretty slow and bloated
+
+> direct :: Bool
+> direct = True
+
+> renderText :: Doc -> L.Text
+> renderText doc =
+>   if direct
+>   then fullRender (mode style) (lineLength style) (ribbonsPerLine style)
+>                    dataTextPrettyer "" doc
+>   else L.pack $ render doc
+
+
+> dataTextPrettyer :: TextDetails -> L.Text -> L.Text
+> dataTextPrettyer (Chr c)   s  = L.cons c s
+> dataTextPrettyer (Str s1)  s2 = L.pack s1 `L.append` s2
+> dataTextPrettyer (PStr s1) s2 = L.pack s1 `L.append` s2
+
+-------------------------------------------------------------------------------
+
+Conversion routines - convert Sql asts into Docs
+
+> -- Statements
+>
+> statement :: PrettyFlags -> Bool -> (Annotation -> String) -> Statement -> Doc
+> statement _flg _se _ca (AntiStatement s) = text $ "$(" ++ s ++ ")"
+>
+> -- selects
+>
+> statement flg se ca (QueryStatement ann s) =
+>   annot ca ann <+>
+>   queryExpr flg True True Nothing s <> statementEnd se
+>
+> --dml
+>
+> statement flg se pa (Insert ann tb atts idata rt) =
+>   annot pa ann <+>
+>   text "insert into" <+> name tb
+>   <+> ifNotEmpty (parens . sepCsvMap nmc) atts
+>   $+$ queryExpr flg True True Nothing idata
+>   $+$ returning flg rt
+>   <> statementEnd se
+>
+> statement flg se ca (Update ann tb scs fr wh rt) =
+>    annot ca ann <+>
+>    text "update" <+> name tb <+> text "set"
+>    <+> sepCsvMap (set flg) scs
+>    <+> ifNotEmpty (\_ -> text "from" <+> sepCsvMap (tref flg) fr) fr
+>    <+> whr flg wh
+>    $+$ returning flg rt <> statementEnd se
+>
+> statement flg se ca (Delete ann tbl us wh rt) =
+>    annot ca ann <+>
+>    text "delete from" <+> name tbl
+>    <+> ifNotEmpty (\_ -> text "using" <+> sepCsvMap (tref flg) us) us
+>    <+> whr flg wh
+>    $+$ returning flg rt
+>    <> statementEnd se
+>
+> statement flg se ca (Truncate ann names ri casc) =
+>     annot ca ann <+>
+>     text "truncate"
+>     <+> sepCsvMap name names
+>     <+> case (diSyntaxFlavour $ ppDialect flg) of
+>        SqlServer -> empty
+>        _ -> text (case ri of
+>                       RestartIdentity -> "restart identity"
+>                       ContinueIdentity -> "continue identity")
+>             <+> cascade casc
+>     <> statementEnd se
+>
+> -- ddl
+>
+> statement flg se ca (CreateTable ann tbl atts cns partition rep) =
+>     annot ca ann <+>
+>     text ("create " ++ (case rep of
+>                          Replace -> "or replace "
+>                          _ -> "") ++ "table")
+>     <+> name tbl <+> lparen
+>     $+$ nest 2 (vcat (csv (map (attrDef flg) atts ++ map (constraint flg) cns)))
+>     $+$ rparen
+>     $+$ case (diSyntaxFlavour $ ppDialect flg) of
+>          SqlServer -> empty
+>          _ -> (tablePartition partition)
+>     <> statementEnd se
+>
+> statement flg se ca (AlterTable ann tnm op) =
+>     annot ca ann <+>
+>     text "alter table" <+> name tnm
+>     <+> alterOperation op <> statementEnd se
+>     where
+>       alterOperation (RenameTable _ nm) = 
+>           text "rename to" <+> name nm
+>       alterOperation (RenameColumn _ old new) = 
+>           text "rename column" <+> nmc old <+> "to" <+> nmc new
+>       alterOperation (AlterTableActions _ actions) = hcatCsvMap alterAction actions
+>       alterAction (AddColumn _ att) = 
+>           text "add column" <+> attrDef flg att
+>       alterAction (DropColumn _ nm) = 
+>           text "drop column" <+> nmc nm
+>       alterAction (AlterColumn _ nm action) = 
+>           text "alter column" <+> nmc nm <+> alterColumnAction action
+>       alterAction (AddConstraint _ con) =
+>           text "add" <+> constraint flg con
+>       alterColumnAction (SetDataType _ t) =
+>           text "set data type" <+> typeName t
+>       alterColumnAction (SetNotNull _) =
+>           text "set not null"
+>       alterColumnAction (DropNotNull _) =
+>           text "drop not null"
+>       alterColumnAction (SetDefault _ def) =
+>           text "set default" <+> scalExpr flg def
+>       alterColumnAction (DropDefault _) =
+>           text "drop default"
+>
+> statement _flg se ca (CreateSequence ann nm incr minv maxv start cache) =
+>     annot ca ann <+>
+>     text "create sequence" <+> name nm <+>
+>     text "increment" <+> text (show incr) <+>
+>     maybe (text "no minvalue") ((text "minvalue" <+>) . (text . show)) minv <+>
+>     maybe (text "no maxvalue") ((text "maxvalue" <+>) . (text . show)) maxv <+>
+>     text "start with" <+> text (show start) <+>
+>     text "cache" <+> text (show cache) <> statementEnd se
+>
+> statement _flg se ca (AlterSequence ann nm op) =
+>     annot ca ann <+>
+>     text "alter sequence" <+> name nm
+>     <+> alterOperation op <> statementEnd se
+>     where
+>       alterOperation (AlterSequenceOwned _ o) = 
+>           text "owned by" <+> name o
+>       alterOperation (AlterSequenceRename _ rnm) = 
+>           text "rename to" <+> name rnm
+>       alterOperation (AlterSequenceActions _ actions) = hsep $ map alterAction actions
+>       alterAction (AlterSequenceIncrement _ incr) = 
+>           text "increment by" <+> text (show incr)
+>       alterAction (AlterSequenceMin _ minv) =
+>           maybe (text "no minvalue") ((text "minvalue" <+>) . (text . show)) minv
+>       alterAction (AlterSequenceMax _ maxv) =
+>           maybe (text "no maxvalue") ((text "maxvalue" <+>) . (text . show)) maxv
+>       alterAction (AlterSequenceStart _ start) = 
+>           text "start with" <+> text (show start)
+>       alterAction (AlterSequenceRestart _ restart) = 
+>           text "restart" <+> text (maybe "" (("with " ++) . show) restart)
+>       alterAction (AlterSequenceCache _ cache) = 
+>           text "cache" <+> text (show cache)
+
+>
+> statement flg se ca (CreateTableAs ann t rep sel) =
+>     annot ca ann <+>
+>     text ("create " ++ (case rep of
+>                          Replace -> "or replace "
+>                          _ -> "") ++ "table")
+>     <+> name t <+> text "as"
+>     $+$ queryExpr flg True True Nothing sel
+>     <> statementEnd se
+>
+> statement flg se ca (CreateFunction ann nm args retType rep lang body vol) =
+>     annot ca ann <+>
+>     text ("create " ++ (case rep of
+>                          Replace -> "or replace "
+>                          _ -> "") ++ "function")
+>     <+> name nm
+>     <+> parens (sepCsvMap paramDefn args)
+>     <+> text "returns" <+> typeName retType <+> text "as" <+> text "$$"
+>     $+$ functionBody body
+>     $+$ text "$$" <+> text "language"
+>     <+> text (case lang of
+>                         Sql -> "sql"
+>                         Plpgsql -> "plpgsql")
+>     <+> text (case vol of
+>                        Volatile -> "volatile"
+>                        Stable -> "stable"
+>                        Immutable -> "immutable")
+>     <> statementEnd se
+>     where
+>       functionBody (SqlFnBody ann1 sts) =
+>         annot ca ann1 <+>
+>         nestedStatements flg ca sts
+>       functionBody (PlpgsqlFnBody ann1 blk) =
+>           annot ca ann1 <+>
+>           statement flg True ca blk
+>       paramDefn (ParamDef _ n t) = nmc n <+> typeName t
+>       paramDefn  (ParamDefTp _ t) = typeName t
+>
+> statement flg se ca (Block ann lb decls sts) =
+>   annot ca ann <+>
+>   label lb <>
+>   ifNotEmpty (\l -> text "declare"
+>                   $+$ nest 2 (vcat $ map varDefn l)) decls
+>   $+$ text "begin"
+>   $+$ nestedStatements flg ca sts
+>   $+$ text "end" <> statementEnd se
+>   where
+>       varDefn (VarDef _ n t v) =
+>         nmc n <+> typeName t
+>         <+> maybePrint (\x -> text ":=" <+> scalExpr flg x) v <> semi
+>       varDefn (VarAlias _ n n1) =
+>         nmc n <+> text "alias for" <+> name n1 <> semi
+>       varDefn (ParamAlias _ n p) =
+>         nmc n <+> text "alias for $" <> text (show p) <> semi
+>
+>
+> statement flg se ca (CreateView ann nm cols sel) =
+>     annot ca ann <+>
+>     text "create view" <+> name nm
+>     <> case cols of
+>          Nothing -> empty
+>          Just cs -> parens (sepCsvMap nmc cs)
+>     <+> text "as"
+>     $+$ nest 2 (queryExpr flg True True Nothing sel) <> statementEnd se
+>
+> statement flg se ca (AlterView ann nm cols sel) =
+>     annot ca ann <+>
+>     text "alter view" <+> name nm
+>     <> case cols of
+>          Nothing -> empty
+>          Just cs -> parens (sepCsvMap nmc cs)
+>     <+> text "as"
+>     $+$ nest 2 (queryExpr flg True True Nothing sel) <> statementEnd se
+>
+> statement flg se ca (CreateDomain ann nm tp n ex) =
+>     annot ca ann <+>
+>     text "create domain" <+> name nm <+> text "as"
+>     <+> typeName tp <+> cname <+> checkExp ex <> statementEnd se
+>     where
+>       checkExp = maybePrint (\e -> text "check" <+> parens (scalExpr flg e))
+>       cname = if n == ""
+>                then empty
+>                else text "constraint" <+> ttext n
+>
+> statement _flg se ca (CreateDatabase ann nm) =
+>     annot ca ann <+>
+>     text "create database" <+> name nm <> statementEnd se
+
+> statement _flg se ca (CreateSchema ann nm musr) =
+>     annot ca ann <+> text "create schema" <+> nmc nm 
+>     <+> case musr of
+>           Nothing -> empty
+>           Just u -> text "authorization" <+> name u
+>     <> statementEnd se
+
+> statement _flg se ca (AlterDatabase ann nm op) =
+>     annot ca ann <+> text "alter database" <+>
+>           name nm <+> alterDbOperation op <> statementEnd se
+>     where
+>      alterDbOperation (RenameDatabase _ nm') =
+>       text "rename to" <+> name nm'
+
+> statement _flg se ca (AlterSchema ann snm op) =
+>     annot ca ann <+>
+>     text "alter schema" <+> nmc snm
+>     <+> alterOperation op <> statementEnd se
+>     where
+>       alterOperation (AlterSchemaName _ nsnm) = 
+>           text "rename to" <+> nmc nsnm
+>       alterOperation (AlterSchemaOwner _ nunm) = 
+>           text "owner to" <+> name nunm
+
+> statement _flg se ca (DropFunction ann ifE fns casc) =
+>   annot ca ann <+>
+>   text "drop function"
+>   <+> ifExists ifE
+>   <+> sepCsvMap doFunction fns
+>   <+> cascade casc
+>   <> statementEnd se
+>   where
+>     doFunction (nm,types) =
+>       name nm <> parens (sepCsvMap typeName types)
+>
+> statement flg se ca (DropSomething ann dropType ifE names casc) =
+>     annot ca ann <+>
+>     text "drop"
+>     <+> text (case dropType of
+>                 Table -> "table"
+>                 View -> "view"
+>                 Domain -> "domain"
+>                 Type -> "type"
+>                 Database -> "database"
+>                 User -> "user"
+>                 Login -> "login"
+>                 Schema -> "schema")
+>     <+> ifExists ifE
+>     <+> sepCsvMap name names
+>     <+> case (diSyntaxFlavour $ ppDialect flg) of
+>            SqlServer -> empty
+>            _ -> cascade casc
+>     <> statementEnd se
+>
+> statement _flg se ca (DropTrigger ann ifE nam tbn casc) =
+>     annot ca ann <+>
+>     text "drop"
+>     <+> text "trigger"
+>     <+> ifExists ifE
+>     <+> nmc nam
+>     <+> text "on"
+>     <+> name tbn
+>     <+> cascade casc
+>     <> statementEnd se
+>
+> statement _flg se ca (CreateType ann nm atts) =
+>     annot ca ann <+>
+>     text "create type" <+> name nm <+> text "as" <+> lparen
+>     $+$ nest 2 (vcat (csv
+>           (map (\(TypeAttDef _ n t) -> nmc n <+> typeName t)  atts)))
+>     $+$ rparen <> statementEnd se
+>
+> statement _flg se ca (CreateLanguage ann nm) =
+>     annot ca ann <+>
+>     text "create language" <+> ttext nm <> statementEnd se
+>
+> statement flg se ca (CreateTrigger ann nm wh events tbl firing fnName fnArgs) =
+>     annot ca ann <+>
+>     text "create trigger" <+> nmc nm
+>     <+> text (case wh of
+>                       TriggerBefore -> "before"
+>                       TriggerAfter -> "after")
+>     <+> evs
+>     <+> text "on" <+> name tbl
+>     <+> text "for" <+> text (case firing of
+>                                         EachRow -> "row"
+>                                         EachStatement -> "statement")
+>     <+> text "execute procedure" <+> name fnName
+>     <> parens (sepCsvMap (scalExpr flg) fnArgs) <> statementEnd se
+>     where
+>       evs = sep $ punctuate (text " or ") $ map
+>             (text . (\e -> case e of
+>                                 TInsert -> "insert"
+>                                 TUpdate -> "update"
+>                                 TDelete -> "delete"
+>                                 AntiTriggerEvent s -> "$(" ++ s ++ ")")) events
+>
+> -- plpgsql
+>
+> statement _flg se ca (NullStatement ann) =
+>   annot ca ann <+> text "null" <> statementEnd se
+> statement _flg se ca (ExitStatement ann lb) =
+>   annot ca ann <+> text "exit"
+>     <+> maybe empty ttext lb <> statementEnd se
+>
+
+> statement flg se ca (Into ann str is (QueryStatement _ q)) =
+>   annot ca ann <+>
+>   queryExpr flg True True (Just (str,is)) q <> statementEnd se
+
+
+> statement flg se ca (Into ann str into st) =
+>   annot ca ann <+>
+>   statement flg False ca st
+>   <+> text "into"
+>   <> (if str
+>       then empty <+> text "strict"
+>       else empty)
+>   <+> sepCsvMap name into
+>   <> statementEnd se
+>   --fixme, should be insert,update,delete,execute
+
+> statement flg se ca (Assignment ann nm val) =
+>     annot ca ann <+>
+>     name nm <+> text ":=" <+> scalExpr flg val <> statementEnd se
+>
+> statement flg se ca (Return ann ex) =
+>     annot ca ann <+>
+>     text "return" <+> maybePrint (scalExpr flg) ex <> statementEnd se
+>
+> statement flg se ca (ReturnNext ann ex) =
+>     annot ca ann <+>
+>     text "return" <+> text "next" <+> scalExpr flg ex <> statementEnd se
+>
+> statement flg se ca (ReturnQuery ann sel) =
+>     annot ca ann <+>
+>     text "return" <+> text "query"
+>     <+> queryExpr flg True True Nothing sel <> statementEnd se
+>
+> statement flg se ca (Raise ann rt st exps) =
+>     annot ca ann <+>
+>     text "raise"
+>     <+> case rt of
+>                 RNotice -> text "notice"
+>                 RException -> text "exception"
+>                 RError -> text "error"
+>     <+> scalExpr flg (StringLit emptyAnnotation st)
+>     <> ifNotEmpty (\e -> comma <+> csvExp flg e) exps
+>     <> statementEnd se
+>
+> statement flg se ca (ForQueryStatement ann lb i sel stmts) =
+>     annot ca ann <+>
+>     label lb <>
+>     text "for" <+> nmc i <+> text "in"
+>     <+> queryExpr flg True True Nothing sel <+> text "loop"
+>     $+$ nestedStatements flg ca stmts
+>     $+$ text "end loop" <> statementEnd se
+>
+> statement flg se ca (ForIntegerStatement ann lb var st en stmts) =
+>     annot ca ann <+>
+>     label lb <>
+>     text "for" <+> nmc var <+> text "in"
+>     <+> scalExpr flg st <+> text ".." <+> scalExpr flg en <+> text "loop"
+>     $+$ nestedStatements flg ca stmts
+>     $+$ text "end loop" <> statementEnd se
+>
+> statement flg se ca (WhileStatement ann lb ex stmts) =
+>     annot ca ann <+>
+>     label lb <>
+>     text "while" <+> scalExpr flg ex <+> text "loop"
+>     $+$ nestedStatements flg ca stmts
+>     $+$ text "end loop" <> statementEnd se
+> statement flg se ca (LoopStatement ann lb stmts) =
+>     annot ca ann <+>
+>     label lb <>
+>     text "loop"
+>     $+$ nestedStatements flg ca stmts
+>     $+$ text "end loop" <> statementEnd se
+>
+> statement _flg se ca (ContinueStatement ann lb) =
+>     annot ca ann <+> text "continue"
+>       <+> maybe empty ttext lb <> statementEnd se
+> statement flg se ca (Perform ann f@(App {})) =
+>     annot ca ann <+>
+>     text "perform" <+> scalExpr flg f <> statementEnd se
+> statement _ _ _ (Perform _ x) =
+>    error $ "internal error: statement not supported for " ++ show x
+>
+> statement _flg se ca (CopyFrom ann tb cols src opts) =
+>     annot ca ann <+>
+>     text "copy" <+> name tb
+>     <+> ifNotEmpty (parens . sepCsvMap nmc) cols
+>     <+> text "from"
+>     <+> case src of
+>                  CopyFilename s -> (quotes $ ttext s)
+>                                    <+> copyFromOpts opts
+>                                    <> statementEnd se
+
+>                  Stdin -> text "stdin"
+>                           <+> copyFromOpts opts
+>                           -- put statement end without new line
+>                           -- so that the copydata follows immediately after
+>                           -- without an extra blank line inbetween
+>                           <> statementEndNNL se
+
+> statement flg se ca (CopyTo ann src fn opts) =
+>     annot ca ann <+>
+>     text "copy" <+> s src
+>     <+> text "to"
+>     <+> quotes (ttext fn)
+>     <+> copyToOpts opts
+>     <> statementEnd se
+>     where
+>       s (CopyTable tb cols) = name tb
+>                               <+> ifNotEmpty (parens . sepCsvMap nmc) cols
+>       s (CopyQuery qry) = parens (queryExpr flg True True Nothing qry)
+>
+> statement _ _ ca (CopyData ann s) =
+>     annot ca ann <+>
+>     tltext s <> text "\\." <> newline
+>
+> statement flg se ca (If ann conds els) =
+>    if tsql
+>    then
+>      annot ca ann <+>
+>      text "if" <+> scalExpr flg (fst $ head conds)
+>                <+> blck (snd $ head conds)
+>      $+$ ifNotEmpty (\e -> text "else" <+> blck e) els
+>      <> statementEnd se
+>    else
+>      annot ca ann <+>
+>      text "if" <+> constraintd (head conds)
+>      $+$ vcat (map (\c -> text "elseif" <+> constraintd c) $ tail conds)
+>      $+$ ifNotEmpty (\e -> text "else" $+$ nestedStatements flg ca e) els
+>      $+$ text "end if" <> statementEnd se
+>    where
+>      constraintd (ex, sts) = scalExpr flg ex <+> text "then"
+>                              $+$ nestedStatements flg ca sts
+>      tsql = diSyntaxFlavour (ppDialect flg) == SqlServer
+>      blck sts = sep [text "begin"
+>                     ,nestedStatements flg ca sts
+>                     ,text "end"]
+> statement flg se ca (Execute ann s) =
+>     annot ca ann <+>
+>     text "execute" <+> scalExpr flg s <> statementEnd se
+>
+>
+> statement flg se ca (CaseStatementSimple ann c conds els) =
+>     annot ca ann <+>
+>     text "case" <+> scalExpr flg c
+>     $+$ nest 2 (
+>                 vcat (map (uncurry whenStatement) conds)
+>                 $+$ elseStatement els
+>                 ) $+$ text "end case" <> statementEnd se
+>     where
+>       whenStatement ex sts = text "when" <+> sepCsvMap (scalExpr flg) ex
+>                           <+> text "then" $+$ nestedStatements flg ca sts
+>       elseStatement = ifNotEmpty (\s -> text "else"
+>                                      $+$ nestedStatements flg ca s)
+> statement flg se ca (CaseStatement ann conds els) =
+>     annot ca ann <+>
+>     text "case"
+>     $+$ nest 2 (
+>                 vcat (map (uncurry whenStatement) conds)
+>                 $+$ elseStatement els
+>                 ) $+$ text "end case" <> statementEnd se
+>     where
+>       whenStatement ex sts = text "when" <+> sepCsvMap (scalExpr flg) ex
+>                           <+> text "then" $+$ nestedStatements flg ca sts
+>       elseStatement = ifNotEmpty (\s -> text "else"
+>                                      $+$ nestedStatements flg ca s)
+
+> statement flg _se ca (DeclareStatement ann des) =
+>   annot ca ann <+>
+>   text "declare" <+> sepCsvMap de des
+>   where
+>     de (nm,ty,val) =
+>       ttext nm <+> typeName ty
+>       <+> maybe empty (\e -> text "=" <+> scalExpr flg e) val
+
+>
+> -- misc
+>
+> statement _flg se _ (Set _ n vs) =
+>   text "set" <+> ttext n <+> text "="
+>   <+> sepCsvMap (text . dv) vs <> statementEnd se
+>   where
+>     dv (SetStr _ s) = "'" ++ s ++ "'"
+>     dv (SetId _ i) = i
+>     dv (SetNum _ nm) = show nm
+>
+> statement _flg se _ (Notify _ n) =
+>   text "notify" <+> ttext n  <> statementEnd se
+
+> statement flg _se _ (ExecStatement _ nm args) =
+>   text "exec" <+> name nm <+> sepCsvMap (scalExpr flg) args
+
+> statement _flg _se _ (CreateIndexTSQL _ nm obj cols) =
+>   text "create" <+> text "index"
+>   <+> nmc nm <+> text "on"
+>   <+> name obj <+> parens (sepCsvMap nmc cols)
+
+> statement _flg _se _ (CreateUser _ nm pw) =
+>   text "create user" <+> name nm
+>   <+> text "with password=" <> quotes (text pw)
+
+> statement _flg _se _ (CreateLogin _ nm pw) =
+>   text "create login" <+> name nm
+>   <+> text "with password=" <> quotes (text pw)
+
+> statement _flg _se _ (AlterUser _ nm pw) =
+>   text "alter user" <+> name nm
+>   <+> text "with password=" <> quotes (text pw)
+
+> statement _flg _se _ (AlterLogin _ nm pw) =
+>   text "alter login" <+> name nm
+>   <+> text "with password=" <> quotes (text pw)
+
+
+> statementEnd :: Bool -> Doc
+> statementEnd b = if b
+>                  then semi <> newline
+>                  else empty
+
+> statementEndNNL :: Bool -> Doc
+> statementEndNNL b = if b
+>                     then semi
+>                     else empty
+
+
+-------------------------------------------------------------------------------
+
+Statement components
+
+> -- selects
+>
+> queryExpr :: PrettyFlags -> Bool -> Bool -> Maybe (Bool,[Name]) -> QueryExpr -> Doc
+> queryExpr flg writeSelect _ intoi (Select _ dis l tb wh grp hav
+>                                     order lim off hs) =
+>   (text (if writeSelect then "select" else "")
+>          <+> (case dis of
+>                  All -> empty
+>                  Distinct -> text "distinct"))
+>          <+> (case lim of
+>                  Just lime | useTop -> text "top" <+> scalExpr flg lime
+>                  _ -> empty)
+>   $+$ nest 2 (vcat $ catMaybes
+>   [fmap (\(str,is) -> text "into"
+>                       <+> (if str
+>                            then text "strict"
+>                            else empty)
+>                       <+> sepCsvMap name is) intoi
+>   ,Just $ nest 2 $ selectList flg l
+>   ,Just $ if null tb
+>           then empty
+>           else text "from" $+$ nest 2 (sepCsvMap (tref flg) tb)
+>   ,Just $ whr flg wh
+>   ,case grp of
+>      [] -> Nothing
+>      g -> Just $ text "group by" $+$ nest 2 (sepCsvMap (scalExpr flg) g)
+>   ,flip fmap hav $ \h -> text "having" $+$ nest 2 (scalExpr flg h)
+>   ,Just $ orderBy flg order
+>   ,if useTop then Nothing else flip fmap lim $ \lm -> text "limit" <+> scalExpr flg lm
+>   ,flip fmap off $ \offs -> text "offset" <+> scalExpr flg offs
+>   ,if null hs then Nothing else Just $ text "option" $+$ parens (sepCsvMap (text . prettyQueryHint) hs)
+>   ])
+>   where
+>     useTop = (diSyntaxFlavour $ ppDialect flg) == SqlServer
+>     prettyQueryHint QueryHintPartitionGroup = "partition group"
+>     prettyQueryHint QueryHintColumnarHostGroup = "columnar host group"
+>
+> queryExpr flg writeSelect topLev _ (CombineQueryExpr _ tp s1 s2) =
+>   let p = queryExpr flg writeSelect False Nothing  s1
+>           $+$ (case tp of
+>                        Except -> text "except"
+>                        Union -> text "union"
+>                        UnionAll -> text "union" <+> text "all"
+>                        Intersect -> text "intersect")
+>           $+$ queryExpr flg True False Nothing s2
+>   in if topLev then p else parens p
+> queryExpr flg _ _ _ (Values _ expss) =
+>   text "values" $$ nest 2 (vcat $ csv $ map (parens . csvExp flg) expss)
+> queryExpr flg _ _ _ (WithQueryExpr _ wqs ex) =
+>   text "with" $$ nest 2 (vcat $ csv $ map pwq wqs)
+>        $+$ queryExpr flg True False Nothing ex
+>   where
+>     pwq (WithQuery _ nm cs ex1) =
+>       nmc nm <> case cs of
+>                    Nothing -> empty
+>                    Just cs' -> parens $ sepCsvMap nmc cs'
+>       <+> text "as"
+>       <+> parens (queryExpr flg True False Nothing ex1)
+
+> name :: Name -> Doc
+> name (Name _ ns) = nmcs ns
+> name (AntiName n) = text ("$n(" ++ n ++ ")")
+
+> nmcs :: [NameComponent] -> Doc
+> nmcs ns = hcat $ punctuate (text ".") $ map nmc ns
+
+> nmc :: NameComponent -> Doc
+> nmc (Nmc ns) = ttext ns
+> nmc (QNmc ns) = doubleQuotes $ ttext ns
+> nmc (AntiNameComponent n) = text ("$m(" ++ n ++ ")")
+
+>
+> tref :: PrettyFlags -> TableRef -> Doc
+> tref _ (Tref _ f) = name f
+> tref flg (SubTref _ sub) =
+>   parens (queryExpr flg True True Nothing sub)
+> tref flg (FunTref _ f@(App {})) = scalExpr flg f
+> tref _flg (FunTref _ x) =
+>       error $ "internal error: node not supported in function tref: "
+>             ++ show x
+> tref flg (TableRefParens _ t) = parens (tref flg t)
+> tref flg (OdbcTableRef _ t) = text "{oj" <+> tref flg t <> text "}"
+> tref flg (TableAlias _ t tr) = maybeParen flg tr <+> text "as" <+> nmc t
+> -- hack this out for now. When the type checking is fixed, can try
+> -- to eliminate unneeded aliases?
+> tref flg (FullAlias _ t s tr) =
+>   maybeParen flg tr <+> text "as"
+>   <+> nmc t <> parens (sepCsvMap nmc s)
+
+> tref flg (JoinTref _ t1 nat jt ht t2 ex) =
+>   sep [tref flg t1
+>       ,hsep ([case nat of
+>                 Natural -> text "natural"
+>                 Unnatural -> empty
+>             ,text $ case jt of
+>                Inner -> "inner"
+>                Cross -> "cross"
+>                LeftOuter -> "left outer"
+>                RightOuter -> "right outer"
+>                FullOuter -> "full outer"]
+>             ++ maybe [] (\h -> [text $ case h of
+>                               Merge -> "merge"
+>                               Loop -> "loop"
+>                               Hash -> "hash"])
+>                      ht
+>             ++ [text "join"])
+>       ,tref flg t2
+>       ,maybePrint (nest 2 . joinScalarExpr) ex]
+>   where
+>     joinScalarExpr (JoinOn _ e) = text "on" <+> scalExpr flg e
+>     joinScalarExpr (JoinUsing _ ids) =
+>         text "using" <+> parens (sepCsvMap nmc ids)
+
+todo: don't want to do this here since it changes pretty . parse = id
+so if you don't add the parens explicitly you get incorrect/ invalid
+syntax maybe should error instead of silently breaking
+
+> maybeParen :: PrettyFlags -> TableRef -> Doc
+> --maybeParen flg t@(JoinTref {}) = parens $ tref flg t
+> maybeParen = tref
+
+> direction :: Direction -> Doc
+> direction d = text $ case d of
+>                           Asc -> "asc"
+>                           Desc -> "desc"
+>
+
+> nullsOrder :: NullsOrder -> Doc
+> nullsOrder d = case d of
+>                     NullsDefault -> empty
+>                     NullsFirst -> text "nulls " <+> text "first"
+>                     NullsLast  -> text "nulls " <+> text "last"
+>
+> whr :: PrettyFlags -> Maybe ScalarExpr -> Doc
+> whr flg (Just ex) = text "where" $+$ nest 2 (scalExpr flg ex)
+> whr _ Nothing = empty
+>
+> selectList :: PrettyFlags -> SelectList -> Doc
+> selectList flg (SelectList _ ex) =
+>   sepCsvMap selectItem ex
+>   where
+>     selectItem (SelectItem _ ex1 nm) = scalExprSl flg ex1 <+> text "as" <+> nmc nm
+>     selectItem (SelExp _ e) = scalExprSl flg e
+>
+> cascade :: Cascade -> Doc
+> cascade casc = text $ case casc of
+>                                  Cascade -> "cascade"
+>                                  Restrict -> "restrict"
+
+> copyToOpts :: [CopyToOption] -> Doc
+> copyToOpts opts =
+>   ifNotEmpty (const $ "with" <+> sep (map po opts)) opts
+>   where
+>       po (CopyToFormat s) = text "format" <+> text s
+>       po (CopyToDelimiter s) = text "delimiter" <+> quotes (text s)
+>       po (CopyToErrorLog s) = text "error_log" <+> quotes (text s)
+>       po (CopyToErrorVerbosity s) = text "error_verbosity" <+> int s
+
+> copyFromOpts :: [CopyFromOption] -> Doc
+> copyFromOpts opts =
+>   ifNotEmpty (const $ "with" <+> sep (map po opts)) opts
+>   where
+>       po (CopyFromFormat s) = text "format" <+> text s
+>       po (CopyFromDelimiter s) = text "delimiter" <+> quotes (text s)
+>       po (CopyFromErrorLog s) = text "error_log" <+> quotes (text s)
+>       po (CopyFromErrorVerbosity s) = text "error_verbosity" <+> int s
+>       po (CopyFromParsers s) = text "parsers" <+> quotes (text s)
+>       po (CopyFromDirectory) = text "directory"
+>       po (CopyFromOffset i) = text "offset" <+> integer i
+>       po (CopyFromLimit i) = text "limit" <+> integer i
+>       po (CopyFromErrorThreshold i) = text "stop after" <+> int i <+> text "errors"
+>       po (CopyFromNewlineFormat n) = text "record delimiter" <+> text n
+> -- ddl
+>
+> constraint :: PrettyFlags -> Constraint -> Doc
+> constraint _flg (UniqueConstraint _ n c) =
+>         mname n <+> text "unique"
+>         <+> parens (sepCsvMap nmc c)
+> constraint _flg (PrimaryKeyConstraint _ n p) =
+>         mname n <+>
+>         text "primary key"
+>         <+> parens (sepCsvMap nmc p)
+> constraint flg (CheckConstraint _ n c) =
+>         mname n <+> text "check" <+> parens (scalExpr flg c)
+> constraint _flg (ReferenceConstraint _ n at tb rat ondel onupd) =
+>         mname n <+>
+>         text "foreign key" <+> parens (sepCsvMap nmc at)
+>         <+> text "references" <+> name tb
+>         <+> ifNotEmpty (parens . sepCsvMap nmc) rat
+>         <+> text "on update" <+> cascade onupd
+>         <+> text "on delete" <+> cascade ondel
+>
+> mname :: String -> Doc
+> mname n = if n == ""
+>           then empty
+>           else text "constraint" <+> text n
+>
+> returning :: PrettyFlags -> Maybe SelectList -> Doc
+> returning flg l = case l of
+>                 Nothing -> empty
+>                 Just ls -> nest 2 (text "returning" <+> selectList flg ls)
+>
+> ifExists :: IfExists -> Doc
+> ifExists i = case i of
+>                         Require -> empty
+>                         IfExists -> text "if exists"
+>
+
+> tablePartition :: Maybe TablePartitionDef -> Doc
+> tablePartition Nothing = text ""
+> tablePartition (Just (TablePartitionDef _ cn tf interval)) =
+>      text "partition by range" <+> parens (nmc cn)
+>      <> parens ((text "every") <+> (text $ show tf) <+> (intervalify interval))
+>  where
+>   intervalify = \x-> text $ case x of
+>            Year -> "years"
+>            Month -> "months"
+>            Day -> "days"
+>            Hour -> "hours"
+>            Minute -> "minutes"
+>            Second -> "seconds"
+>            Millisecond -> "milliseconds"
+>            -- _ -> "unknown type " ++ (show x)
+
+> attrDef :: PrettyFlags -> AttributeDef -> Doc
+> attrDef flg (AttributeDef _ n t def cons) =
+>   nmc n <+> typeName t
+>   <+> maybePrint (\e -> text "default" <+> scalExpr flg e) def
+>   <+> hsep (map cCons cons)
+>   where
+>     cCons (NullConstraint _ cn) =
+>       mname cn <+> text "null"
+>     cCons (NotNullConstraint _ cn) =
+>       mname cn <+> text "not null"
+>     cCons (RowCheckConstraint _ cn ew) =
+>       mname cn <+> text "check" <+> parens (scalExpr flg ew)
+>     cCons (RowUniqueConstraint _ cn) =
+>       mname cn <+> text "unique"
+>     cCons (RowPrimaryKeyConstraint _ cn) =
+>       mname cn <+> text "primary key"
+>     cCons (RowReferenceConstraint _ cn tb att ondel onupd) =
+>       mname cn <+> text "references" <+> name tb
+>       <+> maybePrint (parens . nmc) att
+>       <+> text "on delete" <+> cascade ondel
+>       <+> text "on update" <+> cascade onupd
+>     cCons (IdentityConstraint _ cn si) = 
+>       mname cn <+> text "identity" <> text (maybe "" show si)
+> -- plpgsql
+>
+> nestedStatements :: PrettyFlags -> (Annotation -> String) -> [Statement] -> Doc
+> nestedStatements flg pa = nest 2 . vcat . map (statement flg True pa)
+>
+> typeName :: TypeName -> Doc
+> typeName (SimpleTypeName _ s) = name s
+> typeName (PrecTypeName _ s i) = name s <> parens(integer i)
+> typeName (Prec2TypeName _ s i i1) = name s <> parens (sepCsv [integer i, integer i1])
+> typeName (ArrayTypeName _ t) = typeName t <> text "[]"
+> typeName (SetOfTypeName _ t) = text "setof" <+> typeName t
+>
+> ppType:: Type -> Doc
+> ppType (ScalarType t) = text "scalar type" <> parens (text $ T.unpack t)
+> ppType (DomainType t) = text "domain type" <> parens (text $ T.unpack t)
+> ppType (EnumType t) = text "enum type" <> parens (text $ T.unpack t)
+> ppType (UnknownType) = text "unknown type"
+> ppType (ArrayType t) = text "array type" <> parens (ppType t)
+> ppType (NamedCompositeType t) = text "named composite type" <> parens (text $ T.unpack t)
+> ppType (CompositeType ts)
+>     = text "composite type"
+>       <> brackets (sepCsv
+>                     $ map (\(t,te)
+>                           -> parens $ sepCsv [text (T.unpack t), typeExtra te])
+>                         ts)
+> ppType (TrefType ts)
+>     = text "tref type"
+>       <> brackets (sepCsv
+>                     $ map (\((t1,t2),te)
+>                           -> parens $ sepCsv
+>                                 [parens $ sepCsv
+>                                     [text (T.unpack t1)
+>                                     ,text (T.unpack t2)]
+>                                 , typeExtra te])
+>                         ts)
+> ppType (AnonymousCompositeType ts)
+>     = text "anonymous composite type"
+>       <> brackets (sepCsv $ map ppType ts)
+> ppType (Pseudo _) = text "pseudo type"
+>
+> typeExtra:: TypeExtra -> Doc
+> typeExtra te = parens $ sepCsv
+>     [ppType (teType te)
+>     ,ppPrec "precision" (tePrecision te)
+>     ,ppPrec "scale" (teScale te)
+>     ,ppNullability (teNullable te)]
+
+> ppPrec :: String -> Maybe Int -> Doc
+> ppPrec precType prec = case prec of
+>     Nothing -> text $ "no " ++ precType
+>     Just p -> text $ precType ++ ' ':show p
+
+> ppNullability :: Bool -> Doc
+> ppNullability n = text $ (if n then "" else "not ") ++ "nullable"
+>
+> -- expressions
+>
+> scalExpr :: PrettyFlags -> ScalarExpr -> Doc
+> scalExpr flg (Parens _ e) = parens (scalExpr flg e)
+> scalExpr _ (AntiScalarExpr s) = text $ "$(" ++ s ++ ")"
+> scalExpr _ (Star _) = text "*"
+> scalExpr _ (QStar _ i) = nmc i <> text ".*"
+> scalExpr _ (Identifier _ (AntiName _)) = error "Antiname component"
+
+> scalExpr _flg (Identifier _a (Name _ is)) =
+>   hcat (punctuate (text ".") (map nmc is))
+
+
+> scalExpr _ (NumberLit _ n) = ttext n
+> scalExpr _ (StringLit _ s) = -- needs some thought about using $$?
+>                           text "'" <> ttext replaceQuotes <> text "'"
+>                           where
+>                             replaceQuotes = replace "'" "''" s
+>
+> scalExpr flg (SpecialOp _ n es) =
+>    case getTName n of
+>      Just "arrayctor" -> text "array" <> brackets (csvExp flg es)
+>      Just "between" -> scalExpr flg (head es) <+> text "between"
+>                         <+> scalExpr flg (es !! 1)
+>                         <+> text "and"
+>                         <+> scalExpr flg (es !! 2)
+>      Just "notbetween" -> scalExpr flg (head es) <+> text "not between"
+>                         <+> scalExpr flg (es !! 1)
+>                         <+> text "and"
+>                         <+> scalExpr flg (es !! 2)
+>      Just "substring" -> text "substring"
+>                      <> parens (scalExpr flg (head es)
+>                                 <+> text "from" <+> scalExpr flg (es !! 1)
+>                                 <+> text "for" <+> scalExpr flg (es !! 2))
+>      Just "arraysub" ->
+>        case es of
+>                (Identifier _ i : es1) -> name i
+>                                          <> brackets (csvExp flg es1)
+>                (e:es') -> scalExpr flg e
+>                           <> brackets (csvExp flg es')
+>                _ -> error $ "bad args to !arraysub: " ++ show es
+>      Just "rowctor" -> text "row" <> parens (sepCsvMap (scalExpr flg) es)
+>      x -> error $ "bad special operator name: " ++ show x
+
+> scalExpr flg (BinaryOp _ n e0 e1) =
+>    case getTName n of
+>      Just "and" | otherwise -> sep [scalExpr flg e0
+>                                    ,text "and"
+>                                    ,scalExpr flg e1]
+>      Just n' | Just n'' <- lookup n' [("or","or")
+>                                      ,("like","like")
+>                                      ,("rlike","rlike")
+>                                      ,("notlike","not like")] ->
+>        scalExpr flg e0
+>        <+> text n''
+>        <+> scalExpr flg e1
+>      Just "."   -- special case to avoid ws around '.'. Don't know if this is important
+>                 -- or just cosmetic
+>          -> scalExpr flg e0 <> text "." <> scalExpr flg e1
+>      Just n' -> scalExpr flg e0 <+> ttext n' <+> scalExpr flg e1
+>      Nothing -> error $ "bad binary operator name:" ++ show n
+
+> scalExpr flg (PrefixOp _ n e0)
+>   | Just "not" <- getTName n =
+>       text "not" <+> scalExpr flg e0
+>   | Just n' <- getTName n =
+>       ttext n'
+>     <+> scalExpr flg e0
+>   | otherwise = error $ "bad prefix operator name:" ++ show n
+
+
+> scalExpr flg (PostfixOp _ n e0)
+>   | Just n' <- getTName n >>= flip lookup [("isnull", "is null")
+>                                           ,("isnotnull", "is not null")] =
+>        scalExpr flg e0 <+> ttext n'
+>   | Just n' <- getTName n =
+>       scalExpr flg e0 <+> ttext n'
+>   | otherwise = error $ "bad postfix operator name:" ++ show n
+
+> scalExpr flg (App _ n es) =
+>   name n <> parens (csvExp flg es)
+
+>
+> scalExpr _ (BooleanLit _ b) = bool b
+> scalExpr flg (InPredicate _ att t lst) =
+>   scalExpr flg att <+> (if not t then text "not" else empty) <+> text "in"
+>   <+> parens (case lst of
+>                        InList _ expr -> csvExp flg expr
+>                        InQueryExpr _ sel -> queryExpr flg True True Nothing sel)
+> scalExpr flg (LiftApp _ op flav args) =
+>   scalExpr flg (head args) <+> name op
+>   <+> text (case flav of
+>               LiftAny -> "any"
+>               LiftAll -> "all")
+>   <+> parens (scalExpr flg $ head $ tail args)
+> scalExpr flg (ScalarSubQuery _ s) = parens (queryExpr flg True True Nothing s)
+> scalExpr _ (NullLit _) = text "null"
+> scalExpr flg (WindowApp _ fn part order frm) =
+>   scalExpr flg fn <+> text "over"
+>   <+> parens (if hp || ho
+>               then (if hp
+>                     then text "partition by" <+> csvExp flg part
+>                     else empty)
+>                     <+> orderBy flg order
+>                     <+> frameStuff
+>               else empty)
+>   where
+>     hp = not (null part)
+>     ho = not (null order)
+>     frameStuff = case frm of
+>         Nothing -> empty
+>         Just FrameUnboundedPreceding -> text "range unbounded preceding"
+>         Just FrameUnboundedFull -> text "range between unbounded preceding and unbounded following"
+>         Just FrameRowsUnboundedPreceding -> text "rows unbounded preceding"
+>
+> scalExpr flg (AggregateApp _ d (App _ fn es) o) =
+>   name fn <> parens ((case d of
+>                         All -> text "all"
+>                         Distinct -> text "distinct")
+>                      <+> csvExp flg es
+>                      <+> orderBy flg o)
+> scalExpr _ a@(AggregateApp {}) = error $ "bad syntax for aggregate function" ++ show a
+> scalExpr flg (Case _ whens els) =
+>   text "case"
+>   $+$ nest 2 (vcat (map whn whens)
+>               $+$ maybePrint (\e -> text "else" <+> scalExpr flg e) els)
+>   $+$ text "end"
+>       where
+>         whn (ex1, ex2) =
+>             text "when" <+> sepCsvMap (scalExpr flg) ex1
+>             <+> text "then" <+> scalExpr flg ex2
+>
+> scalExpr flg (CaseSimple _ val whens els) =
+>   text "case" <+> scalExpr flg val
+>   $+$ nest 2 (vcat (map whn whens)
+>               $+$ maybePrint (\e -> text "else" <+> scalExpr flg e) els)
+>   $+$ text "end"
+>       where
+>         whn (ex1, ex2) =
+>             text "when" <+> sepCsvMap (scalExpr flg) ex1
+>             <+> text "then" <+> scalExpr flg ex2
+>
+> scalExpr _ (PositionalArg _ a) = text "$" <> integer a
+> scalExpr _ (Placeholder _) = text "?"
+> scalExpr flg (Exists _ s) =
+>   text "exists" <+> parens (queryExpr flg True True Nothing s)
+> scalExpr flg (Cast _ ex t) = text "cast" <> parens (scalExpr flg ex
+>                                              <+> text "as"
+>                                              <+> typeName t)
+> scalExpr flg (ImplicitCast _ ex te) = text "impl_cast" <> parens (scalExpr flg ex
+>                                              <+> text "as"
+>                                              <+> typeExtra te)
+> scalExpr flg (TypedStringLit a t s) =
+>   typeName t <+> scalExpr flg (StringLit a s)
+> scalExpr flg (Interval a v f p) =
+>   text "interval" <+> scalExpr flg (StringLit a v)
+>   <+> intervalField <+> precision
+>   where
+>     intervalField =
+>       text $ case f of
+>                     IntervalYear -> "year"
+>                     IntervalMonth -> "month"
+>                     IntervalDay -> "day"
+>                     IntervalHour -> "hour"
+>                     IntervalMinute -> "minute"
+>                     IntervalSecond -> "second"
+>                     IntervalYearToMonth -> "year to month"
+>                     IntervalDayToHour -> "day to hour"
+>                     IntervalDayToMinute -> "day to minute"
+>                     IntervalDayToSecond -> "day to second"
+>                     IntervalHourToMinute -> "hour to minute"
+>                     IntervalHourToSecond -> "hour to second"
+>                     IntervalMinuteToSecond -> "minute to second"
+>     precision = case p of
+>                  Nothing -> empty
+>                  Just i -> parens (int i)
+> scalExpr flg (Extract _ f e) =
+>   text "extract"
+>   <> parens (text field <+> text "from" <+> scalExpr flg e)
+>   where
+>     field =
+>       case f of
+>              ExtractCentury -> "century"
+>              ExtractDay -> "day"
+>              ExtractDecade -> "decade"
+>              ExtractDow -> "dow"
+>              ExtractDoy -> "doy"
+>              ExtractEpoch -> "epoch"
+>              ExtractHour -> "hour"
+>              ExtractIsodow -> "isodow"
+>              ExtractIsoyear -> "isoyear"
+>              ExtractMicroseconds -> "microseconds"
+>              ExtractMillennium -> "millennium"
+>              ExtractMilliseconds -> "milliseconds"
+>              ExtractMinute -> "minute"
+>              ExtractMonth -> "month"
+>              ExtractQuarter -> "quarter"
+>              ExtractSecond -> "second"
+>              ExtractTimezone -> "timezone"
+>              ExtractTimezoneHour -> "timezone_hour"
+>              ExtractTimezoneMinute -> "timezone_minute"
+>              ExtractWeek -> "week"
+>              ExtractYear -> "year"
+
+> scalExpr _flg (OdbcLiteral _ t s) =
+>     text "{" <> lt t <+> quotes (text s) <> text "}"
+>   where
+>     lt OLDate = "d"
+>     lt OLTime = "t"
+>     lt OLTimestamp = "ts"
+
+> scalExpr flg (OdbcFunc _ e) =
+>     text "{fn" <+> scalExpr flg e <> text "}"
+
+
+> scalExprSl :: PrettyFlags ->  ScalarExpr -> Doc
+> scalExprSl flg (App _ f es) | Just "." <- getTName f
+>                                 , [a@(Identifier _ _), b] <- es =
+>   scalExprSl flg a <> text "." <> scalExprSl flg b
+> scalExprSl flg x = scalExpr flg x
+
+>
+> set :: PrettyFlags -> SetClause -> Doc
+> set flg (SetClause _ a e) =
+>   nmc a <+> text "=" <+> scalExpr flg e
+> set flg (MultiSetClause _ is (SpecialOp _ f es)) | Just "rowctor" <- getTName f =
+>   parens (sepCsvMap nmc is) <+> text "="
+>   <+> parens (sepCsvMap (scalExpr flg) es)
+> set _ a = error $ "bad expression in set in update: " ++ show a
+>
+> --utils
+>
+> -- convert a list of expressions to horizontal csv
+>
+> csvExp :: PrettyFlags -> [ScalarExpr] -> Doc
+> csvExp flg = hcatCsvMap (scalExpr flg)
+>
+> maybePrint :: (t -> Doc) -> Maybe t -> Doc
+> maybePrint f c =
+>     case c of
+>       Nothing -> empty
+>       Just a -> f a
+>
+> csv :: [Doc] -> [Doc]
+> csv = punctuate comma
+>
+> hcatCsv :: [Doc] -> Doc
+> hcatCsv = hcat . csv
+
+> sepCsv :: [Doc] -> Doc
+> sepCsv = sep . csv
+>
+> ifNotEmpty :: ([a] -> Doc) -> [a] -> Doc
+> ifNotEmpty c l = if null l then empty else c l
+>
+> hcatCsvMap :: (a -> Doc) -> [a] -> Doc
+> hcatCsvMap ex = hcatCsv . map ex
+
+> sepCsvMap :: (a -> Doc) -> [a] -> Doc
+> sepCsvMap ex = sepCsv . map ex
+
+> orderBy :: PrettyFlags -> [(ScalarExpr,Direction,NullsOrder)] -> Doc
+> orderBy _ [] = empty
+> orderBy flg os =
+>   text "order by"
+>   $+$ nest 2 (sepCsvMap (\(oe,od,on) -> scalExpr flg oe
+>                                      <+> direction od <+> nullsOrder on) os)
+
+> --vcatCsvMap :: (a -> Doc) -> [a] -> Doc
+> --vcatCsvMap ex = vcat . csv . map ex
+
+>
+> bool :: Bool -> Doc
+> bool b = if b then text "true" else text "false"
+>
+> newline :: Doc
+> newline = text "\n"
+>
+> annot :: (Annotation -> String) -> Annotation -> Doc
+> annot ca a = let s = ca a
+>               in if s == ""
+>                    then empty
+>                    else text "/*\n" <+> text s
+>                         <+> text "*/\n"
+
+> label :: Maybe String -> Doc
+> label =
+>   maybe empty (\l -> text "<<"
+>                      <+> text l
+>                      <+> text ">>" <> text "\n")
+
+util: to be removed when outputting names is fixed
+
+> getTName :: Name -> Maybe String
+> getTName (Name _ [n]) = Just $ ncStr n
+> getTName _ = Nothing
+
+> ttext :: String -> Doc
+> ttext = text
+
+> tltext :: String -> Doc
+> tltext = text
diff --git a/src/Database/HsSqlPpp/Internals/TypeChecking/Environment.lhs b/src/Database/HsSqlPpp/Internals/TypeChecking/Environment.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/TypeChecking/Environment.lhs
@@ -0,0 +1,427 @@
+
+
+This module represents part of the bound names environment used in the
+type checker. It doesn't cover the stuff that is contained in the
+catalog (so it is slightly misnamed), but focuses only on identifiers
+introduced by things like tablerefs, sub selects, plpgsql parameters
+and variables, etc.
+
+> {-# LANGUAGE DeriveDataTypeable,TupleSections,ScopedTypeVariables,OverloadedStrings #-}
+> module Database.HsSqlPpp.Internals.TypeChecking.Environment
+>     (-- * abstract environment value
+>      Environment
+>     ,JoinType(..)
+>      -- * environment create and update functions
+>     ,emptyEnvironment
+>     ,isEmptyEnv
+>     ,envCreateTrefEnvironment
+>     ,createJoinTrefEnvironment
+>     ,envSelectListEnvironment
+>     ,createCorrelatedSubqueryEnvironment
+>     ,createTrefAliasedEnvironment
+>     ,brokeEnvironment
+>     ,orderByEnvironment
+>      -- * environment query functions
+>     ,envLookupIdentifier
+>     ,envExpandStar
+>     ) where
+
+> import Data.Data
+> import Data.Char
+> --import Data.Maybe
+> import Control.Monad
+> import Control.Arrow
+> import Data.List
+> --import Debug.Trace
+> --import Text.Show.Pretty
+
+> import Database.HsSqlPpp.Internals.TypesInternal
+> import Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.TypeConversion
+> import Database.HsSqlPpp.Internals.Catalog.CatalogInternal
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes hiding (ncStr)
+> import Data.Generics.Uniplate.Data
+> import Data.Text (Text)
+> import qualified Data.Text as T
+
+---------------------------------
+
+Alex:
+  Not sure that handling of USING joins (and specifically of join keys) is correct, but
+    don't know, have to investigate all the connections in the code.
+  One problem is that types for the purpose of comparison are different from the output types.
+  Moreover, major DBs are imprecise in their definitions of USING joins.
+    For instance, what Postgre writes about output columns seems to be related only to the
+      star expansion. I still can explicitly reference a key column from the inner table
+      in the output expression, with the use of table name or alias. Or can I not?
+    Have to look at ANSI.
+  More precisely, we have:
+    1. Type check join keys to see that they are compatible.
+    2. If needed, create additional columns that would exist for the purpose of comparison
+        only. The scalar expressions that create them are casts from join keys.
+    3. If a join key is used in an output scalar expression, the original' key type is used.
+  For a qualified column reference, including qualified star expansion, original' type
+    is same as original type, except that it is possibly cast to nullable for an inner table
+    of an outer join.
+  For star expansion:
+    The original' type is defined strictly for LeftOuter and RightOuter.
+    It is unclear what to do in case of Inner and FullOuter if the types differ (but, as we
+      already know, are compatible).
+    There are two choices:
+      1. Reject the query.
+      2. Resolve the types and return the result type.
+  For now, I'll do the 2nd thing, let's see what happens.
+    And I don't implement the rest of this plan either, of course:
+      - I convert things to nullable for outer joins, but don't separate between
+        condition columns and output columns, of course;
+      - For Right Outer Joins, I reverse the order of input environments in listBindingsTypes,
+        for the purpose of getting the key types.
+    And now I see that TypeExtra's in join ids are not actually used.
+
+> -- | Represent an environment using an abstracted version of the syntax
+> -- which produced the environment. This structure has all the catalog
+> -- queries resolved. No attempt is made to combine environment parts from
+> -- different sources, they are just stacked together, the logic for
+> -- working with combined environments is in the query functions below
+> data Environment =
+>                  -- | represents an empty environment, makes e.g. joining
+>                  -- the environments for a list of trefs in a select list
+>                  -- more straightforward
+>                    EmptyEnvironment
+>                  -- | represents the bindings introduced by a tableref:
+>                  -- the name, the public fields, the private fields
+>                  | SimpleTref (Text,Text) [(Text,TypeExtra)] [(Text,TypeExtra)]
+>                  -- | environment from joining two tables
+>                  | JoinTref [(Text,TypeExtra)] -- join ids
+>                             JoinType  -- added because outer join makes some things nullabie
+>                             Environment Environment
+>                  -- | environment from a sub select
+>                  | SelectListEnv [(Text,TypeExtra)]
+>                    -- | correlated subquery environment
+>                  | CSQEnv Environment -- outerenv
+>                           Environment -- main env
+>                    -- | an aliased tref
+>                  | TrefAlias Text (Maybe [Text]) Environment
+>                  | BrokeEnvironment
+>                    -- order by: can use the name of a select list column
+>                    -- or anything from the same environment which select
+>                    -- list operates on
+>                  | OrderByEnvironment Environment Environment
+>                    deriving (Data,Typeable,Show,Eq)
+>
+> data JoinType = Inner | LeftOuter | RightOuter | FullOuter
+>                    deriving (Data,Typeable,Show,Eq)
+
+---------------------------------------------------
+
+Create/ update functions, these are shortcuts to create environment variables,
+the main purpose is to encapsulate looking up information in the
+catalog and combining environment values with updates
+
+TODO: remove the create prefixes
+
+> emptyEnvironment :: Environment
+> emptyEnvironment = EmptyEnvironment
+
+> isEmptyEnv :: Environment -> Bool
+> isEmptyEnv EmptyEnvironment = True
+> isEmptyEnv _ = False
+
+> envCreateTrefEnvironment :: Catalog -> [NameComponent] -> Either [TypeError] Environment
+> envCreateTrefEnvironment cat tbnm = do
+>   (nm,pub,prv) <- catLookupTableAndAttrs cat tbnm
+>   return $ SimpleTref nm pub (second mkTypeExtraNN `map` prv)
+
+> envSelectListEnvironment :: [(Text,TypeExtra)] -> Either [TypeError] Environment
+> envSelectListEnvironment cols =
+>   return $ SelectListEnv $ map (first $ T.map toLower) cols
+
+
+> -- | create an environment as two envs joined together
+> createJoinTrefEnvironment :: Catalog
+>                           -> Environment
+>                           -> Environment
+>                           -> JoinType
+>                           -> Maybe [NameComponent] -- join ids: empty if cross join
+>                                                    -- nothing for natural join
+>                           -> Either [TypeError] Environment
+> createJoinTrefEnvironment cat tref0 tref1 jt jsc = do
+>   -- todo: handle natural join case
+>   (jids::[Text]) <- case jsc of
+>             Nothing -> do
+>                        j0 <- fmap (map (snd . fst)) $ envExpandStar Nothing tref0
+>                        j1 <- fmap (map (snd . fst)) $ envExpandStar Nothing tref1
+>                        return $ j0 `intersect` j1
+>             Just x -> return $ map nmcString x
+
+>  --         maybe (error "natural join ids") (map (nnm . (:[]))) jsc
+
+>   jts <- forM jids $ \i -> do
+>            (_,t0) <- envLookupIdentifier [QNmc $ T.unpack i] tref0
+>            (_,t1) <- envLookupIdentifier [QNmc $ T.unpack i] tref1
+>            let  adjustTypeExtra te = case jt of
+>                     Inner -> te
+>                     LeftOuter -> t0
+>                     RightOuter -> t1
+>                     FullOuter -> mkNullable te
+>            fmap ((i,) . adjustTypeExtra) $ resolveResultSetTypeExtra cat [t0,t1]
+>            -- ImplicitCastToDo: remove or restore
+>            --fmap (i,) $ resolveResultSetTypeExtra cat [t0,t1]
+>   -- todo: check type compatibility
+>   return $ JoinTref jts jt tref0 tref1
+
+> createCorrelatedSubqueryEnvironment :: Environment -> Environment -> Environment
+> createCorrelatedSubqueryEnvironment = CSQEnv
+
+> createTrefAliasedEnvironment :: Text -> Maybe [Text] -> Environment -> Environment
+> createTrefAliasedEnvironment = TrefAlias
+
+> -- | represents type check failure upstream, don't produce additional
+> -- type check errors
+> brokeEnvironment :: Environment
+> brokeEnvironment = BrokeEnvironment
+
+> isBroken :: Environment -> Bool
+> isBroken env = not $ null [() | BrokeEnvironment <- universeBi env]
+
+> orderByEnvironment :: Environment -> Environment -> Environment
+> orderByEnvironment = OrderByEnvironment
+
+-------------------------------------------------------
+
+
+The main hard work is done in the query functions: so the idea is that
+the update functions create environment values which contain the
+context free contributions of each part of the ast to the current
+environment, and these query functions do all the work of resolving
+implicit correlation names, ambigous identifiers, etc.
+
+for each environment type, provide two functions which do identifier
+lookup and star expansion
+
+> listBindingsTypes :: Environment -> ((Maybe Text,Text) -> [((Text,Text),TypeExtra)]
+>                                     ,Maybe Text -> [((Text,Text),TypeExtra)] -- star expand
+>                                     )
+> listBindingsTypes EmptyEnvironment = (const [],const [])
+> listBindingsTypes BrokeEnvironment = (const [],const [])
+
+> listBindingsTypes (TrefAlias ta Nothing env) =
+>   (\(q,n) -> if q `elem` [Nothing, Just ta]
+>              then req $ fst (listBindingsTypes env) (Nothing,n)
+>              else []
+>   ,\q -> if q `elem` [Nothing, Just ta]
+>          then req $ snd (listBindingsTypes env) Nothing
+>          else [])
+>   where
+>     req = map (\((_,i),t) -> ((ta,i),t))
+
+> listBindingsTypes (TrefAlias ta (Just cs) env) =
+>   (\(q,n) -> --trace ("lookup: " ++ show (q,n)) $
+>      if q `elem` [Nothing, Just ta]
+>      then    --really hacky, assume the ids come out of the star expansion in same order
+>              -- almost certainly wrong some of the time
+>              case elemIndex n cs of
+>                Just i -> let s :: [((Text, Text), TypeExtra)]
+>                              s = (snd (listBindingsTypes env) Nothing)
+>                          in {-trace ("getit : " ++ show (i,show s))
+>                                      $ -}
+>                             -- map to change the qualifier name to match
+>                             -- this alias not the source tref
+>                             map (\((_,_j),t) -> ((ta,n),t)) $ take 1 $ drop i s
+>                Nothing -> []
+>      else []
+>   ,\q -> if q `elem` [Nothing, Just ta]
+>          then let -- if there are too many aliases for the aliased tref
+>                   -- the extras are ignored (not sure if this is correct)
+>                   -- if there are not enough, the extras are kept without
+>                   -- being renamed (think this is correct)
+>                   repColNames = map Just cs ++ repeat Nothing
+>                   aliasize :: [((Text, Text), TypeExtra)] -> [((Text, Text), TypeExtra)]
+>                   aliasize =
+>                     flip zipWith repColNames (\r ((_,n),t) ->
+>                              case r of
+>                                Just r' -> ((ta,r'),t)
+>                                Nothing -> ((ta,n),t))
+>               in aliasize $ snd (listBindingsTypes env) Nothing
+>          else [])
+>   where
+>     -- not sure why this is here, code layout is a bit confusing
+>     _req = map (\((_,i),t) -> ((ta,i),t))
+
+
+FIXME!!! (_,nm) ?
+
+> listBindingsTypes (SimpleTref (_,nm) pus pvs) =
+>   (\(q,n) -> let m (n',_) = (q `elem` [Nothing,Just nm])
+>                             && n == n'
+>              in addQual nm $ filter m $ pus ++ pvs
+>   ,\q -> case () of
+>            _ | q `elem` [Nothing, Just nm] -> addQual nm pus
+>              | otherwise -> [])
+
+> listBindingsTypes (JoinTref jids jt env0 env1) =
+>   (idens,starexp)
+>   where
+
+>     idens k = let [iOuter,iInner] = (if jt==RightOuter then reverse else id) [is0 k, is1 k]
+>               in if not (null iOuter) && snd k `elem` jnames
+>                  then iOuter
+>                  else iOuter ++ iInner
+
+>     _useResolvedType tr@((q,n),_) = case lookup n jids of
+>                                    Just t' -> ((q,n),t')
+>                                    Nothing -> tr
+>     jnames = map fst jids
+>     isJ ((_,n),_) = n `elem` jnames
+
+todo: use useResolvedType
+
+unqualified star:
+reorder the ids so that the join columns are first
+
+>     starexp Nothing = let (aj,anj) = partition isJ (st0 Nothing)
+>                           bnj = filter (not . isJ) (st1 Nothing)
+>                       in aj ++ anj ++ bnj
+>     starexp q@(Just _) =
+>       let s0 = st0 q
+>           s1 = st1 q
+>       in case (s0,s1) of
+>            -- if we only get ids from one side, then don't
+>            -- reorder them (is this right?)
+>            (_:_,[]) -> s0
+>            ([], _:_) -> s1
+>            -- have ids coming from both sides
+>            -- no idea how this is supposed to work
+>            _ -> let (aj,anj) = partition isJ s0
+>                     bnj = filter (not . isJ) s1
+>                 in aj ++ anj ++ bnj
+>     (is0,st0) = (if jt `elem` [RightOuter,FullOuter] then addNullability else id)
+>                 $ listBindingsTypes env0
+>     (is1,st1) = (if jt `elem` [LeftOuter,FullOuter] then addNullability else id)
+>                 $ listBindingsTypes env1
+>     addNullability = (map (second mkNullable) .) *** (map (second mkNullable) .)
+
+selectlistenv: not quite right, but should always have an alias so the
+empty qualifier never gets very far
+
+> listBindingsTypes (SelectListEnv is) =
+>   (\(_,n) -> addQual "" $ filter ((==n).fst) is
+>   ,const $ addQual "" is)
+
+not quite right, see queryexprs.ag
+
+> listBindingsTypes (OrderByEnvironment sl tr) =
+>   (\i ->
+>      -- hack: return the tref first so that
+>      -- a qualifier can be added. This
+>      -- is probably more wrong than the other
+>      -- way round
+>      case (fst (listBindingsTypes tr) i
+>           ,fst (listBindingsTypes sl) i) of
+>        ([],x) -> x
+>        (y,_) -> y
+>   ,const [])
+
+
+csq just uses standard shadowing for iden lookup
+for star expand, the outer env is ignored
+
+> listBindingsTypes (CSQEnv outerenv env) =
+>   (\k -> case (fst (listBindingsTypes env) k
+>               ,fst (listBindingsTypes outerenv) k) of
+>            (x,_) | not (null x) -> x
+>            (_, x) | not (null x)  -> x
+>            _ -> []
+>   ,snd $ listBindingsTypes env)
+
+
+> addQual :: Text -> [(Text,TypeExtra)] -> [((Text,Text),TypeExtra)]
+> addQual q = map (\(n,t) -> ((q,n),t))
+
+
+-------------------------------------------------------
+
+use listBindingsTypes to implement expandstar and lookupid
+
+> envExpandStar:: Maybe NameComponent -> Environment
+>                 -> Either [TypeError] [((Text,Text),TypeExtra)]
+
+> envExpandStar {-nmc env-} = {-let r =-} envExpandStar2 {-nmc env-}
+>                         {-in trace ("env expand star: " ++ show nmc ++ " " ++ show r)
+>                            r-}
+
+> envExpandStar2 :: Maybe NameComponent -> Environment -> Either [TypeError] [((Text,Text),TypeExtra)]
+> envExpandStar2 nmc env =
+>   if isBroken env
+>   then Left []
+>   else
+>     let st = snd (listBindingsTypes env) $ fmap nmcString nmc
+>     in if null st
+>        then case nmc of
+>               Just x -> Left [UnrecognisedCorrelationName $ nmcString x]
+>               Nothing -> Left [BadStarExpand]
+>        else Right st
+
+> nmcString :: NameComponent -> Text
+> nmcString (QNmc n) = T.pack n
+> nmcString (Nmc n) = T.pack $ map toLower n
+> -- todo: don't use error
+> nmcString (AntiNameComponent _) = error "tried to get ncstr of antinamecomponent"
+
+> envLookupIdentifier :: [NameComponent] -> Environment
+>                      -> Either [TypeError] ((Text,Text), TypeExtra)
+> envLookupIdentifier nmc env = --trace ("lookup: " ++ show nmc  ++ "\n" ++ ppShow env) $
+>   if isBroken env
+>   then Left []
+>   else do
+>     k <- case nmc of
+>                [a,b] -> Right (Just $ nmcString a, nmcString b)
+>                [b] -> Right (Nothing, nmcString b)
+>                [_,_,_] -> Left [SchemadColumnName "an identifier cannot be used with an explicit schema name, please use only a correlation name without a schema name (you can use a table reference alias to disambiguate if you need to)."]
+>                [_,_,_,_] -> Left [DbSchemadColumnName "an identifier cannot be used with an explicit database name and schema name, please use only a correlation name without a schema name (you can use a table reference alias to disambiguate if you need to)."]
+>                _ -> Left [InternalError "too many nmc components in envlookupiden"]
+>     case (fst $ listBindingsTypes env) k of
+>       [] -> Left [UnrecognisedIdentifier $ nmcString $ last nmc]
+>       [x] -> Right $ keepCasehack x
+>       _ -> Left [AmbiguousIdentifier $ nmcString $ last nmc]
+>   where
+>     keepCasehack ((na,nb),t) =
+>       case nmc of
+>         [a,b] -> let x = ((keepcase a na,keepcase b nb),t)
+>                  in {-(if True -- map toLower nb == "ou_id"
+>                      then trace ("\n\n*********************\n\nlookup: " ++ show x ++ "\n\n********************************\n\n" ++ ppShow env ++ "\n\n********************************\n\n")
+>                      else id)-} x
+>         [b] -> ((na,keepcase b nb),t)
+>         _ -> error "too many nmc components in envlookupiden(2)"
+>     keepcase orig new = -- sanity check: make sure the nmcs are equal
+>                         if T.map toLower new == nmcString orig
+>                         then noLower orig
+>                         else new
+>     noLower (QNmc n) = T.pack n
+>     noLower (Nmc n) = T.pack n
+>     noLower (AntiNameComponent n) = error $ "bad antinamecomponent in Environment.envLookupIdentifier.noLower " ++ n
+
+--------------------------
+adding for plpgsql notes:
+
+additional envs
+* parameter in function
+* declaration in function block
+* implicit integer loop var in for loop
+* set explicit record type in for loop/ assignment to record type
+* for constraints in create table, create domain
+
+Write tests to quickly check each bit of code which uses these using
+the full typechecking:
+update: sets, where, returning
+select: tref -> select list, where, group by, order by
+join: out to tref, into on expression
+implicit variable in for loop
+record type in for loop
+record type in assignment
+record type in select into
+delete where and returning
+block declarations
+constraints in create table, create domain
+parameters in function body
+statementlist: pass on record updates?
+insert: columns?, returning
diff --git a/src/Database/HsSqlPpp/Internals/TypeChecking/ErrorUtils.lhs b/src/Database/HsSqlPpp/Internals/TypeChecking/ErrorUtils.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Internals/TypeChecking/ErrorUtils.lhs
+++ /dev/null
@@ -1,30 +0,0 @@
-
-This file contains a bunch of small low level utilities to help with
-type checking.
-
-> module Database.HsSqlPpp.Internals.TypeChecking.ErrorUtils
->     where
->
-> import Database.HsSqlPpp.Internals.TypeType
-> import Debug.Trace
-
-> type E a = Either [TypeError] a
-> type Et = E Type
->
-> lmt :: Maybe a -> E a
-> lmt = maybe (Left []) Right
->
-> tes :: E a -> [TypeError]
-> tes = either id (const [])
->
-> etmt :: E a -> Maybe a
-> etmt = either (const Nothing) Just
->
-
-> liftList :: [(a,Maybe b)] -> Maybe [(a,b)]
-> liftList is = sequence $ flip map is $ \(a,b) -> case b of
->                                                    Just b' -> Just (a,b')
->                                                    Nothing -> Nothing
-
-> showIt :: Show a => String -> a -> a
-> showIt m a = trace (m ++ " " ++ show a) a
diff --git a/src/Database/HsSqlPpp/Internals/TypeChecking/IDEnv.lhs b/src/Database/HsSqlPpp/Internals/TypeChecking/IDEnv.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Internals/TypeChecking/IDEnv.lhs
+++ /dev/null
@@ -1,148 +0,0 @@
-
-code to resolve the qualifier of an identifier and expand stars and
-some helpers to get ids for a table, and help with aliases
-
-this should eventually expand to take over the local identifier
-bindings code
-
-> {-# LANGUAGE TupleSections #-}
-> module Database.HsSqlPpp.Internals.TypeChecking.IDEnv
->     (IDEnv(..)
->     ,emptyIDEnv
->     ,qualifyID
->     ,expandStar) where
-
-> import Data.List
-> --import Debug.Trace
-> import Control.Monad
-> import Data.Maybe
-
-> data IDEnv =
-
-table name, public ids, private ids aliases already folded in
-used for tref and subtref
-
->                TrefIDEnv String [String] [String]
-
->              | FunTrefIDEnv String
->              | CompFunTrefIDEnv String [String]
-
-first element is the alias, used for joins
-
->              | JoinTrefIDEnv [String] -- join ids for natural/using equijoins
->                   IDEnv IDEnv
->              | EmptyIDEnv String
->              | TableAliasIDEnv String IDEnv
->              | FullAliasIDEnv String [String] IDEnv
->              | CorrelatedIDEnv IDEnv IDEnv -- normal env, extra correlated env
->                deriving Show
-
-> emptyIDEnv :: String -> IDEnv
-> emptyIDEnv = EmptyIDEnv
-
-> qualifyID :: IDEnv -> String -> Maybe (String,String)
-> qualifyID idenv s =
->   {-(if s == "c"
->    then showit ("qualifyID " ++ show idenv ++ " " ++ show s ++ ": ")
->    else id) $ -} qualifyID' idenv s
-> qualifyID' :: IDEnv -> String -> Maybe (String,String)
-> qualifyID' (CorrelatedIDEnv ids cids) i =
->    msum [qualifyID ids i, qualifyID cids i]
-> qualifyID' (TrefIDEnv s pus pvs) i = if i `elem` pus || i `elem` pvs
->                                   then Just (s,i)
->                                   else Nothing
-> qualifyID' (FunTrefIDEnv f) i = if f == i
->                                 then Just (f,i)
->                                 else Nothing
-> qualifyID' (CompFunTrefIDEnv f cs) i = case () of
->                                       _ | i `elem` cs -> Just (f,i)
->                                         | i == f -> Nothing --slighly hacky, this should be left alone
->                                         | otherwise -> Nothing
-> qualifyID' (JoinTrefIDEnv js t0 t1) i =
->   case (qualifyID t0 i,qualifyID t1 i) of
->     (Just q, _) | i `elem` js -> Just q
->     (Just q, Nothing) -> Just q
->     (Nothing, Just q) -> Just q
->     _ -> Nothing
-
-> qualifyID' (EmptyIDEnv _) _ = Nothing -- error $ "qualify: " ++ show x ++ " " ++ show y
-
-private ids. When can a private column be referenced without a
-qualifying name?
-a straight tref env
-in a join when the private column is joined on? FIXME
-in an aliased trefenv
-
-> -- special cases for aliased private ids
-
-> qualifyID' (TableAliasIDEnv t (TrefIDEnv _ _ pvs)) i | i `elem` pvs = Just (t,i)
-> qualifyID' (FullAliasIDEnv t _ (TrefIDEnv _ _ pvs)) i | i `elem` pvs = Just (t,i)
-
-special case for aliased funtrefs
-
-> qualifyID' (TableAliasIDEnv t (FunTrefIDEnv _)) i =
->   if t == i
->   then Just (t,t)
->   else Nothing
-
-
-> qualifyID' (FullAliasIDEnv t cs _) i | i `elem` cs = Just (t,i)
->                                   | otherwise = Nothing
-
-> qualifyID' (TableAliasIDEnv t ids) i =
->   fmap (\x -> (t,snd x)) $ qualifyID ids i
-
-> --showit :: Show a => String -> a -> a
-> --showit a t = trace (a ++ show t ++ "\n\n") t
-
-> expandStar :: IDEnv -> Maybe String -> Maybe [(String,String)]
-> expandStar i s = {-showit ("expandStar: " ++ show i ++ "\n" ++ show s ++ "\n\n")
->                  $ showit "esresult: " $ -} expandStar' i s
-
-> expandStar' :: IDEnv -> Maybe String -> Maybe [(String,String)]
-> expandStar' (CorrelatedIDEnv ids _) i = expandStar ids i
-> expandStar' (TrefIDEnv s pus _) Nothing = Just $ zip (repeat s) pus
-> expandStar' (TrefIDEnv s pus _) (Just s1) | s == s1 = Just $ zip (repeat s) pus
->                                         | otherwise = Nothing
-> expandStar' (CompFunTrefIDEnv f cs) Nothing = Just $ zip (repeat f) cs
-> expandStar' (CompFunTrefIDEnv f cs) (Just f1) | f == f1 = Just $ zip (repeat f) cs
->                                               | otherwise = Nothing
-> expandStar' (FunTrefIDEnv f) Nothing = Just [(f,f)]
-> expandStar' (FunTrefIDEnv f) (Just f1) | f == f1 = Just [(f,f)]
->                                        | otherwise = Nothing
-
-special case for a table alias on a non table valued funtref
-
-> expandStar' (TableAliasIDEnv t (FunTrefIDEnv _)) Nothing = Just [(t,t)]
-> expandStar' (TableAliasIDEnv t (FunTrefIDEnv _)) (Just f1)
->     | t == f1 = Just [(t,t)]
->     | otherwise = Nothing
-
-
-
-> expandStar' (JoinTrefIDEnv js t0 t1) Nothing =
->   let isJ = (`elem` js) . snd
->       (jis,t0is) = partition isJ $ fromMaybe [] (expandStar t0 Nothing)
->              -- remove join columns from second list
->       t1is = filter (not . isJ) $ fromMaybe [] (expandStar t1 Nothing)
->   in case jis ++ t0is ++ t1is of -- check for duplicates?
->     [] -> Nothing
->     x -> Just x
-
-expand actual alias, assume that there is no overlap so don't have to eliminate js
-
-> expandStar' (JoinTrefIDEnv _js t0 t1) i =
->   let t0is = fromMaybe [] (expandStar t0 i)
->       t1is = fromMaybe [] (expandStar t1 i)
->   in case t0is ++ t1is of -- check for duplicates?
->     [] -> Nothing
->     x -> Just x
-
-> expandStar' (TableAliasIDEnv t ids) i
->     | maybe True (==t) i = fmap (map (\x -> (t,snd x))) $ expandStar ids Nothing
->     | otherwise = Nothing
-> expandStar' (FullAliasIDEnv t cs _) i
->     | maybe True (==t) i = Just $ map (t,) cs
->     | otherwise = Nothing
-
-> expandStar' (EmptyIDEnv _) _ = Nothing
diff --git a/src/Database/HsSqlPpp/Internals/TypeChecking/LocalBindings.lhs b/src/Database/HsSqlPpp/Internals/TypeChecking/LocalBindings.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Internals/TypeChecking/LocalBindings.lhs
+++ /dev/null
@@ -1,66 +0,0 @@
-
-Forwarder for the interface to LocalBindingsInternal used by the rest
-of the system.
-
-> module Database.HsSqlPpp.Internals.TypeChecking.LocalBindings
->     (
->      LocalBindingsUpdate(..)
->     ,LocalBindings
->     ,emptyBindings
->     ,lbUpdate
->     ,lbLookupID
->     ,lbLookupIDInType
->     ,ppLocalBindings
->     ,createLocalBindings
->     ,getUnqualifiedBindings
->     ,joinBindings
->     ,lookupLocalBinding
->     ) where
-
-> --import Control.Monad
->
-> import Database.HsSqlPpp.Internals.TypeChecking.LocalBindingsInternal
-> --import Database.HsSqlPpp.Internals.TypeType
-> --import Database.HsSqlPpp.Internals.TypeChecking.ErrorUtils
-
-
-> {-data LocalEnv =
->         TrefEnv String [(String,Type)] [(String,Type)]
->       | FunTrefEnv String Type
->       | CompFunTrefEnv String [(String, Type)]
->       | JoinTrefEnv [String] LocalEnv LocalEnv
->       | EmptyEnv
->       | TableAliasEnv String LocalEnv
->       | FullAliasEnv String [String] LocalEnv
->       | CorrelatedEnv LocalEnv LocalEnv
->         deriving Show
-
-
-> lookupID :: LocalEnv -> Maybe String -> String -> E (Maybe Type)
-> lookupID (TrefEnv _t _pus _pvs) Nothing _i = Right Nothing
-> lookupID (TrefEnv t pus pvs) (Just q) i
->    | t == q =
->      Right $ msum [lookup i pus, lookup i pvs]
->    | otherwise = Right Nothing
-
-> lookupID (FunTrefEnv _f _) Nothing _i = Right Nothing
-> lookupID (FunTrefEnv f t) (Just q) i | q == f && i == f = Right $ Just t
->                                      | otherwise = Right Nothing
-
-> lookupID (JoinTrefEnv js e0 e1) Nothing _ = Right Nothing
-> lookupID (JoinTrefEnv js e0 e1) (Just q) i
->     -- if this is a join id, just lookup in e0
->    | i `elem` js
->    , t@(Right (Just _)) <- lookupe0 = t
->    -- otherwise require to be in either e0 or e1 but not both
->    | t@(Right (Just _)) <- lookupe0
->    , Nothing <- lookupe1 = t
->    | Nothing <- lookupe0
->    , t@(Right (Just _)) <- lookupe1 = t
->    | Right (Just _) <- lookupe0
->    , Right (Just _) <- lookupe1 = Left $ AmbiguousIdentifier i
->    | Nothing <- lookupe0
->    , Nothing <- lookupe1 = Left $ UnrecognisedIdentifier i
->    where
->      lookupe0 = lookupID e0 (Just q) i
->      lookupe1 = lookupID e1 (Just q) i-}
diff --git a/src/Database/HsSqlPpp/Internals/TypeChecking/LocalBindingsInternal.lhs b/src/Database/HsSqlPpp/Internals/TypeChecking/LocalBindingsInternal.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Internals/TypeChecking/LocalBindingsInternal.lhs
+++ /dev/null
@@ -1,744 +0,0 @@
-
-This module contains the code to manage local identifier bindings
-during the type checking process. This is used for e.g. looking up the
-types of parameter and variable references in plpgsql functions, and
-for looking up the types of identifiers in select expressions.
-
-This module exposes the internals of the localbindings datatype for
-testing.
-
-The lookups to support are a single identifier, or to give a star
-expansion.
-
-
-Some notes on lookups
-all lookups are case insensitive
-start by searching the head of the lookup update list and working down
-the code here handles resolving the types of join columns when they
-are not the same, and the update routine returns error if the join columns are not compatible
-the code here handles expanding record types so that the components can be looked up
-
-The local bindings is arranged as a stack. To append to this stack,
-you use the LocalBindingsUpdate type. This is designed to be as easy as
-possible for clients to use, so as much logic as possible is pushed
-into the innards of this module, in particular most of the logic for
-working with joins is in here.
-
-The basic idea of the stack is at each level, there is a list of
-qualified and unqualified names and types, to look up individual
-ids. Some of the lookups map to ambiguous identifier errors. Also at
-each level is a list of star expansions, one for each correlation name
-in scope, and one for an unqualified star.
-
-> {-# LANGUAGE ScopedTypeVariables,TupleSections #-}
->
-> module Database.HsSqlPpp.Internals.TypeChecking.LocalBindingsInternal
->     (
->      LocalBindingsUpdate(..)
->     ,LocalBindings(..)
->     ,Source
->     ,FullId
->     ,SimpleId
->     ,IDLookup
->     -- ,StarExpand
->     ,LocalBindingsLookup(..)
->     ,emptyBindings
->     ,lbUpdate
->     -- ,lbExpandStar
->     ,lbLookupID
->     ,lbLookupIDInType
->     --,lbUpdateDot
->     ,ppLocalBindings
->     ,ppLbls
->     ,createLocalBindings
->     ,getUnqualifiedBindings
->     ,joinBindings
->     ,lookupLocalBinding
->     ) where
->
-> --import Control.Monad as M
-> --import Control.Applicative
-> --import Debug.Trace
-> --import Data.List
-> --import Data.Maybe
-> --import Data.Char
-> --import Data.Either
-> --import qualified Data.Map as M
->
-> import Database.HsSqlPpp.Internals.TypeType
-> --import Database.HsSqlPpp.Utils.Utils
-> import Database.HsSqlPpp.Internals.Catalog.CatalogInternal
-> --import Database.HsSqlPpp.Internals.TypeChecking.TypeConversion
-> import Database.HsSqlPpp.Internals.TypeChecking.ErrorUtils
->
-
-> --import Debug.Trace
-
-> data LocalBindings = LocalBindingsError
->                    | LocalBindings [((String,String),Maybe Type)]
->                      deriving Show
-
-> createLocalBindings :: Maybe [(String,[(String,Maybe Type)])] -> LocalBindings
-> createLocalBindings i =
->   maybe LocalBindingsError mb i
->   where
->     mb b = LocalBindings
->             $ flip concatMap b $ \(qn,cs) -> flip map cs $ \(c,t) -> ((qn,c), t)
-
-> getUnqualifiedBindings :: LocalBindings -> [(String,Maybe Type)]
-> getUnqualifiedBindings (LocalBindings ls) =
->   map unwrap ls
->   where
->     unwrap ((_,n),t) = (n,t)
-> getUnqualifiedBindings LocalBindingsError = []
-
-> joinBindings :: LocalBindings -> LocalBindings -> LocalBindings
-> joinBindings (LocalBindings a) (LocalBindings b) = LocalBindings $ a ++ b
-> joinBindings LocalBindingsError _ = LocalBindingsError
-> joinBindings _ LocalBindingsError = LocalBindingsError
-
-> lookupLocalBinding :: LocalBindings -> String -> String -> E (Maybe Type)
-> lookupLocalBinding LocalBindingsError _ _ = Right Nothing
-> lookupLocalBinding (LocalBindings lb) q i = {-trace ("lookupLocalBinding " ++ show lb ++ "\n" ++ show q ++ " " ++ i) $ showit "result: " $ -}
->   case lookup (q,i) lb of
->     Just t -> Right t
->     Nothing -> if (q == "") || any (==q) (map (fst . fst) lb)
->                then Left [UnrecognisedIdentifier i]
->                else Left [UnrecognisedCorrelationName q]
-
-> --showit :: Show a => String -> a -> a
-> --showit s a = trace (s ++ show a) a
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
----------------------------------------------
-
-
-
-The data type to represent a set of local bindings in scope. The list
-of updates used to create the local bindings is saved for debugging/
-information.
-
-> {-data LocalBindings = LocalBindings [LocalBindingsUpdate]
->                                    [LocalBindingsLookup]
->                      deriving Show-}
-
-Each layer of the local bindings stack is
-a map from (correlation name, id name) to source,correlation name, id
-name, type tuple, or a type error, used e.g. to represent ambigious
-ids, etc.;
-and a map from correlation name to a list of these tuples to handle
-star expansions.
-
-Missing correlation names are represented by an empty string for the
-correlation name.
-
-> type Source = String
->
-> type FullId = (Source,[String],Type) -- source,fully qualified name components,type
-> type SimpleId = (String,Type)
-> type IDLookup = ([String], E FullId)
-> --type StarExpand = E [FullId] --the order of the [FullId] part is important
->
-> data LocalBindingsLookup = LocalBindingsLookup [IDLookup]
->                            deriving (Eq,Show)
-
-This is the local bindings update that users of this module use.
-
-> data LocalBindingsUpdate = LBIds {source :: Source
->                                  ,correlationName :: Maybe String
->                                  ,lbids :: [SimpleId]}
->                          | LBTref {source :: Source
->                                   ,talias :: String
->                                   ,lbids :: [SimpleId]
->                                   ,lbsysids :: [SimpleId]}
->                          | LBJoinTref {source :: Source
->                                       ,jtref1 :: LocalBindingsUpdate
->                                       ,jtref2 :: LocalBindingsUpdate
->                                       ,joinIds :: Either () [String] -- left () represents natural join
->                                                            -- right [] represents no join ids
->                                       ,jalias :: Maybe String}
->                            deriving Show
->
-> emptyBindings :: LocalBindings
-> emptyBindings = LocalBindings [] -- undefined --LocalBindings [] []
-
-================================================================================
-
-> ppLocalBindings :: LocalBindings -> String
-> ppLocalBindings = error "ppLocalBindings" -- (LocalBindings lbus lbls) =
->   -- "LocalBindings\n" ++ doList show lbus ++ doList ppLbls lbls-}
->
-> ppLbls :: LocalBindingsLookup -> String
-> ppLbls = error "ppLbls" {- (LocalBindingsLookup is) =
->        "LocalBindingsLookup\n" ++ doList show is -}
->
-> --doList :: (a -> String) -> [a] -> String
-> --doList m l = "[\n" ++ intercalate "\n," (map m l) ++ "\n]\n"
-
-================================================================================
-
-> lbUpdate :: Catalog -> LocalBindingsUpdate -> LocalBindings -> E LocalBindings
-> lbUpdate _ _ lb = return lb {- cat u1 (LocalBindings us s) = do
->   ids <- updateStuff cat u1
->   return $ LocalBindings (u1 : us) (LocalBindingsLookup ids : s)-}
-
-
-
-> --updateStuff :: Catalog -> LocalBindingsUpdate -> E [IDLookup]
-
-> --updateStuff _ _ = error "updateStuff"
-
-LBIds doesn't support any star expansion, and doesn't support
-accessing the whole set of ids as a composite via cn
-
-> {-updateStuff _ (LBIds src cn ids) =
->     return (unQuals ++ quals)
->     where
->       unQuals = map (\(n,t) -> ([n], Right (src,maybe [n] (: [n]) cn, t))) ids
->       quals = maybe [] (\cn' -> map (\(n,t) -> ([cn',n], Right (src,[cn',n], t))) ids) cn
-
-tref - used for a non join table reference, supports accessing public
-fields under the alias name as a composite, and also supports system
-id lookups. The star expansions are all the non system ids qualified and unqualified
-
-> updateStuff _ (LBTref src al ids sids) =
->     -- comp has to come after unquals because an unqualified reference which could refer
->     -- to a column or the composite resolves as the column
->     return (unQuals ++ quals ++ [comp])
->            -- ,[("",Right pids),(al,Right pids)])
->     where
->       allIds = ids ++ sids
->       unQuals = map (\(n,t) -> ([n], Right (src,[al,n], t))) allIds
->       quals = map (\(n,t) -> ([al,n], Right (src,[al,n], t))) allIds
->       comp = ([al], Right (src, [al], CompositeType ids))
->       pids = map (\(n,t) -> (src,[al,n],t)) ids
-
-
-LBJoinTref {source :: Source
-            ,jtref1 :: LocalBindingsUpdate
-            ,jtref2 :: LocalBindingsUpdate
-            ,joinIds :: Either () [String] -- left () represents natural join
-                  -- right [] represents no join ids
-            ,jalias :: Maybe String}
-
-> {-updateStuff cat (LBJoinTref _src u1 u2 jnames' _al) = do
-
-How to get the lbs for a join:
-
-First get the info for the two sub trefs:
-
->   ids1 <- updateStuff cat u1
->   ids2 <- updateStuff cat u2
-
-split these apart so you have the unqualified lookups and star expands
-separately
-
->   let (uids1,qids1) = splitLkps ids1
->       (uids2,qids2) = splitLkps ids2
-
-We need some information: the names and types of the join ids, and the
-names of any remaining ambiguous identifiers:
-
->   let jnames :: [String]
->       jnames = case jnames' of
->                          Right ns -> ns
->                          Left () -> intersect (map fst uids1)
->                                               (map fst uids2)
->   --todo: resolve these properly
->   let jids = flip map jnames $ \i -> (i,fromJust $ lookup [i] ids1)
-
-
-First: get the names of the join ids: this is the explicit list in the
-case of a using join, or the commonly named fields in a natural
-join. You get the commonly named fields from the unqualified star
-expansions so you don't include system attributes in a natural join.
-
-Then check: make sure explicit join id list is in both trefs, and
-resolve the types of the join ids.
-
-If there is no alias:
-
-work out the lookups: the qualified lookups stay the same (doesn't
-properly deal with the same correlation names coming from 2 trefs at
-the moment).
-
-get the list of duplicate ids: uses the same code as getting the
-natural join id list, - there will be none if this is a natural
-join. Otherwise, get the list of common ids and remove any using ids
-from this list. TODO?: system attributes can't be referenced through a
-join unqualified?
-
-The unqualified lookups: start with the join ids and types, then add
-all the ids from each subtref except the ones which match the
-duplicate ids. Add these dups which now lookup to left ambiguous
-reference.
-
-work out the star expansion: the qualified star expansions stay the
-same
-
-for the unqualified star expansion: similar to lookups. Start with the
-join ids, but then add all the non join ids from each table - so we
-might have more than one column with the same name.
-
-If there is an alias:
-
-do the same as above for the unqualified ids/starexpand, add these
-again under the given alias, and don't pass through qualified lookups
-or star expands.
-
-
->   {-let plainIds1 = pl ids1
->       plainIds2 = pl ids2
->   let jnames :: [String]
->       jnames = case jids of
->                          Right ns -> ns
->                          Left () -> intersect (map fst plainIds1) (map fst plainIds2)
->   -- make the lookups
->       isJ :: IDLookup -> Bool
->       isJ (ii,_) = case ii of
->                        [i] | i `elem` jnames -> True
->                        _ -> False
->       nj :: [IDLookup] -> [IDLookup]
->       nj = filter (not . isJ)
->       joinLkps = filter isJ ids1
->       nonJoinLkps1 = nj ids1
->       nonJoinLkps2 = nj ids2-}
->   {-let jids1 :: [(String,E FullId)]
->       jids1 = flip map jnames $ \i -> (i,fromJust $ lookup i ids1)
->       rj :: [(String,E FullId)] -> [(String,E FullId)]
->       rj = filter $ \e -> fst e `notElem` jnames
->       ids :: [(String,E FullId)]
->       ids = jids1 ++ rj ids1 ++ rj ids2-}
->   --make the star expansion
->   --se1' <- se1
->   --se2' <- se2
->   {-let (us1',qs1) = splitSe se1'
->       (us2',qs2) = splitSe se2'
->   us1 <- us1'
->   us2 <- us2'-}
->   {-    rj1 :: [FullId] -> [FullId]
->       rj1 = filter $ \(_,n,_t) -> last n `notElem` jnames
->       se = map snd jids1 ++ map return (rj1 se1) ++ map return (rj1 se2)
->   return (ids, sequence se)-}
->   --let x = joinLkps ++ nonJoinLkps1 ++ nonJoinLkps2
->   --trace ("join stuff: " ++ doList show x) $ return ()
->   return (ids1 ++ ids1, se1 ++ se2) --(joinLkps ++ nonJoinLkps1 ++ nonJoinLkps2, ("", Right (us1 ++ us2)) : qs1 ++ qs2)
->   where
->     {-splitSe :: [(String,StarExpand)] -> (StarExpand,[(String,StarExpand)])
->     splitSe se = (uq, nuq)
->                  where
->                    uq = maybe [] snd $ find isUq se
->                    nuq = filter (not . isUq) se
->                    isUq (Right (a,_)) = a == ""-}
->     splitLkps :: [([String], E FullId)]
->               -> ([(String, E FullId)],[([String], E FullId)])
->     splitLkps = partitionEithers . (map $ \x -> case x of
->                                                       ([n],t) -> Left (n,t)
->                                                       z -> Right z)-} -}
-
-================================================================================
-
-> {-lbExpandStar :: LocalBindings -> String -> E [FullId]
-> lbExpandStar (LocalBindings _ (LocalBindingsLookup _ x : _)) c =
->   maybe (case c of
->            "" -> Left [BadStarExpand]
->            y -> Left [UnrecognisedCorrelationName y])
->            id $ lookup c x
-> lbExpandStar _ _ = Left [BadStarExpand]-}
-
-================================================================================
-
-> lbLookupID :: LocalBindings -> [String] -> E FullId
-> lbLookupID  = error "lbLookupID" {-(LocalBindings _ lbl) i =
->     let ls :: [[([String],E FullId)]]
->         ls = map getLbIdl lbl
->     in lkp1 ls $ map mtl i
->     where
->       lkp1 :: [[IDLookup]] -> [String] -> E FullId
->       lkp1 (l:ls) i1 = fromMaybe (lkp1 ls i1) (lookup i1 l)
->       lkp1 [] _ = if corMatch
->                   then Left [UnrecognisedIdentifier (intercalate "." i)]
->                   else Left [UnrecognisedCorrelationName (head i)]
->       getLbIdl (LocalBindingsLookup x ) = x
->       corMatch = case i of
->                    [q,_] -> q `elem` cors
->                    _ -> True
->       cors :: [String]
->       cors = let ls = map getLbIdl lbl
->              in catMaybes $ concatMap (map getQ) ls
->       getQ :: ([String], E FullId) -> Maybe String
->       getQ ([q,_], _) = Just q
->       getQ _ = Nothing -}
-
-
-> lbLookupIDInType :: Catalog -> LocalBindings -> Type -> String -> E FullId
-> lbLookupIDInType = error "lbLookupIDInType" {-cat _ ty i = do
->   t <- lmt $ getNamedCompositeTypes ty
->   maybe (Left [UnrecognisedIdentifier i]) (fmap Right ("",[i],)) $ lookup i t
->  where
->    getNamedCompositeTypes :: Type -> Maybe [(String,Type)]
->    getNamedCompositeTypes (NamedCompositeType n) =
->         Just $ either (const []) id $ catCompositePublicAttrs cat [] n
->    getNamedCompositeTypes (CompositeType t) = Just t
->    getNamedCompositeTypes (PgRecord (Just t)) = getNamedCompositeTypes t
->    getNamedCompositeTypes _ = Nothing -}
-
-================================================================================
-
- > lbUpdateDot :: Catalog -> String -> LocalBindings -> E LocalBindings
- > lbUpdateDot cat i lb = do
- >     (_,_,c) <- lbLookupID lb i
- >     f <- lmt $ expandComposite cat True c
- >     lbUpdate cat (LBIds "dot qual" Nothing f) emptyBindings
-
->     {-f <- lmt $ expandComposite cat True c
->     let u1 = (LBIds "dot qual" Nothing f)
->     (ids,_) <- updateStuff cat u1
->     pf <- lmt $ expandComposite cat False c
->     let se = Right $ map (\(n,t) -> ("dot qual", [i,n], t)) pf
->     return $ LocalBindings [u1] [LocalBindingsLookup ids se]-}
-
-(Source, [String], Type)'
-           against inferred type `(String, Type)'
-
- > expandComposite :: Catalog -> Bool -> Type -> Maybe [(String,Type)]
- > expandComposite cat b (SetOfType t) = expandComposite cat b t
- > expandComposite cat b (PgRecord (Just t)) = expandComposite cat b t
- > expandComposite _ _ (CompositeType fs) = Just fs
- > expandComposite cat b (NamedCompositeType n) = etmt $ (if b
- >                                                        then catCompositeAttrs
- >                                                        else catCompositePublicAttrs) cat [] n
- > expandComposite _ _ _ = Nothing
-
-
-================================================================================
-
-> --mtl :: String -> String
-> --mtl = map toLower
-
-
-
-
-
-
-------------------------------------------------------------
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-wrapper for the proper lookupid function, this is for backwards
-compatibility with the old lookup code
-
-> {-lbLookupID :: LocalBindings
->            -> String -- identifier name
->            -> E Type
-> lbLookupID lb ci = let (cor,i) = splitIdentifier ci
->                    in fmap extractType $ lbLookupID1 lb cor i
->                    where
->                      extractType (_,_,_,t) = t
->                      splitIdentifier s = let (a,b) = span (/= '.') s
->                                          in if b == ""
->                                             then ("", a)
->                                             else (a,tail b)
->
-> lbLookupID1 :: LocalBindings
->            -> String -- correlation name
->            -> String -- identifier name
->            -> E FullId -- type error or source, corr, type
-> lbLookupID1 (LocalBindings _ lkps) cor' i' =
->   --trace ("lookup: " ++ showID cor' i'
->   --       ++ "in " ++ concatMap ppLbls lkps) $
->   -- hack for triggers
->   case cor of
->     "new" | isTrigRec -> Right ("", "new", i, UnknownType)
->     "old" | isTrigRec -> Right ("", "old", i, UnknownType)
->     _ -> lkId lkps
->   where
->     isTrigRec = case lbLookupID1 (LocalBindings undefined lkps) "" cor of
->                   Right (_,_,_,Pseudo TriggerRecord) -> True
->                   _ -> False
->     cor = mtl cor'
->     i = mtl i'
->     lkId ((LocalBindingsLookup idmap _):ls) =
->       case lookup (cor,i) idmap of
->         Just s -> s
->         Nothing -> if cor /= "" && any ((==cor) . fst . fst) idmap
->                    then Left [UnrecognisedIdentifier $ showID cor i']
->                    else lkId ls
->     lkId [] = if cor' == "" --todo: need to throw unrecognised identifier, if the correlation name isn't "", a id isn't found, and there are other ids with that correlation name
->               then Left [UnrecognisedIdentifier $ showID cor i']
->               else Left [UnrecognisedCorrelationName cor']
-
-================================================================================
-
-wrapped for the proper expand star routine, for compatibility with the
-old implementation of local bindings
-
-> lbExpandStar :: LocalBindings -> String -> E [SimpleId]
-> lbExpandStar lb cor =
->   fmap stripAll $ lbExpandStar1 lb cor
->   where
->     strip (_,_,n,t) = (n,t)
->     stripAll = map strip
->
-> lbExpandStar1 :: LocalBindings -> String -> E [FullId]
-> lbExpandStar1 (LocalBindings _ lkps) cor' =
->   exSt lkps
->   where
->     cor = mtl cor'
->     exSt ((LocalBindingsLookup _ lst):ls) =
->         case lookup cor lst of
->           Just s -> s
->           Nothing -> exSt ls
->     exSt [] = Left [UnrecognisedCorrelationName cor]
-
-================================================================================
-
-This is where constructing the local bindings lookup stacks is done
-
-> lbUpdate :: Catalog -> LocalBindingsUpdate -> LocalBindings -> E LocalBindings
-> lbUpdate cat lbu' (LocalBindings lbus lkps) = do
->    lbl <- makeStack cat lbu
->    lbl1 <- expandComposites cat lbl
->    --trace ("update: " ++ ppLbls lbl1) $ return ()
->    return $ LocalBindings (lbu':lbus) (lbl1:lkps)
->    where
->      lbu = lowerise lbu'
->      -- make correlation names and id names case insensitive
->      -- by making them all lowercase
->      lowerise (LBIds src ids) =
->        LBIds src (mtll ids)
->      lowerise (LBJoinIds t1 t2 ji a) =
->        LBJoinIds (lowerise t1) (lowerise t2) (fmap mtll1 ji) (mtl a)
->      lowerise (LBParallel lbu1 lbu2) =
->        LBParallel (lowerise lbu1) (lowerise lbu2)
->      mtll = map (\(n,t) -> (mtl n, t))
->      mtll1 = map (\l -> mtl l)
->
-> makeStack :: Catalog -> LocalBindingsUpdate -> E LocalBindingsLookup
-> makeStack _ (LBIds src ids) =
->   Right $ LocalBindingsLookup doIds doStar
->   where
->     doIds :: [((String,String)
->               ,E FullId)]
->     doIds = -- add unqualified if cor isn't empty string
->             map (makeLookup "")
->                    (case cor of
->                             "" -> []
->                             _ -> map addDetails ids ++ map addDetails iids)
->             ++ map (makeLookup cor) (map addDetails ids ++ map addDetails iids)
->             where
->               makeLookup c1 (s,_,n,t)= ((c1,n), Right (s,cor,n,t))
->     doStar :: [(String, E [FullId])]
->     doStar = case cor of
->                       "" -> []
->                       _ -> [("",Right $ map addDetails ids)]
->              ++ [(cor,Right $ map addDetails ids)]
->     addDetails (n,t) = (src,cor,n,t)
->
-> makeStack cat (LBJoinIds t1 t2 jns a) = do
->   --first get the stacks from t1 and t2
->   --combine the elements of these filtering out the join ids
->   --
->   (LocalBindingsLookup i1 s1) <- makeStack cat t1
->   (LocalBindingsLookup i2 s2) <- makeStack cat t2
->   -- get the names and types of the join columns
->   let jns' = case jns of
->              Left () -> -- natural join, so you have to work out the names
->                         -- by looking at the common attributes
->                         -- you do this by getting the star expansion
->                         -- with no correlation name, and then finding
->                         -- the ids which appear in both lists
->                         -- (so this ignores internal ids)
->                  let ic1 :: [FullId]
->                      ic1 = fromRight [] $ maybe (Right []) id $ lookup "" s1
->                      ic2 = fromRight [] $ maybe (Right []) id $ lookup "" s2
->                      third (_,_,n,_) = n
->                      ii1 :: [String]
->                      ii1 = map third ic1
->                      ii2 = map third ic2
->                  in intersect ii1 ii2
->              Right x -> x
->       -- first prepare for the id lookups
->       -- remove the join ids from the id lookups
->       isJid ((_,n),_) = (n `elem` jns')
->       removeJids = filter (not . isJid)
->       i1' = removeJids i1
->       i2' = removeJids i2
->   jids <- M.sequence $ joinIDTypes i1 i2 jns'
->   {-trace ("joinids: " ++ show jids
->          ++ "\ni1 " ++ show i1
->          ++ "\ni2 " ++ show i2
->          ++ "\ni1' " ++ show i1'
->          ++ "\ni2' " ++ show i2'
->         ) $ return ()-}
->   let jidsLk :: [IDLookup]
->       jidsLk = if null i1 || null i2
->                then [] --error?
->                else let (_,Right (sc1,c1,_,_)) = head i1
->                         (_,Right (sc2,c2,_,_)) = head i2
->                     in flip concatMap jids $ \(n,t) -> [(("",n), Right (sc1,c1,n,t))
->                                                        ,((c1,n), Right (sc1,c1,n,t))
->                                                        ,((c2,n), Right (sc2,c2,n,t))
->                                                        ]
->       --jidsF :: [FullId]
->       --jidsF = rights $ map snd jidsLk
->       newIdLookups = (jidsLk ++ (combineAddAmbiguousErrors i1' i2'))
->       -- now do the star expansions
->       -- for each correlation name, remove any ids which match a join id
->       -- then prepend the join ids to that list
->       se = combineStarExpansions s1 s2 -- don't know if this is quite right
->       removeJids1 :: StarLookup -> StarLookup
->       removeJids1 (k,ids) = (k, fmap (filter (\(_,_,n,_) -> n `notElem` jns')) ids)
->       prependJids :: StarLookup -> StarLookup
->       prependJids (c, lkps) = case lkps of
->                                 Left _ -> (c,lkps)
->                                 Right r | null r -> (c,lkps)
->                                 Right r -> let (s,c1,_,_) = head r
->                                                ids = map (\(n,t) -> (s,c1,n,t)) jids
->                                            in (c, fmap (ids++) lkps)
->       newStarExpansion = map (prependJids . removeJids1) se
->       -- if you have an alias then you just want unqualified ids, then
->       -- the same ids with a t3 alias for both ids and star expansion
->       -- with all the correlation names replaced with the alias
->   if a == ""
->     then return $ LocalBindingsLookup newIdLookups newStarExpansion
->     else return $ LocalBindingsLookup (aliasIds newIdLookups) (aliasExps newStarExpansion)
->   where
->     aliasIds :: [IDLookup] -> [IDLookup]
->     aliasIds lkps = let trimmed = filter (\((c,_),_) -> c == "") lkps
->                         aliased = map (\(c,i) -> (c, fmap replaceCName i)) trimmed
->                     in aliased ++ map (\((_,n),i) -> ((a,n),i)) aliased
->     aliasExps :: [StarLookup] -> [StarLookup]
->     aliasExps lkps = let is = fromMaybe (error "localbindingsinternal.makestack : fromJust") $
->                               lookup "" lkps
->                          aliased = fmap (map replaceCName) is
->                      in [("",aliased), (a, aliased)]
->     replaceCName (s,_,n,t) = (s,a,n,t)
->     joinIDTypes :: [IDLookup] -> [IDLookup] -> [String] -> [E (String,Type)]
->     joinIDTypes i1 i2 = map (joinIDType i1 i2)
->     joinIDType :: [IDLookup] -> [IDLookup] -> String -> E (String,Type)
->     joinIDType i1 i2 s = do
->       (_,_,_,ty1) <- fromMaybe (Left [MissingJoinAttribute]) $
->                      lookup ("",s) i1
->       (_,_,_,ty2) <- fromMaybe (Left [MissingJoinAttribute]) $
->                      lookup ("",s) i2
->       ty <- resolveResultSetType cat [ty1,ty2]
->       return (s,ty)
->
-> makeStack cat (LBParallel u1 u2) = do
->   -- get the two stacks,
->   -- for any keys that appear in both respective lookups, replace with ambigious error
->   -- and concatenate the lot
->   (LocalBindingsLookup i1 s1) <- makeStack cat u1
->   (LocalBindingsLookup i2 s2) <- makeStack cat u2
->   return $ LocalBindingsLookup (combineAddAmbiguousErrors i1 i2) $ combineStarExpansions s1 s2
->
-> combineStarExpansions :: [StarLookup] -> [StarLookup] -> [StarLookup]
-> combineStarExpansions s1 s2 =
->   let p :: [(String, [(String, E [FullId])])]
->       p = npartition fst (s1 ++ s2)
->   in flip map p $ \(a,b) -> (a,concat <$> M.sequence (map snd b))
->
-> combineAddAmbiguousErrors :: [IDLookup] -> [IDLookup] -> [IDLookup]
-> combineAddAmbiguousErrors i1 i2 =
->   let commonIds = intersect (map fst i1) (map fst i2)
->       removeCommonIds = filter (\a -> fst a `notElem` commonIds)
->       fi1 = removeCommonIds i1
->       fi2 = removeCommonIds i2
->       errors = map (\(c,n) -> ((c,n),Left [AmbiguousIdentifier $ showID c n])) commonIds
->   in fi1 ++ fi2 ++ errors
-
-===============================================================================
-
-> mtl :: String -> String
-> mtl = map toLower
->
-> showID :: String -> String -> String
-> showID cor i = if cor == "" then i else cor ++ "." ++ i
-
-================================================================================
-
-expand composites
-
-slightly dodgy - run through all the unqualified ids in the idlookups, and if any
-have a composite type, add each element of that composite under the
-correlation name of the idlookup itself, and add a star expansion for
-that name also. This pretends that using a correlation name, composite
-name and id name as a three part id isn't possible
-
-> expandComposites :: Catalog -> LocalBindingsLookup -> E LocalBindingsLookup
-> expandComposites cat (LocalBindingsLookup idlkp stlkp) = do
->   let unqids = filter (\((a,_),_) -> a == "") idlkp
->       strip = map snd unqids
->       getComposites = filter (\(_,_,_,t) -> isCt t) $ rights strip
->   comps <- mapM compExp getComposites
->   let sts = map toStarLookup comps
->   Right (LocalBindingsLookup (idlkp ++ (concat comps)) (stlkp ++ sts))
->   where
->     isCt (SetOfType t) = isCompositeType t
->     isCt t = isCompositeType t
->     getCompFields :: Type -> E [(String,Type)]
->     getCompFields (SetOfType t) = getCompFields t
->     getCompFields (PgRecord Nothing) = Right []
->     getCompFields (PgRecord (Just t)) = getCompFields t
->     getCompFields (CompositeType f) = return f
->     getCompFields (NamedCompositeType s) = catCompositePublicAttrs cat [] s
->     getCompFields (AnonymousRecordType _) = Right [] -- ??
->     getCompFields _ = Right []
->     compExp :: FullId -> E [IDLookup]
->     compExp (s,_,n,t) = do
->       f <- getCompFields t
->       return $ flip map f $ \(n1,t1) -> ((n,n1),Right (s,n,n1,t1))
->     toStarLookup :: [IDLookup] -> StarLookup
->     toStarLookup ids =
->       let fids::[FullId]
->           fids = rights $ map snd ids
->           (_,c,_,_) = if null fids then (undefined,"ERROR",undefined,undefined) else head fids
->       in (c,Right fids)-}
diff --git a/src/Database/HsSqlPpp/Internals/TypeChecking/OldTediousTypeUtils.lhs b/src/Database/HsSqlPpp/Internals/TypeChecking/OldTediousTypeUtils.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/TypeChecking/OldTediousTypeUtils.lhs
@@ -0,0 +1,60 @@
+
+The reason this file exists is because the representation of types in
+hssqlppp (in the module ...Internals.TypesInternal) is not good. I'm
+not sure it can be improved that much though.
+
+> {-# LANGUAGE FlexibleInstances,DeriveDataTypeable #-}
+>
+> module Database.HsSqlPpp.Internals.TypeChecking.OldTediousTypeUtils where
+
+> import Database.HsSqlPpp.Internals.TypesInternal
+> import Control.Arrow
+> import Data.Text (Text)
+> --import qualified Data.Text as T
+
+> isArrayType :: Type -> Bool
+> isArrayType (ArrayType _) = True
+> isArrayType _ = False
+>
+> isDomainType :: Type -> Bool
+> isDomainType (DomainType _) = True
+> isDomainType _ = False
+>
+> isCompositeType :: Type -> Bool
+> isCompositeType (CompositeType _) = True
+> isCompositeType (NamedCompositeType _) = True
+> isCompositeType (AnonymousCompositeType _) = True
+> isCompositeType (Pseudo (Record _)) = True
+> isCompositeType _ = False
+>
+> isCompositeOrSetOfCompositeType :: Type -> Bool
+> isCompositeOrSetOfCompositeType (Pseudo (SetOfType a)) = isCompositeType a
+> isCompositeOrSetOfCompositeType a = isCompositeType a
+>
+> unwrapArray :: Type -> Either [TypeError] Type
+> unwrapArray (ArrayType t) = Right t
+> unwrapArray x = Left [InternalError $ "can't get types from non array " ++ show x]
+>
+> unwrapSetOfWhenComposite :: Type -> Either [TypeError] Type
+> unwrapSetOfWhenComposite (Pseudo (SetOfType a@(CompositeType _))) = Right a
+> unwrapSetOfWhenComposite x = Left [InternalError $ "tried to unwrapSetOfWhenComposite on " ++ show x]
+>
+> unwrapSetOfComposite :: Type -> Either [TypeError]  [(Text,Type)]
+> unwrapSetOfComposite (Pseudo (SetOfType (CompositeType a))) = Right $ map (second teType) a
+> unwrapSetOfComposite x = Left [InternalError $ "tried to unwrapSetOfComposite on " ++ show x]
+>
+> unwrapSetOf :: Type -> Either [TypeError] Type
+> unwrapSetOf (Pseudo (SetOfType a)) = Right a
+> unwrapSetOf x = Left [InternalError $ "tried to unwrapSetOf on " ++ show x]
+>
+> unwrapComposite :: Type -> Either [TypeError] [(Text,Type)]
+> unwrapComposite (CompositeType a) = Right $ map (second teType) a
+> unwrapComposite x = Left [InternalError $ "cannot unwrapComposite on " ++ show x]
+>
+> consComposite :: (Text,Type) -> Type -> Either [TypeError] Type
+> consComposite l (CompositeType a) = Right $ CompositeType (second mkTypeExtra l :a)
+> consComposite a b = Left [InternalError $ "called consComposite on " ++ show (a,b)]
+>
+> unwrapRowCtor :: Type -> Either [TypeError] [Type]
+> unwrapRowCtor (AnonymousCompositeType a) = Right a
+> unwrapRowCtor x = Left [InternalError $ "cannot unwrapRowCtor on " ++ show x]
diff --git a/src/Database/HsSqlPpp/Internals/TypeChecking/TypeConversion.lhs b/src/Database/HsSqlPpp/Internals/TypeChecking/TypeConversion.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Internals/TypeChecking/TypeConversion.lhs
+++ /dev/null
@@ -1,676 +0,0 @@
-
-
-This file contains the functions for resolving types and
-function/operator resolution (which is seriously crazy). See the pg
-manual chapter 10:
-
-http://www.postgresql.org/docs/8.4/interactive/typeconv.html
-
-This code is really spaghettified.
-
-findCallMatch - pass in a name and a list of arguments, and it returns
-the matching function. (pg manual 10.2,10.3)
-
-resolveResultSetType - pass in a set of types, and it tries to find
-the common type they can all be cast to. (pg manual 10.5)
-
-checkAssignmentValid - pass in source type and target type, returns
-                typelist[] if ok, otherwise error, pg manual 10.4
-                Value Storage
-
-I wrote this when I was still struggling with haskell basics so it is
-probably the worst bit of code in the codebase (there are a few
-other contenders for this accolade). A rewrite is planned, but it
-seems to do the job reasonably well at the moment so keeps getting put
-off.
-
-
-> {-# LANGUAGE PatternGuards,NondecreasingIndentation #-}
-> module Database.HsSqlPpp.Internals.TypeChecking.TypeConversion (
->                        findCallMatch
->                       ,resolveResultSetType
->                       ,checkAssignmentValid
->                       ,checkAssignmentsValid
->                       ) where
->
-> import Data.Maybe
-> import Data.List
-> import Data.Either
-> --import Debug.Trace
-> import Data.Char
->
-> import Database.HsSqlPpp.Internals.TypeType
-> import Database.HsSqlPpp.Internals.Catalog.CatalogInternal
-> import Database.HsSqlPpp.Utils.Utils
-
- > traceIt :: Show a => String -> a -> a
- > traceIt s t = trace (s ++ ": " ++ show t) t
-
-= findCallMatch
-
-~~~~
-
-findCallMatch - partially implements the type conversion rules for
-finding an operator or function match given a name and list of
-arguments with partial or fully specified types
-
-TODO:, qualifiers
-namespaces
-function style casts not in catalog
-variadic args
-default args
-domains -> base type
-what about aggregates and window functions?
-
-Algo:
-
-cands = all fns with matching names
-        and same number of args
-
-if exact match on types in this list, use it
-  (if binary operator being matched, and one arg is typed and one is
-  unknown, also match an operator by assuming the unknown is the same
-  as the typed arg)
-
-best match part:
-
-filter cands with args which don't exactly match input args, and input
-args cannot be converted by an implicit cast. unknowns count as
-matching anything
-if one left: use it
-
-filter for preferred types:
-
-for each cand, count each arg at each position which needs conversion,
-and the cand type is a preferred type at that position.
-if there are cands with count>0, keep only cands with the max count,
-if one return it
-if there are no cands with count>0, keep them all
-
-check unknowns:
-if any input args are unknown, and any cand accepts string at that
-position, fix that arg's category as string, otherwise if all cands
-accept same category at that position, fix that input args as that
-category.
-if we still have unknowns, then fail
-
-discard cands which don't match the new input arg/category list
-
-for each categorised input arg, if any cand accepts preferred type at
-that position, get rid of cands which don't accept preferred type at
-that position
-
-if one left: use
-else fail
-
-polymorphic matching:
-want to create a set of matches to insert into the cast pairs list
-so:
-
-find all matches on name, num args and have polymorphic parameters
-
-for each one, check the polymorphic categories - eliminate fns that
-have params in wrong category - array, non array, enum.
-work out the base types for the polymorphic args at each spot based on
-the args passed - so each arg is unchanged except arrays which have
-the array part stripped off
-
-now we have a list of types to match against the polymorphic params,
-use resolveResultSetType to see if we can produce a match, if so,
-create a new prototype which is the same as the polymorphic function
-but with this matching arg swapped in, work out the casts and add it
-into cand cast pairs, after exact match has been run.
-
-
-findCallMatch is a bit of a mess
-
-todos:
-
-rewrite this to try to make it a bit clearer
-
-find some way to draw a data flow diagram of the code easily
-
-add a logging facility so the function can explain what has happened
-at each state, so you can provide a detailed explanation e.g. if the
-code can't find an operator match to see what it has tried to match
-against.
-
-~~~~
-
-> type ProtArgCast = (FunctionPrototype, [ArgCastFlavour])
-
->       {-
->         between, greatest and least are treated as syntactic sugar so we
->         delegate the function lookups to the <=/>= operators.
->         the row comparison should be more general than this, since it supports
->         any operator satisfying some properties
-> -}
-> findCallMatch :: Catalog -> String -> [Type] ->  Either [TypeError] FunctionPrototype
-> findCallMatch cat fnName' argsType =
->     --trace ("typecheckfncall " ++ fnName' ++ show argsType) $
->     --dependsOnRTpe argsType $
->       case fnName of
->               "count" -> -- not quite sure how this is suppose to work,
->                          -- the counts in the pg catalog accept either
->                          -- no args, or one arg of type any, but you can call
->                          -- count with multiple arguments?
->                          return ("count", argsType, typeBigInt, False)
->               "!between" | as@[_,_,_] <- argsType -> do
->                     -- not sure if this is correct - use the result set resolution
->                     -- to make the argument types compatible
->                     -- then just check there is a >=, <= returning a pair
->                     -- of somethings which can be anded
->                     t <- resolveResultSetType cat as
->                     f1 <- lookupReturnType ">=" [t,t]
->                     f2 <- lookupReturnType "<=" [t,t]
->                     _ <- lookupFn "!and" [f1,f2]
->                     return ("!between", [t,t,t], typeBool, False)
->               "greatest" -> do
->                     (_,a,t,x) <- lookupFn fnName argsType
->                     _ <- lookupFn ">=" [t,t]
->                     return ("greatest",a,t,x)
->               "least" -> do
->                     (_,a,t,x) <- lookupFn fnName argsType
->                     _ <- lookupFn "<=" [t,t]
->                     return ("greatest",a,t,x)
->               "!rowctor" -> return ("!rowCtor", argsType, AnonymousRecordType argsType, False)
->                     -- special case the row comparison ops
->                     -- this needs to be fixed: we want to match
->                     -- any implicit casts to functions on composite types
->                     -- first, then we can use the anonymous record type on
->                     -- any composite
->               "." | [_,b] <- argsType -> Right (".", argsType, b, False)
->               _ | fnName `elem` ["=", "<>", "<=", ">=", "<", ">"]
->                          && length argsType == 2
->                          && all isCompositeOrSetOfCompositeType argsType,
->                          Just a1 <- matchCompTypes argsType ->
->                          -- && compositesCompatible cat (head argsType) (head $ tail argsType) ->
->                              return (fnName, a1, typeBool, False)
->               --checked for all special cases, so run general case now
->               s -> lookupFn s argsType
->     where
->       lookupReturnType :: String -> [Type] -> Either [TypeError] Type
->       lookupReturnType s1 args = fmap (\(_,_,r,_) -> r) $ lookupFn s1 args
->       lookupFn :: String -> [Type] -> Either [TypeError] FunctionPrototype
->       lookupFn s1 = findCallMatch1 cat
->                              (if s1 == "u-" then "-" else s1)
->       fnName = map toLower fnName'
->       -- help the type inference for rowCtors. pretty unfinished. If we compare
->       -- two compatible row constructors, then replace any unknown types with the
->       -- pair type
->       matchCompTypes :: [Type] -> Maybe [Type]
->       matchCompTypes [a@(AnonymousRecordType as),b@(AnonymousRecordType bs)] =
->         if not (compositesCompatible cat a b)
->         then Nothing
->         else let (nt1,nt2) = unzip $ map (\(t,t1) -> case (t,t1) of
->                                          (UnknownType, u) -> (u,u)
->                                          (u, UnknownType) -> (u,u)
->                                          _ -> (t,t1)) $ zip as bs
->              in Just [AnonymousRecordType nt1,AnonymousRecordType nt2]
->       matchCompTypes [a,b] =
->         if not (compositesCompatible cat a b)
->         then Nothing
->         else Just [a,b]
->       matchCompTypes _ = Nothing
-
-
->
-> findCallMatch1 :: Catalog -> String -> [Type] ->  Either [TypeError] FunctionPrototype
-> findCallMatch1 cat f inArgs =
->     returnIfOnne [
->        exactMatch
->       ,binOp1UnknownMatch
->       ,polymorpicExactMatches
->       ,reachable
->       ,mostExactMatches
->       ,filteredForPreferred
->       ,unknownMatchesByCat]
->       [NoMatchingOperator f inArgs]
->     where
->       -- basic lists which roughly mirror algo
->       -- get the possibly matching candidates
->       initialCandList :: [FunctionPrototype]
->       initialCandList = filter (\(_,candArgs,_,_) ->
->                                   length candArgs == length inArgs) $
->                                map expandVariadic $ catLookupFns cat f
->
->       expandVariadic fp@(fn,a,r,v) =
->         if v
->           then case last a of
->                  ArrayType t -> (fn, na,r,v)
->                                 where na = init a ++ replicate (length inArgs - length a + 1) t
->                  _ -> fp --should be error
->           else fp
->
->       -- record what casts are needed for each candidate
->       castPairs :: [[ArgCastFlavour]]
->       castPairs = map (listCastPairs . getFnArgs) initialCandList
->
->       candCastPairs :: [ProtArgCast]
->       candCastPairs = {-traceIt "candCastPairs" $-} zip initialCandList castPairs
->
->       -- see if we have an exact match
->       exactMatch :: [ProtArgCast]
->       exactMatch = filterCandCastPairs (all (==ExactMatch)) candCastPairs
->
->       -- implement the one known, one unknown resolution for binary operators
->       binOp1UnknownMatch :: [ProtArgCast]
->       binOp1UnknownMatch = getBinOp1UnknownMatch candCastPairs
->
->       --collect possible polymorphic matches
->       polymorphicMatches :: [ProtArgCast]
->       polymorphicMatches = filterPolymorphics candCastPairs
->
->       polymorpicExactMatches :: [ProtArgCast]
->       polymorpicExactMatches = filterCandCastPairs (all (==ExactMatch)) polymorphicMatches
->
->       -- eliminate candidates for which the inargs cannot be casted to
->       reachable :: [ProtArgCast]
->       reachable = mergePolys (filterCandCastPairs (none (==CannotCast)) candCastPairs)
->                     polymorphicMatches
->
->       mostExactMatches :: [ProtArgCast]
->       mostExactMatches =
->         let inArgsBase = map (replaceWithBase cat) inArgs
->             exactCounts :: [Int]
->             exactCounts =
->               map ((length
->                       . filter (\(a1,a2) -> a1==replaceWithBase cat a2)
->                       . zip inArgsBase)
->                 . (\((_,a,_,_),_) -> a)) reachable
->             pairs = zip reachable exactCounts
->             maxm = maximum exactCounts
->         in case () of
->              _ | null reachable -> []
->                | maxm > 0 -> map fst $ filter (\(_,b) -> b == maxm) pairs
->                | otherwise -> []
->
->       -- keep the cands with the most casts to preferred types
->       preferredTypesCounts = countPreferredTypeCasts reachable
->       keepCounts = maximum preferredTypesCounts
->       itemCountPairs :: [(ProtArgCast,Int)]
->       itemCountPairs = zip reachable preferredTypesCounts
->       filteredForPreferred :: [ProtArgCast]
->       filteredForPreferred = map fst $ filter (\(_,i) -> i == keepCounts) itemCountPairs
->
->       -- collect the inArg type categories to do unknown inArg resolution
->       argCats :: [Either () String]
->       argCats = getCastCategoriesForUnknowns filteredForPreferred
->       unknownMatchesByCat :: [ProtArgCast]
->       unknownMatchesByCat = getCandCatMatches filteredForPreferred argCats
->
->       -------------
->
->       listCastPairs :: [Type] -> [ArgCastFlavour]
->       listCastPairs l = listCastPairs' inArgs l
->                         where
->                           listCastPairs' :: [Type] -> [Type] -> [ArgCastFlavour]
->                           listCastPairs' (ia:ias) (ca:cas) =
->                               (case () of
->                                  _ | ia == ca -> ExactMatch
->                                    | castableFromTo cat ImplicitCastContext ia ca ->
->                                        if forceRight (catPreferredType cat ca)
->                                          then ImplicitToPreferred
->                                          else ImplicitToNonPreferred
->                                    | otherwise -> CannotCast
->                               ) : listCastPairs' ias cas
->                           listCastPairs' [] [] = []
->                           listCastPairs' _ _ = error "internal error: mismatched num args in implicit cast algorithm"
->
->
->       getBinOp1UnknownMatch :: [ProtArgCast] -> [ProtArgCast]
->       getBinOp1UnknownMatch cands =
->           if not (isOperatorName f &&
->                   length inArgs == 2 &&
->                   count (==UnknownType) inArgs == 1)
->             then []
->             else let newInArgs =
->                          replicate 2 (if head inArgs == UnknownType
->                                         then inArgs !! 1
->                                         else head inArgs)
->                  in filter (\((_,a,_,_),_) -> a == newInArgs) cands
->
->       filterPolymorphics :: [ProtArgCast] -> [ProtArgCast]
->       filterPolymorphics cl =
->           let ms :: [ProtArgCast]
->               ms = filter canMatch polys
->               polyTypes :: [Maybe Type]
->               polyTypes = map resolvePolyType ms
->               polyTypePairs :: [(Maybe Type, ProtArgCast)]
->               polyTypePairs = zip polyTypes ms
->               keepPolyTypePairs :: [(Type, ProtArgCast)]
->               keepPolyTypePairs =
->                 mapMaybe (\(t,p) -> case t of
->                                            Nothing -> Nothing
->                                            Just t' -> Just (t',p))
->                               polyTypePairs
->               finalRows = map (\(t,p) -> instantiatePolyType p t)
->                               keepPolyTypePairs
->               --create the new cast lists
->               cps :: [[ArgCastFlavour]]
->               cps = map (listCastPairs . getFnArgs . fst) finalRows
->           in zip (map fst finalRows) cps
->           where
->             polys :: [ProtArgCast]
->             polys = filter (\((_,a,_,_),_) -> any (`elem`
->                                               -- bit hacky
->                                              [Pseudo Any
->                                              ,Pseudo AnyArray
->                                              ,Pseudo AnyElement
->                                              ,Pseudo AnyEnum
->                                              ,Pseudo AnyNonArray]) a) cl
->             canMatch :: ProtArgCast -> Bool
->             canMatch pac =
->                let ((_,fnArgs,_,_),_) = pac
->                in canMatch' inArgs fnArgs
->                where
->                  canMatch' [] [] = True
->                  canMatch' (ia:ias) (pa:pas) =
->                    case pa of
->                      Pseudo Any -> nextMatch
->                      Pseudo AnyArray -> isArrayType ia && nextMatch
->                      Pseudo AnyElement -> nextMatch
->                      Pseudo AnyEnum -> False
->                      Pseudo AnyNonArray -> if isArrayType ia
->                                              then False
->                                              else nextMatch
->                      _ -> True
->                    where
->                      nextMatch = canMatch' ias pas
->                  canMatch' _ _ = error "internal error: mismatched lists in canMatch'"
->             resolvePolyType :: ProtArgCast -> Maybe Type
->             resolvePolyType ((_,fnArgs,_,_),_) =
->                 {-trace ("\nresolving " ++ show fnArgs ++ " against " ++ show inArgs ++ "\n") $-}
->                 let argPairs = zip inArgs fnArgs
->                     typeList :: [Type]
->                     typeList = catMaybes $ flip map argPairs
->                                  $ \(ia,fa) -> case fa of
->                                                   Pseudo Any -> if isArrayType ia
->                                                                 then eitherToMaybe $ unwrapArray ia
->                                                                 else Just ia
->                                                   Pseudo AnyArray -> eitherToMaybe $ unwrapArray ia
->                                                   Pseudo AnyElement -> if isArrayType ia
->                                                                        then eitherToMaybe $ unwrapArray ia
->                                                                        else Just ia
->                                                   Pseudo AnyEnum -> Nothing
->                                                   Pseudo AnyNonArray -> Just ia
->                                                   _ -> Nothing
->                 in {-trace ("\nresolve types: " ++ show typeList ++ "\n") $-}
->                    case resolveResultSetType cat typeList of
->                      Left _ -> Nothing
->                      Right t -> Just t
->             instantiatePolyType :: ProtArgCast -> Type -> ProtArgCast
->             instantiatePolyType pac t =
->               let ((fn,a,r,v),_) = pac
->                   instArgs = swapPolys t a
->                   p1 = (fn, instArgs, swapPoly t r,v)
->               in let x = (p1,listCastPairs instArgs)
->                  in {-trace ("\nfixed:" ++ show x ++ "\n")-} x
->               where
->                 swapPolys :: Type -> [Type] -> [Type]
->                 swapPolys = map . swapPoly
->                 swapPoly :: Type -> Type -> Type
->                 swapPoly pit at =
->                   case at of
->                     Pseudo Any -> if isArrayType at
->                                     then ArrayType pit
->                                     else pit
->                     Pseudo AnyArray -> ArrayType pit
->                     Pseudo AnyElement -> if isArrayType at
->                                            then ArrayType pit
->                                            else pit
->                     Pseudo AnyEnum -> pit
->                     Pseudo AnyNonArray -> pit
->                     SetOfType (Pseudo AnyElement) -> if isArrayType at
->                                                      then SetOfType (ArrayType pit)
->                                                      else SetOfType pit
->                     _ -> at
->       --merge in the instantiated poly functions, with a twist:
->       -- if we already have the exact same set of args in the non poly list
->       -- as a poly, then don't include that poly
->       mergePolys :: [ProtArgCast] -> [ProtArgCast] -> [ProtArgCast]
->       mergePolys orig polys =
->           let origArgs = map (\((_,a,_,_),_) -> a) orig
->               filteredPolys = filter (\((_,a,_,_),_) -> a `notElem` origArgs) polys
->           in orig ++ filteredPolys
->
->       countPreferredTypeCasts :: [ProtArgCast] -> [Int]
->       countPreferredTypeCasts =
->           map (\(_,cp) -> count (==ImplicitToPreferred) cp)
->
->       -- Left () is used for inArgs which aren't unknown,
->       --                      and for unknowns which we don't have a
->       --                      unique category
->       -- Right s -> s is the single letter category at
->       --                           that position
->       getCastCategoriesForUnknowns :: [ProtArgCast] -> [Either () String]
->       getCastCategoriesForUnknowns cands =
->           filterArgN 0
->           where
->             candArgLists :: [[Type]]
->             candArgLists = map (\((_,a,_,_), _) -> a) cands
->             filterArgN :: Int -> [Either () String]
->             filterArgN n =
->                 if n == length inArgs
->                   then []
->                   else let targType = inArgs !! n
->                        in ((if targType /= UnknownType
->                               then Left ()
->                               else getCandsCatAt n) : filterArgN (n+1))
->                 where
->                   getCandsCatAt :: Int -> Either () String
->                   getCandsCatAt n' =
->                       let typesAtN = map (!!n') candArgLists
->                           catsAtN = map (forceRight . catTypeCategory cat) typesAtN
->                       in case () of
->                            --if any are string choose string
->                            _ | any (== "S") catsAtN -> Right "S"
->                              -- if all are same cat choose that
->                              | all (== head catsAtN) catsAtN -> Right $ head catsAtN
->                              -- otherwise no match, this will be
->                              -- picked up as complete failure to match
->                              -- later on
->                              | otherwise -> Left ()
->
->       getCandCatMatches :: [ProtArgCast] -> [Either () String] -> [ProtArgCast]
->       getCandCatMatches candsA cats = getMatches candsA 0
->          where
->            getMatches :: [ProtArgCast] -> Int -> [ProtArgCast]
->            getMatches cands n =
->                case () of
->                  _ | n == length inArgs -> cands
->                    | (inArgs !! n) /= UnknownType -> getMatches cands (n + 1)
->                    | otherwise ->
->                        let catMatches :: [ProtArgCast]
->                            catMatches = filter (\c -> Right (getCatForArgN n c) ==
->                                                      (cats !! n)) cands
->                            prefMatches :: [ProtArgCast]
->                            prefMatches = filter (forceRight . catPreferredType cat .
->                                                    getTypeForArgN n) catMatches
->                            keepMatches :: [ProtArgCast]
->                            keepMatches = if length prefMatches > 0
->                                            then prefMatches
->                                            else catMatches
->                        in getMatches keepMatches (n + 1)
->            getTypeForArgN :: Int -> ProtArgCast -> Type
->            getTypeForArgN n ((_,a,_,_),_) = a !! n
->            getCatForArgN :: Int -> ProtArgCast -> String
->            getCatForArgN n = forceRight . catTypeCategory cat . getTypeForArgN n
->
->       -- utils
->       -- filter a candidate/cast flavours pair by a predicate on each
->       -- individual cast flavour
->       filterCandCastPairs :: ([ArgCastFlavour] -> Bool)
->                           -> [ProtArgCast]
->                           -> [ProtArgCast]
->       filterCandCastPairs predi = filter (\(_,cp) -> predi cp)
->
->       getFnArgs :: FunctionPrototype -> [Type]
->       getFnArgs (_,a,_,_) = a
->       returnIfOnne [] e = Left e
->       returnIfOnne (l:ls) e = if length l == 1
->                               then Right $ getHeadFn l
->                               else returnIfOnne ls e
->
->       getHeadFn :: [ProtArgCast] -> FunctionPrototype
->       getHeadFn l =  let ((hdFn, _):_) = l
->                      in hdFn
->       none p = not . any p
->       count p = length . filter p
->
-> data ArgCastFlavour = ExactMatch
->                     | CannotCast
->                     | ImplicitToPreferred
->                     | ImplicitToNonPreferred
->                       deriving (Eq,Show)
->
-
-~~~~
-resolveResultSetType -
-partially implement the typing of results sets where the types aren't
-all the same and not unknown
-used in union,except,intersect columns, case, array ctor, values, greatest and least
-
-algo:
-if all inputs are same and not unknown -> that type
-replace domains with base types
-if all inputs are unknown then text
-if the non unknown types aren't all in same category then fail
-choose first input type that is a preferred type if there is one
-choose last non unknown type that has implicit casts from all preceding inputs
-check all can convert to selected type else fail
-
-code is not as much of a mess as findCallMatch
-~~~~
-
-> resolveResultSetType :: Catalog -> [Type] -> Either [TypeError] Type
-> resolveResultSetType cat inArgs = do
->   errorWhen (null inArgs) [TypelessEmptyArray]
->   returnWhen allSameType (head inArgs) $ do
->   returnWhen allSameBaseType (head inArgsBase) $ do
->   --returnWhen allUnknown (UnknownType) $ do
->   errorWhen (not allSameCat) [IncompatibleTypeSet inArgs]
->   returnWhen (isJust targetType &&
->               allConvertibleToFrom (fromMaybe (error "TypeConversion.resolveresultsettype 1: fromJust") targetType) inArgs)
->               (fromMaybe (error "TypeConversion.resolveresultsettype 2: fromJust") targetType) $ do
->   Left [IncompatibleTypeSet inArgs]
->   where
->      allSameType = all (== head inArgs) inArgs -- &&
->                      --head inArgs /= UnknownType
->      allSameBaseType = all (== head inArgsBase) inArgsBase &&
->                      head inArgsBase /= UnknownType
->      inArgsBase = map (replaceWithBase cat) inArgs
->      --allUnknown = all (==UnknownType) inArgsBase
->      allSameCat = let firstCat = catTypeCategory cat (head knownTypes)
->                   in all (\t -> catTypeCategory cat t == firstCat)
->                          knownTypes
->      targetType = case catMaybes [firstPreferred, lastAllConvertibleTo] of
->                     [] -> Nothing
->                     (x:_) -> Just x
->      firstPreferred = find (forceRight . catPreferredType cat) knownTypes
->      lastAllConvertibleTo = firstAllConvertibleTo (reverse knownTypes)
->      firstAllConvertibleTo (x:xs) = if allConvertibleToFrom x xs
->                                       then Just x
->                                       else firstAllConvertibleTo xs
->      firstAllConvertibleTo [] = Nothing
->      knownTypes = filter (/=UnknownType) inArgsBase
->      allConvertibleToFrom = all . flip (castableFromTo cat ImplicitCastContext)
-
-todo:
-cast empty array, where else can an empty array work?
-
-================================================================================
-
-= checkAssignmentValue
-
-> checkAssignmentValid :: Catalog -> Type -> Type -> Either [TypeError] ()
-> checkAssignmentValid cat from to =
->     if castableFromTo cat AssignmentCastContext from to
->     then Right ()
->     else Left [IncompatibleTypes to from]
->
-> compositesCompatible :: Catalog -> Type -> Type -> Bool
-> compositesCompatible cat =
->     castableFromTo cat ImplicitCastContext
-
-> checkAssignmentsValid :: Catalog -> [Type] -> [Type] -> Either [TypeError] ()
-> checkAssignmentsValid cat from to = do
->     -- special case for assigning to composite
->     let f = case to of
->                    [t] | isCompositeType t -> [AnonymousRecordType from]
->                    _ -> from
->     errorWhen (length f /= length to)
->               [WrongNumberOfColumns]
->     let ls = concat $ lefts $ zipWith (checkAssignmentValid cat) f to
->     errorWhen (not (null ls)) ls
-
-
-================================================================================
-
-= castable function
-
-wrapper around the catalog to add a bunch of extra valid casts
-
-> castableFromTo :: Catalog -> CastContext -> Type -> Type -> Bool
-> castableFromTo cat cc from to =
->   --trace ("check cast " ++ show from ++ "->" ++ show to) $
->   -- put this here to avoid having to write it everywhere else
->   from == to
->   -- unknown can be implicitly cast to anything (is this completely true?)
->   || from == UnknownType
->   --hack?
->   || to == UnknownType
->   -- check base types of domains
->   || ((isDomainType from || isDomainType to)
->       && castableFromTo cat cc (replaceWithBase cat from)
->                                (replaceWithBase cat to))
->   -- check the casts listed in the catalog
->   || forceRight (catCast cat cc from to)
->   -- implicitcast => assignment cast
->   || (cc == AssignmentCastContext
->       && forceRight (catCast cat ImplicitCastContext from to))
->   -- can assign composite to record
->   || (cc == AssignmentCastContext
->       && isCompOrSetoOfComp from
->       && case to of
->            PgRecord _ -> True
->            _ -> False)
->   -- check unboxing: wrapped single attribute
->   || recurseTransFrom (unboxedSingleType from)
->   || recurseTransTo (unboxedSingleType to)
->   -- check unboxing: wrapped composite
->   || recurseTransFrom (unboxedSetOfType from)
->   || recurseTransTo (unboxedSetOfType to)
->   -- check composites compatible by comparing attribute types
->   || case (getCompositeTypes from
->           ,getCompositeTypes to) of
->        -- zip almost does the right thing here, needs a bit of tweaking
->        (Just ft, Just tt) | length ft == length tt -> all (uncurry $ castableFromTo cat cc) $ zip ft tt
->        _ -> False
->   where
->
->     getCompositeTypes (NamedCompositeType n) =
->         Just $ map snd $ fromRight [] $ catCompositePublicAttrs cat [] n
->     getCompositeTypes (CompositeType t) = Just $ map snd t
->     getCompositeTypes (AnonymousRecordType t) = Just t
->     getCompositeTypes (PgRecord Nothing) = Nothing
->     getCompositeTypes (PgRecord (Just t)) = getCompositeTypes t
->     getCompositeTypes _ = Nothing
->
->     isCompOrSetoOfComp (SetOfType c) = isCompositeType c
->     isCompOrSetoOfComp c = isCompositeType c
->
->     unboxedSingleType (SetOfType (CompositeType [(_,t)])) = Just t
->     unboxedSingleType (PgRecord (Just t)) = unboxedSingleType t
->     unboxedSingleType _ = Nothing
->
->     unboxedSetOfType (SetOfType a) = Just a
->     unboxedSetOfType (PgRecord (Just t)) = unboxedSetOfType t
->     unboxedSetOfType _ = Nothing
->
->     recurseTransFrom = maybe False (flip (castableFromTo cat cc) to)
->     recurseTransTo = maybe False (castableFromTo cat cc from)
->
-> replaceWithBase :: Catalog -> Type -> Type
-> replaceWithBase cat t@(DomainType _) = forceRight $ catDomainBaseType cat t
-> replaceWithBase _ t = t
diff --git a/src/Database/HsSqlPpp/Internals/TypeChecking/TypeConversion/OldTypeConversion.lhs b/src/Database/HsSqlPpp/Internals/TypeChecking/TypeConversion/OldTypeConversion.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/TypeChecking/TypeConversion/OldTypeConversion.lhs
@@ -0,0 +1,742 @@
+
+
+This file contains the functions for resolving types and
+function/operator resolution (which is seriously crazy). See the pg
+manual chapter 10:
+
+http://www.postgresql.org/docs/8.4/interactive/typeconv.html
+
+This code is really spaghettified.
+
+findCallMatch - pass in a name and a list of arguments, and it returns
+the matching function. (pg manual 10.2,10.3)
+
+resolveResultSetType - pass in a set of types, and it tries to find
+the common type they can all be cast to. (pg manual 10.5)
+
+checkAssignmentValid - pass in source type and target type, returns
+                typelist[] if ok, otherwise error, pg manual 10.4
+                Value Storage
+
+I wrote this when I was still struggling with haskell basics so it is
+probably the worst bit of code in the codebase (there are a few
+other contenders for this accolade). A rewrite is planned, but it
+seems to do the job reasonably well at the moment so keeps getting put
+off.
+
+
+> {-# LANGUAGE PatternGuards,OverloadedStrings,NondecreasingIndentation #-}
+> module Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.OldTypeConversion (
+>                        findCallMatch
+>                       ,resolveResultSetType
+>                       ,resolveResultSetTypeExtra
+>                       ,adjustStringCastPrec
+>                       ,joinPrecision
+>                       ,joinScale
+>                       ,joinNullability
+>                       ,checkAssignmentValid
+>                       ,checkAssignmentsValid
+>                       ) where
+>
+> import Data.Maybe
+> import Data.List
+> import Data.Either
+> --import Debug.Trace
+> import Data.Char
+> import Control.Monad
+> import Control.Arrow
+>
+> import Database.HsSqlPpp.Internals.TypesInternal
+> import Database.HsSqlPpp.Internals.Dialect
+> import Database.HsSqlPpp.Internals.Catalog.CatalogInternal
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+> --import Database.HsSqlPpp.Utils.Utils
+> import Database.HsSqlPpp.Internals.TypeChecking.OldTediousTypeUtils
+> import Data.Text (Text)
+> import qualified Data.Text as T
+> --import Text.Show.Pretty
+
+ > traceIt :: Show a => String -> a -> a
+ > traceIt s t = trace (s ++ ": " ++ show t) t
+
+= findCallMatch
+
+~~~~
+
+findCallMatch - partially implements the type conversion rules for
+finding an operator or function match given a name and list of
+arguments with partial or fully specified types
+
+TODO:, qualifiers
+namespaces
+function style casts not in catalog
+variadic args
+default args
+domains -> base type
+what about aggregates and window functions?
+
+Algo:
+
+cands = all fns with matching names
+        and same number of args
+
+if exact match on types in this list, use it
+  (if binary operator being matched, and one arg is typed and one is
+  unknown, also match an operator by assuming the unknown is the same
+  as the typed arg)
+
+best match part:
+
+filter cands with args which don't exactly match input args, and input
+args cannot be converted by an implicit cast. unknowns count as
+matching anything
+if one left: use it
+
+filter for preferred types:
+
+for each cand, count each arg at each position which needs conversion,
+and the cand type is a preferred type at that position.
+if there are cands with count>0, keep only cands with the max count,
+if one return it
+if there are no cands with count>0, keep them all
+
+check unknowns:
+if any input args are unknown, and any cand accepts string at that
+position, fix that arg's category as string, otherwise if all cands
+accept same category at that position, fix that input args as that
+category.
+if we still have unknowns, then fail
+
+discard cands which don't match the new input arg/category list
+
+for each categorised input arg, if any cand accepts preferred type at
+that position, get rid of cands which don't accept preferred type at
+that position
+
+if one left: use
+else fail
+
+polymorphic matching:
+want to create a set of matches to insert into the cast pairs list
+so:
+
+find all matches on name, num args and have polymorphic parameters
+
+for each one, check the polymorphic categories - eliminate fns that
+have params in wrong category - array, non array, enum.
+work out the base types for the polymorphic args at each spot based on
+the args passed - so each arg is unchanged except arrays which have
+the array part stripped off
+
+now we have a list of types to match against the polymorphic params,
+use resolveResultSetType to see if we can produce a match, if so,
+create a new prototype which is the same as the polymorphic function
+but with this matching arg swapped in, work out the casts and add it
+into cand cast pairs, after exact match has been run.
+
+
+findCallMatch is a bit of a mess
+
+todos:
+
+rewrite this to try to make it a bit clearer
+
+find some way to draw a data flow diagram of the code easily
+
+add a logging facility so the function can explain what has happened
+at each state, so you can provide a detailed explanation e.g. if the
+code can't find an operator match to see what it has tried to match
+against.
+
+~~~~
+
+> type ProtArgCast = (OperatorPrototype, [ArgCastFlavour])
+
+>       {-
+>         between, greatest and least are treated as syntactic sugar so we
+>         delegate the function lookups to the <=/>= operators.
+>         the row comparison should be more general than this, since it supports
+>         any operator satisfying some properties
+> -}
+> findCallMatch :: Dialect -> Catalog -> Text -> [Type] ->  Either [TypeError] OperatorPrototype
+> findCallMatch d cat fnName' argsType =
+>     --trace (if fnName=="=" then "typecheckfncall " ++ fnName' ++ show argsType else "") $
+>     --dependsOnRTpe argsType $
+>       case fnName of
+>               "between" | as@[_,_,_] <- argsType -> do
+>                     -- not sure if this is correct - use the result set resolution
+>                     -- to make the argument types compatible
+>                     -- then just check there is a >=, <= returning a pair
+>                     -- of somethings which can be anded
+>                     t <- resolveResultSetType cat as
+>                     f1 <- lookupReturnType ">=" [t,t]
+>                     f2 <- lookupReturnType "<=" [t,t]
+>                     _ <- lookupFn "and" [f1,f2]
+>                     bt <- maybe (Left []) Right $ ansiTypeNameToDialect d "boolean"
+>                     return ("between", [t,t,t], ScalarType bt, False)
+>               "notbetween" | as@[_,_,_] <- argsType -> do
+>                     -- not sure if this is correct - use the result set resolution
+>                     -- to make the argument types compatible
+>                     -- then just check there is a >=, <= returning a pair
+>                     -- of somethings which can be anded
+>                     t <- resolveResultSetType cat as
+>                     f1 <- lookupReturnType "<" [t,t]
+>                     f2 <- lookupReturnType ">" [t,t]
+>                     _ <- lookupFn "or" [f1,f2]
+>                     bt <- maybe (Left []) Right $ ansiTypeNameToDialect d "boolean"
+>                     return ("notbetween", [t,t,t], ScalarType bt, False)
+>               "greatest" -> do
+>                     (_,a,t,x) <- lookupFn fnName argsType
+>                     _ <- lookupFn ">=" [t,t]
+>                     return ("greatest",a,t,x)
+>               "least" -> do
+>                     (_,a,t,x) <- lookupFn fnName argsType
+>                     _ <- lookupFn "<=" [t,t]
+>                     return ("greatest",a,t,x)
+>               "rowctor" -> return ("rowCtor", argsType, AnonymousCompositeType argsType, False)
+>                     -- special case the row comparison ops
+>                     -- this needs to be fixed: we want to match
+>                     -- any implicit casts to functions on composite types
+>                     -- first, then we can use the anonymous record type on
+>                     -- any composite
+>               "." | [_,b] <- argsType -> Right (".", argsType, b, False)
+>               _ | fnName `elem` ["=", "<>", "<=", ">=", "<", ">"]
+>                          && length argsType == 2
+>                          && all isCompositeOrSetOfCompositeType argsType,
+>                          Just bt <- ansiTypeNameToDialect d "boolean",
+>                          Just a1 <- matchCompTypes argsType ->
+>                          -- && compositesCompatible cat (head argsType) (head $ tail argsType) ->
+>                              return (fnName, a1, ScalarType bt, False)
+>               --checked for all special cases, so run general case now
+>               s -> lookupFn s argsType
+>     where
+>       lookupReturnType :: Text -> [Type] -> Either [TypeError] Type
+>       lookupReturnType s1 args = fmap (\(_,_,r,_) -> r) $ lookupFn s1 args
+>       lookupFn :: Text -> [Type] -> Either [TypeError] OperatorPrototype
+>       lookupFn = findCallMatch1 cat
+>       fnName = T.map toLower fnName'
+>       -- help the type inference for rowCtors. pretty unfinished. If we compare
+>       -- two compatible row constructors, then replace any unknown types with the
+>       -- pair type
+>       matchCompTypes :: [Type] -> Maybe [Type]
+>       matchCompTypes [a@(AnonymousCompositeType as),b@(AnonymousCompositeType bs)] =
+>         if not (compositesCompatible cat a b)
+>         then Nothing
+>         else let (nt1,nt2) = unzip $ map (\(t,t1) -> case (t,t1) of
+>                                          (UnknownType, u) -> (u,u)
+>                                          (u, UnknownType) -> (u,u)
+>                                          _ -> (t,t1)) $ zip as bs
+>              in Just [AnonymousCompositeType nt1,AnonymousCompositeType nt2]
+>       matchCompTypes [a,b] =
+>         if not (compositesCompatible cat a b)
+>         then Nothing
+>         else Just [a,b]
+>       matchCompTypes _ = Nothing
+
+>
+> findCallMatch1 :: Catalog -> Text -> [Type] ->  Either [TypeError] OperatorPrototype
+> findCallMatch1 cat f inArgs =
+>     let x = [exactMatch
+>             ,binOp1UnknownMatch
+>             ,polymorpicExactMatches
+>             ,reachable
+>             ,mostExactMatches
+>             ,filteredForPreferred
+>             ,unknownMatchesByCat]
+>         y = returnIfOnne ({-trace (if f `elem` ["=","lower"]
+>                              then ("\n-----------------\n"
+>                                  -- ++ ppShow (let c = catUpdates cat in drop (length c - 30) c)
+>                                  -- ++ "\n-----------------\n"
+>                                  ++ ppShoe (f,inArgs) ++ "\n" ++ groom x)
+>                              else "")-} x)
+>                     [NoMatchingOperator f inArgs]
+>     in {-trace (if f `elem` ["=","lower"] then "y = " ++ show y else "")-} y
+>     where
+>       -- basic lists which roughly mirror algo
+>       -- get the possibly matching candidates
+>       initialCandList :: [OperatorPrototype]
+>       initialCandList = filter (\(_,candArgs,_,_) ->
+>                                   length candArgs == length inArgs) $
+>                                map expandVariadic $ catLookupFns cat f
+>
+>       expandVariadic fp@(fn,a,r,v) =
+>         if v
+>           then case last a of
+>                  ArrayType t -> (fn, na,r,v)
+>                                 where na = init a ++ replicate (length inArgs - length a + 1) t
+>                  _ -> fp --should be error
+>           else fp
+>
+>       -- record what casts are needed for each candidate
+>       castPairs :: [[ArgCastFlavour]]
+>       castPairs = map (listCastPairs . getFnArgs) initialCandList
+>
+>       candCastPairs :: [ProtArgCast]
+>       candCastPairs = {-traceIt "candCastPairs" $-} zip initialCandList castPairs
+>
+>       -- see if we have an exact match
+>       exactMatch :: [ProtArgCast]
+>       exactMatch = filterCandCastPairs (all (==ExactMatch)) candCastPairs
+>
+>       -- implement the one known, one unknown resolution for binary operators
+>       binOp1UnknownMatch :: [ProtArgCast]
+>       binOp1UnknownMatch = getBinOp1UnknownMatch candCastPairs
+>
+>       --collect possible polymorphic matches
+>       polymorphicMatches :: [ProtArgCast]
+>       polymorphicMatches = filterPolymorphics candCastPairs
+>
+>       polymorpicExactMatches :: [ProtArgCast]
+>       polymorpicExactMatches = filterCandCastPairs (all (==ExactMatch)) polymorphicMatches
+>
+>       -- eliminate candidates for which the inargs cannot be casted to
+>       reachable :: [ProtArgCast]
+>       reachable = mergePolys (filterCandCastPairs (none (==CannotCast)) candCastPairs)
+>                     polymorphicMatches
+>
+>       mostExactMatches :: [ProtArgCast]
+>       mostExactMatches =
+>         let inArgsBase = map (replaceWithBase cat) inArgs
+>             exactCounts :: [Int]
+>             exactCounts =
+>               map ((length
+>                       . filter (\(a1,a2) -> a1==replaceWithBase cat a2)
+>                       . zip inArgsBase)
+>                 . (\((_,a,_,_),_) -> a)) reachable
+>             pairs = zip reachable exactCounts
+>             maxm = maximum exactCounts
+>         in case () of
+>              _ | null reachable -> []
+>                | maxm > 0 -> map fst $ filter (\(_,b) -> b == maxm) pairs
+>                | otherwise -> []
+>
+>       -- keep the cands with the most casts to preferred types
+>       preferredTypesCounts = countPreferredTypeCasts reachable
+>       keepCounts = maximum preferredTypesCounts
+>       itemCountPairs :: [(ProtArgCast,Int)]
+>       itemCountPairs = zip reachable preferredTypesCounts
+>       filteredForPreferred :: [ProtArgCast]
+>       filteredForPreferred = map fst $ filter (\(_,i) -> i == keepCounts) itemCountPairs
+>
+>       -- collect the inArg type categories to do unknown inArg resolution
+>       argCats :: [Either () Text]
+>       argCats = getCastCategoriesForUnknowns filteredForPreferred
+>       unknownMatchesByCat :: [ProtArgCast]
+>       unknownMatchesByCat = getCandCatMatches filteredForPreferred argCats
+>
+>       -------------
+>
+>       listCastPairs :: [Type] -> [ArgCastFlavour]
+>       listCastPairs = listCastPairs' inArgs
+>                         where
+>                           listCastPairs' :: [Type] -> [Type] -> [ArgCastFlavour]
+>                           listCastPairs' (ia:ias) (ca:cas) =
+>                               (case () of
+>                                  _ | ia == ca -> ExactMatch
+>                                    | castableFromTo cat ImplicitCastContext ia ca ->
+>                                        either (error . show)
+>                                               (\b ->  if b
+>                                                       then ImplicitToPreferred
+>                                                       else ImplicitToNonPreferred)
+>                                               (catPreferredType cat ca)
+>                                    | otherwise -> CannotCast
+>                               ) : listCastPairs' ias cas
+>                           listCastPairs' [] [] = []
+>                           listCastPairs' _ _ = error "internal error: mismatched num args in implicit cast algorithm"
+>
+>
+>       getBinOp1UnknownMatch :: [ProtArgCast] -> [ProtArgCast]
+>       getBinOp1UnknownMatch cands =
+>           if not (isOperatorName f &&
+>                   length inArgs == 2 &&
+>                   count (==UnknownType) inArgs == 1)
+>             then []
+>             else let newInArgs =
+>                          replicate 2 (if head inArgs == UnknownType
+>                                         then inArgs !! 1
+>                                         else head inArgs)
+>                  in filter (\((_,a,_,_),_) -> a == newInArgs) cands
+>
+>       filterPolymorphics :: [ProtArgCast] -> [ProtArgCast]
+>       filterPolymorphics cl =
+>           let ms :: [ProtArgCast]
+>               ms = filter canMatch polys
+>               polyTypes :: [Maybe Type]
+>               polyTypes = map resolvePolyType ms
+>               polyTypePairs :: [(Maybe Type, ProtArgCast)]
+>               polyTypePairs = zip polyTypes ms
+>               keepPolyTypePairs :: [(Type, ProtArgCast)]
+>               keepPolyTypePairs =
+>                 mapMaybe (\(t,p) -> case t of
+>                                            Nothing -> Nothing
+>                                            Just t' -> Just (t',p))
+>                               polyTypePairs
+>               finalRows = map (\(t,p) -> instantiatePolyType p t)
+>                               keepPolyTypePairs
+>               --create the new cast lists
+>               cps :: [[ArgCastFlavour]]
+>               cps = map (listCastPairs . getFnArgs . fst) finalRows
+>           in zip (map fst finalRows) cps
+>           where
+>             polys :: [ProtArgCast]
+>             polys = filter (\((_,a,_,_),_) -> any (`elem`
+>                                               -- bit hacky
+>                                              [Pseudo Any
+>                                              ,Pseudo AnyArray
+>                                              ,Pseudo AnyElement
+>                                              ,Pseudo AnyEnum
+>                                              ,Pseudo AnyNonArray]) a) cl
+>             canMatch :: ProtArgCast -> Bool
+>             canMatch pac =
+>                let ((_,fnArgs,_,_),_) = pac
+>                in canMatch' inArgs fnArgs
+>                where
+>                  canMatch' [] [] = True
+>                  canMatch' (ia:ias) (pa:pas) =
+>                    case pa of
+>                      Pseudo Any -> nextMatch
+>                      Pseudo AnyArray -> isArrayType ia && nextMatch
+>                      Pseudo AnyElement -> nextMatch
+>                      Pseudo AnyEnum -> False
+>                      Pseudo AnyNonArray -> if isArrayType ia
+>                                              then False
+>                                              else nextMatch
+>                      _ -> True
+>                    where
+>                      nextMatch = canMatch' ias pas
+>                  canMatch' _ _ = error "internal error: mismatched lists in canMatch'"
+>             resolvePolyType :: ProtArgCast -> Maybe Type
+>             resolvePolyType ((_,fnArgs,_,_),_) =
+>                 {-trace ("\nresolving " ++ show fnArgs ++ " against " ++ show inArgs ++ "\n") $-}
+>                 let argPairs = zip inArgs fnArgs
+>                     typeList :: [Type]
+>                     typeList = catMaybes $ flip map argPairs
+>                                  $ \(ia,fa) -> case fa of
+>                                                   Pseudo Any -> if isArrayType ia
+>                                                                 then either (const Nothing) Just $ unwrapArray ia
+>                                                                 else Just ia
+>                                                   Pseudo AnyArray -> either (const Nothing) Just $ unwrapArray ia
+>                                                   Pseudo AnyElement -> if isArrayType ia
+>                                                                        then either (const Nothing) Just $ unwrapArray ia
+>                                                                        else Just ia
+>                                                   Pseudo AnyEnum -> Nothing
+>                                                   Pseudo AnyNonArray -> Just ia
+>                                                   _ -> Nothing
+>                 in {-trace ("\nresolve types: " ++ show typeList ++ "\n") $-}
+>                    case resolveResultSetType cat typeList of
+>                      Left _ -> Nothing
+>                      Right t -> Just t
+>             instantiatePolyType :: ProtArgCast -> Type -> ProtArgCast
+>             instantiatePolyType pac t =
+>               let ((fn,a,r,v),_) = pac
+>                   instArgs = swapPolys t a
+>                   p1 = (fn, instArgs, swapPoly t r,v)
+>               in let x = (p1,listCastPairs instArgs)
+>                  in {-trace ("\nfixed:" ++ show x ++ "\n")-} x
+>               where
+>                 swapPolys :: Type -> [Type] -> [Type]
+>                 swapPolys = map . swapPoly
+>                 swapPoly :: Type -> Type -> Type
+>                 swapPoly pit at =
+>                   case at of
+>                     Pseudo Any -> if isArrayType at
+>                                     then ArrayType pit
+>                                     else pit
+>                     Pseudo AnyArray -> ArrayType pit
+>                     Pseudo AnyElement -> if isArrayType at
+>                                            then ArrayType pit
+>                                            else pit
+>                     Pseudo AnyEnum -> pit
+>                     Pseudo AnyNonArray -> pit
+>                     Pseudo (SetOfType (Pseudo AnyElement)) ->
+>                         if isArrayType at
+>                         then Pseudo $ SetOfType (ArrayType pit)
+>                         else Pseudo $ SetOfType pit
+>                     _ -> at
+>       --merge in the instantiated poly functions, with a twist:
+>       -- if we already have the exact same set of args in the non poly list
+>       -- as a poly, then don't include that poly
+>       mergePolys :: [ProtArgCast] -> [ProtArgCast] -> [ProtArgCast]
+>       mergePolys orig polys =
+>           let origArgs = map (\((_,a,_,_),_) -> a) orig
+>               filteredPolys = filter (\((_,a,_,_),_) -> a `notElem` origArgs) polys
+>           in orig ++ filteredPolys
+>
+>       countPreferredTypeCasts :: [ProtArgCast] -> [Int]
+>       countPreferredTypeCasts =
+>           map (\(_,cp) -> count (==ImplicitToPreferred) cp)
+>
+>       -- Left () is used for inArgs which aren't unknown,
+>       --                      and for unknowns which we don't have a
+>       --                      unique category
+>       -- Right s -> s is the single letter category at
+>       --                           that position
+>       getCastCategoriesForUnknowns :: [ProtArgCast] -> [Either () Text]
+>       getCastCategoriesForUnknowns cands =
+>           filterArgN 0
+>           where
+>             candArgLists :: [[Type]]
+>             candArgLists = map (\((_,a,_,_), _) -> a) cands
+>             filterArgN :: Int -> [Either () Text]
+>             filterArgN n =
+>                 if n == length inArgs
+>                   then []
+>                   else let targType = inArgs !! n
+>                        in ((if targType /= UnknownType
+>                               then Left ()
+>                               else getCandsCatAt n) : filterArgN (n+1))
+>                 where
+>                   getCandsCatAt :: Int -> Either () Text
+>                   getCandsCatAt n' =
+>                       let typesAtN = map (!!n') candArgLists
+>                           catsAtN = map (either (error . show) id . catTypeCategory cat) typesAtN
+>                       in case () of
+>                            --if any are string choose string
+>                            _ | "S" `elem` catsAtN -> Right "S"
+>                              -- if all are same cat choose that
+>                              | all (== head catsAtN) catsAtN -> Right $ head catsAtN
+>                              -- otherwise no match, this will be
+>                              -- picked up as complete failure to match
+>                              -- later on
+>                              | otherwise -> Left ()
+>
+>       getCandCatMatches :: [ProtArgCast] -> [Either () Text] -> [ProtArgCast]
+>       getCandCatMatches candsA cats = getMatches candsA 0
+>          where
+>            getMatches :: [ProtArgCast] -> Int -> [ProtArgCast]
+>            getMatches cands n =
+>                case () of
+>                  _ | n == length inArgs -> cands
+>                    | (inArgs !! n) /= UnknownType -> getMatches cands (n + 1)
+>                    | otherwise ->
+>                        let catMatches :: [ProtArgCast]
+>                            catMatches = filter (\c -> Right (getCatForArgN n c) ==
+>                                                      (cats !! n)) cands
+>                            prefMatches :: [ProtArgCast]
+>                            prefMatches = filter (either (error . show) id . catPreferredType cat .
+>                                                    getTypeForArgN n) catMatches
+>                            keepMatches :: [ProtArgCast]
+>                            keepMatches = if length prefMatches > 0
+>                                            then prefMatches
+>                                            else catMatches
+>                        in getMatches keepMatches (n + 1)
+>            getTypeForArgN :: Int -> ProtArgCast -> Type
+>            getTypeForArgN n ((_,a,_,_),_) = a !! n
+>            getCatForArgN :: Int -> ProtArgCast -> Text
+>            getCatForArgN n = either (error . show) id . catTypeCategory cat . getTypeForArgN n
+>
+>       -- utils
+>       -- filter a candidate/cast flavours pair by a predicate on each
+>       -- individual cast flavour
+>       filterCandCastPairs :: ([ArgCastFlavour] -> Bool)
+>                           -> [ProtArgCast]
+>                           -> [ProtArgCast]
+>       filterCandCastPairs predi = filter (\(_,cp) -> predi cp)
+>
+>       getFnArgs :: OperatorPrototype -> [Type]
+>       getFnArgs (_,a,_,_) = a
+>       returnIfOnne [] e = Left e
+>       returnIfOnne (l:ls) e = if length l == 1
+>                               then Right $ getHeadFn l
+>                               else returnIfOnne ls e
+>
+>       getHeadFn :: [ProtArgCast] -> OperatorPrototype
+>       getHeadFn l =  let ((hdFn, _):_) = l
+>                      in hdFn
+>       none p = not . any p
+>       count p = length . filter p
+>
+> data ArgCastFlavour = ExactMatch
+>                     | CannotCast
+>                     | ImplicitToPreferred
+>                     | ImplicitToNonPreferred
+>                       deriving (Eq,Show)
+>
+
+~~~~
+resolveResultSetType -
+partially implement the typing of results sets where the types aren't
+all the same and not unknown
+used in union,except,intersect columns, case, array ctor, values, greatest and least
+
+algo:
+if all inputs are same and not unknown -> that type
+replace domains with base types
+if all inputs are unknown then text
+if the non unknown types aren't all in same category then fail
+choose first input type that is a preferred type if there is one
+choose last non unknown type that has implicit casts from all preceding inputs
+check all can convert to selected type else fail
+
+code is not as much of a mess as findCallMatch
+~~~~
+
+> resolveResultSetTypeExtra:: Catalog -> [TypeExtra] -> Either [TypeError] TypeExtra
+> resolveResultSetTypeExtra cat inArgs
+>   = liftM addPrecAndNull $ resolveResultSetType cat $ map teType inArgs
+>   where
+>     addPrecAndNull t = if null inArgs
+>       then mkTypeExtra t
+>       else TypeExtra t (prec t) scale nullability
+>     nullability = joinNullability $ map teNullable inArgs
+>     prec t = joinPrecision $ adjustStringCastPrec t inArgs
+>     scale = joinScale $ map teScale inArgs
+
+> adjustStringCastPrec:: Type -> [TypeExtra] -> [Maybe Int]
+> adjustStringCastPrec tTo = map $ uncurry adjust . (teType&&&tePrecision)
+>   where
+>     stringTypes = map ScalarType ["char","varchar","nvarchar","text"]
+>     adjust tFrom precFrom = msum  [guard (tTo `elem` stringTypes) >> lookup tFrom typePrecs
+>                                   -- if there will be problems with literals, add here
+>                                   -- a treatment for UnknownType
+>                                   ,precFrom]
+>     typePrecs = map (first ScalarType)  [("bool",1)
+>                                         ,("int1",4), ("int2",6), ("int4",12), ("int8",24)
+>                                         ,("float4",23), ("float8",23)
+>                                         ,("date",40), ("timestamp",40)]
+
+> resolveResultSetType :: Catalog -> [Type] -> Either [TypeError] Type
+> resolveResultSetType cat inArgs = do
+>   when (null inArgs) $ Left [TypelessEmptyArray]
+>   if allSameType then return (head inArgs) else do
+>   if allSameBaseType then return (head inArgsBase) else do
+>   --returnWhen allUnknown (UnknownType) $ do
+>   unless allSameCat $ Left [IncompatibleTypeSet inArgs]
+>   if isJust targetType
+>       && allConvertibleToFrom (fromMaybe (error "TypeConversion.resolveresultsettype 1: fromJust") targetType) inArgs
+>     then return (fromMaybe (error "TypeConversion.resolveresultsettype 2: fromJust") targetType)
+>     else Left [IncompatibleTypeSet inArgs]
+>   where
+>      allSameType = all (== head inArgs) inArgs -- &&
+>                      --head inArgs /= UnknownType
+>      allSameBaseType = all (== head inArgsBase) inArgsBase &&
+>                      head inArgsBase /= UnknownType
+>      inArgsBase = map (replaceWithBase cat) inArgs
+>      --allUnknown = all (==UnknownType) inArgsBase
+>      allSameCat = let firstCat = catTypeCategory cat (head knownTypes)
+>                   in all (\t -> catTypeCategory cat t == firstCat)
+>                          knownTypes
+>      targetType = case catMaybes [firstPreferred, lastAllConvertibleTo] of
+>                     [] -> Nothing
+>                     (x:_) -> Just x
+>      firstPreferred = find (either (error . show) id . catPreferredType cat) knownTypes
+>      lastAllConvertibleTo = firstAllConvertibleTo (reverse knownTypes)
+>      firstAllConvertibleTo (x:xs) = if allConvertibleToFrom x xs
+>                                       then Just x
+>                                       else firstAllConvertibleTo xs
+>      firstAllConvertibleTo [] = Nothing
+>      knownTypes = filter (/=UnknownType) inArgsBase
+>      allConvertibleToFrom = all . flip (castableFromTo cat ImplicitCastContext)
+
+todo:
+cast empty array, where else can an empty array work?
+
+--------------------
+
+join (in Order Theory terms) of precision, scale, and nullability
+
+> joinNullability:: [Bool] -> Bool
+> joinNullability = or
+> -- questionable logic; to be revisited
+> joinPrecision:: [Maybe Int] -> Maybe Int
+> joinPrecision ps = if null ps' then Nothing else Just $ maximum ps'
+>   where
+>     ps' = catMaybes ps
+> -- same thing for now
+> joinScale:: [Maybe Int] -> Maybe Int
+> joinScale = joinPrecision
+
+================================================================================
+
+= checkAssignmentValue
+
+> checkAssignmentValid :: Catalog -> Type -> Type -> Either [TypeError] ()
+> checkAssignmentValid cat from to =
+>     if castableFromTo cat AssignmentCastContext from to
+>     then Right ()
+>     else Left [IncompatibleTypes to from]
+>
+> compositesCompatible :: Catalog -> Type -> Type -> Bool
+> compositesCompatible cat =
+>     castableFromTo cat ImplicitCastContext
+
+> checkAssignmentsValid :: Catalog -> [Type] -> [Type] -> Either [TypeError] ()
+> checkAssignmentsValid cat from to = do
+>     -- special case for assigning to composite
+>     let f = case to of
+>                    [t] | isCompositeType t -> [AnonymousCompositeType from]
+>                    _ -> from
+>     when (length f /= length to) $ Left [WrongNumberOfColumns]
+>     let ls = concat $ lefts $ zipWith (checkAssignmentValid cat) f to
+>     unless (null ls) $ Left ls
+
+
+================================================================================
+
+= castable function
+
+wrapper around the catalog to add a bunch of extra valid casts
+
+> castableFromTo :: Catalog -> CastContext -> Type -> Type -> Bool
+> castableFromTo cat cc from to =
+>   --trace ("check cast " ++ show from ++ "->" ++ show to) $
+>   -- put this here to avoid having to write it everywhere else
+>   from == to
+>   -- unknown can be implicitly cast to anything (is this completely true?)
+>   || from == UnknownType
+>   --hack?
+>   || to == UnknownType
+>   -- check base types of domains
+>   || ((isDomainType from || isDomainType to)
+>       && castableFromTo cat cc (replaceWithBase cat from)
+>                                (replaceWithBase cat to))
+>   -- check the casts listed in the catalog
+>   || either (error . show) id (catCast cat cc from to)
+>   -- implicitcast => assignment cast
+>   || (cc == AssignmentCastContext
+>       && either (error . show) id (catCast cat ImplicitCastContext from to))
+>   -- can assign composite to record
+>   || (cc == AssignmentCastContext
+>       && isCompOrSetoOfComp from
+>       && case to of
+>            Pseudo (Record _) -> True
+>            _ -> False)
+>   -- check unboxing: wrapped single attribute
+>   || recurseTransFrom (unboxedSingleType from)
+>   || recurseTransTo (unboxedSingleType to)
+>   -- check unboxing: wrapped composite
+>   || recurseTransFrom (unboxedSetOfType from)
+>   || recurseTransTo (unboxedSetOfType to)
+>   -- check composites compatible by comparing attribute types
+>   || case (getCompositeTypes from
+>           ,getCompositeTypes to) of
+>        -- zip almost does the right thing here, needs a bit of tweaking
+>        (Just ft, Just tt) | length ft == length tt -> all (uncurry $ castableFromTo cat cc) $ zip ft tt
+>        _ -> False
+>   where
+>
+>     getCompositeTypes (NamedCompositeType n) =
+>         Just $ map (teType . snd) $ either (const []) id  $ catCompositePublicAttrs cat [] n
+>     getCompositeTypes (CompositeType t) = Just $ map (teType . snd) t
+>     getCompositeTypes (AnonymousCompositeType t) = Just t
+>     getCompositeTypes (Pseudo (Record Nothing)) = Nothing
+>     getCompositeTypes (Pseudo (Record (Just t))) = getCompositeTypes t
+>     getCompositeTypes _ = Nothing
+>
+>     isCompOrSetoOfComp (Pseudo (SetOfType c)) = isCompositeType c
+>     isCompOrSetoOfComp c = isCompositeType c
+>
+>     unboxedSingleType (Pseudo (SetOfType (CompositeType [(_,t)]))) = Just $ teType t
+>     unboxedSingleType (Pseudo (Record (Just t))) = unboxedSingleType t
+>     unboxedSingleType _ = Nothing
+>
+>     unboxedSetOfType (Pseudo (SetOfType a)) = Just a
+>     unboxedSetOfType (Pseudo (Record (Just t))) = unboxedSetOfType t
+>     unboxedSetOfType _ = Nothing
+>
+>     recurseTransFrom = maybe False (flip (castableFromTo cat cc) to)
+>     recurseTransTo = maybe False (castableFromTo cat cc from)
+>
+> replaceWithBase :: Catalog -> Type -> Type
+> replaceWithBase cat t@(DomainType _) = either (error . show) id $ catDomainBaseType cat t
+> replaceWithBase _ t = t
diff --git a/src/Database/HsSqlPpp/Internals/TypeChecking/TypeConversion/SqlTypeConversion.lhs b/src/Database/HsSqlPpp/Internals/TypeChecking/TypeConversion/SqlTypeConversion.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/TypeChecking/TypeConversion/SqlTypeConversion.lhs
@@ -0,0 +1,77 @@
+
+Code for the sql server type conversion rules (and implicit/explicit
+casting)
+
+The plan is to follow the same functions as postgresql support for now:
+
+findCallMatch
+resolveResultSetType
+checkAssignmentValid
+
+The rules in sql server for implicit casting and function resolution
+are quite different to postgresql. The biggest one is that e.g. select
+cast(1 as int) + cast('2' as varchar(20)) works in sql server but not
+in postgresql.
+
+
+just hack for operators for now: if one argument is a number type, and
+the other is a text type, then cast the text to number.
+
+> {-# LANGUAGE PatternGuards,OverloadedStrings #-}
+> module Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.SqlTypeConversion (
+>                        findCallMatch
+>                       ) where
+>
+> --import Data.Maybe
+> --import Data.List
+> --import Data.Either
+> --import Debug.Trace
+> --import Data.Char
+> --import Control.Monad
+>
+> import Database.HsSqlPpp.Internals.TypesInternal
+> import Database.HsSqlPpp.Internals.Dialect
+> import Database.HsSqlPpp.Internals.Catalog.CatalogInternal
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+> --import Database.HsSqlPpp.Utils.Utils
+> --import Database.HsSqlPpp.Internals.TypeChecking.OldTediousTypeUtils
+> import qualified Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.OldTypeConversion as T
+> import Data.Text (Text)
+
+> findCallMatch :: Dialect -> Catalog -> Text -> [Type] ->  Either [TypeError] OperatorPrototype
+> findCallMatch d cat fnName argsType =
+>   case argsType of
+>      [_a,_b] | Just x <- checkOperator d cat fnName argsType -> Right x
+>      _ -> T.findCallMatch d cat fnName argsType
+
+hack to allow implicit casting one of the args to a numeric operator
+from a text type to the correct numeric type:
+
+check is an operator
+check on arg is numeric, the other text
+match an exact operator itself with two args the same numeric type
+- in this case, cast the text arg to the numeric type and return a match
+
+
+> checkOperator :: Dialect -> Catalog -> Text -> [Type] -> Maybe OperatorPrototype
+> checkOperator d cat fnName [a,b] | Just t <- ty a b =
+>   -- have the argument type in t
+>   -- find all the matching fns by name
+>   let nm = catLookupFns cat fnName
+>   -- keep the ones which have exactly two args with the
+>   -- type t, only proceed if there is onne match
+>       cands = filter (\(_,as,_,_) -> as == [t,t]) nm
+>   in case cands of
+>        [c] -> return c
+>        _ -> Nothing
+>   where
+>     ty a' b' | isNumber a' && isText b' = Just a'
+>     ty a' b' | isText a' && isNumber b' = Just b'
+>     ty _ _ = Nothing
+>     isNumber x =
+>       x `elem` (map ScalarType $ diNumberTypes d)
+>     --isNumber _ = False
+>     isText x =
+>       x `elem` (map ScalarType $ diTextTypes d)
+>     --isText _ = False
+> checkOperator _ _ _ _ = Nothing
diff --git a/src/Database/HsSqlPpp/Internals/TypeChecking/TypeConversion/TypeConversion.lhs b/src/Database/HsSqlPpp/Internals/TypeChecking/TypeConversion/TypeConversion.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/TypeChecking/TypeConversion/TypeConversion.lhs
@@ -0,0 +1,662 @@
+
+
+This file contains the functions for resolving types and
+function/operator resolution (which is seriously crazy). See the pg
+manual chapter 10:
+
+http://www.postgresql.org/docs/8.4/interactive/typeconv.html
+
+sql server todo: want to match sql server implicit cast rules better
+when doing tsql type checking. Follows a completely different approach, possible info here:
+http://msdn.microsoft.com/en-us/library/ms187928.aspx
+http://msdn.microsoft.com/en-us/library/ms190309.aspx
+linked from here:
+http://blogs.msdn.com/b/craigfr/archive/2010/01/20/more-on-implicit-conversions.aspx
+
+
+TODO: rewrite
+Wrappers to zap:
+
+tcAppLike
+matchApp
+matchAppExtra
+resolveResultSetType
+resolveResultSetTypeExtra
+findcallmatch
+resolveresultsettype
+checkassignments
+
+We should have one function for each of the resolvers (3 just like
+postgres) all the nullability, precision, dialect and special hacks
+should all be in one place.
+
+> {-# LANGUAGE OverloadedStrings, TupleSections, MultiWayIf,FlexibleInstances,ScopedTypeVariables #-}
+> module Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.TypeConversion
+>     (matchApp
+>     ,matchAppExtra
+>     ,tcAppLike
+>     ,resolveResultSetType
+>     ,resolveResultSetTypeExtra
+>     ,checkAssignmentValid
+>     ,MatchAppLiteralList -- (..)
+>     ) where
+>
+> import Data.Maybe
+> import Data.List
+> import Data.Either
+> import Data.Char
+>
+> import Database.HsSqlPpp.Internals.TypesInternal
+> --import Database.HsSqlPpp.Internals.Catalog.CatalogInternal
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+> import Database.HsSqlPpp.Internals.Utils
+> import Control.Monad
+> import Control.Applicative
+> import Control.Arrow
+
+> import Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.OldTypeConversion
+> import Database.HsSqlPpp.Internals.Dialect
+> import qualified Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.SqlTypeConversion as TSQL
+> import Data.Text ()
+> import qualified Data.Text as T
+> import Text.Printf
+> --import Debug.Trace
+
+******************************************************************
+
+matchApp: takes the function name and argument types, and returns the
+matching operator/function
+
+This needs a lot more tests
+
+> type MatchAppLiteralList = [Maybe Int]
+
+> matchApp :: Dialect
+>          -> Catalog
+>          -> [NameComponent]
+>          -> [Type]
+>          -> Either [TypeError] ([Type],Type)
+> matchApp d cat nmcs =
+>     ambiguityResolver $ matchApp' d nmcs
+>   where
+>     -- matchApp' a b c | trace (show (a,b,c)) False = undefined
+>     -- hack in support for sql server datediff function
+>     -- need to think of a better way to handle this when
+>     -- have a better idea of all the weird syntax used in
+>     -- tsql
+>     -- this is a todo since currently the sql server dialect uses
+>     -- postgresql type names, and this is about to be fixed
+>     matchApp' (Dialect {diSyntaxFlavour = SqlServer})
+>                   [Nmc dd] [_
+>                                  ,ScalarType "date"
+>                                  ,ScalarType "date"]
+>       | map toLower dd == "datediff" =
+>       -- check there are 3 args
+>       -- first is identifier from list
+>       -- other two are date types
+>       Right ([ScalarType "int4",ScalarType "date",ScalarType "date"], ScalarType "int4")
+>     matchApp' (Dialect {diSyntaxFlavour = SqlServer}) [Nmc dd] [_,ScalarType "date"]
+>       | map toLower dd == "datepart" =
+>       Right ([ScalarType "int4",ScalarType "date"], ScalarType "int4")
+
+>     matchApp' (Dialect {diSyntaxFlavour = SqlServer}) [Nmc dd] [_,ScalarType "timestamp"]
+>       | map toLower dd == "datepart" =
+>       Right ([ScalarType "int4",(ScalarType "timestamp")], ScalarType "int4")
+
+
+>     matchApp' (Dialect {diSyntaxFlavour = SqlServer}) [Nmc dd] [_,_,ScalarType "date"]
+>       | map toLower dd == "dateadd" =
+>       Right ([ScalarType "int4",ScalarType "int4",ScalarType "date"], ScalarType "date")
+
+>     matchApp' (Dialect {diSyntaxFlavour = SqlServer}) [Nmc dd] [_,_,ScalarType "timestamp"]
+>       | map toLower dd == "dateadd" =
+>       Right ([ScalarType "int4",ScalarType "int4",ScalarType "timestamp"], ScalarType "timestamp")
+
+double hack: support oracle decode when in tsql mode:
+
+>     matchApp' (Dialect {diSyntaxFlavour = SqlServer}) [Nmc dd] as
+>       | map toLower dd == "decode" =
+
+decode is just syntax for simple case statement:
+demand at least 3 arguments
+get the type of the first argument: this is the test target
+
+>       case as of
+>         (tt:as'@(_:_:_)) -> do
+
+for each pair of arguments following: check the first
+one can be compared to the test target
+
+collect all the second types
+if there is a single trailing argument this is the else
+
+>             let checkBranches [] acc = return $ reverse acc
+>                 checkBranches [els] acc = return $ reverse (els:acc)
+>                 checkBranches (w:t:xs) acc = do
+>                   _ <- matchApp' d [Nmc "="] [tt,w]
+>                   checkBranches xs (t:acc)
+>             sndTypes <- checkBranches as' []
+
+check the seconds types + the else for type compatilibility
+return this type
+todo: add the implicit casting where needed
+
+>             (as,) <$> resolveResultSetType cat sndTypes
+
+
+>         _ -> Left [NoMatchingOperator (T.pack dd) as]
+
+
+
+>     matchApp' d' nmcs' pts = {-trace ("matchapp: " ++ show (d,nmcs,pts)) $ -} do
+>       (_,ps,r,_) <- case d' of
+>                       (Dialect {diSyntaxFlavour = SqlServer}) -> TSQL.findCallMatch d' cat nm pts
+>                       _ -> findCallMatch d' cat nm pts
+>       return (ps,r)
+>       where
+>         nm = case last nmcs' of
+>                Nmc n -> T.pack $ map toLower n
+>                QNmc n -> T.pack n
+>                AntiNameComponent _ -> -- todo: use left instead of error
+>                  error "tried to find function matching an antinamecomponent"
+
+hack to support literal arguments to overloaded functions
+  currently, the problem arises only for date/datetime arguments
+  the solution reflects this
+for long argument lists with several literals, there can be a lot of variants generated, but
+  this shouldn't slow down the execution because lazyness composes well with the functions used
+
+> ambiguityResolver:: ([Type] -> Either [TypeError] ([Type],Type))
+>                     -> [Type] -> Either [TypeError] ([Type],Type)
+> ambiguityResolver f ts =  let rs :: [Either [TypeError] ([Type], Type)]
+>                               rs = map f $ expandList variants ts
+>                           -- this is needed in order to preserve the original error
+>                           --  in case when all the attempts fail
+>                           in case rights rs of
+>                                  x:_ -> Right x
+>                                  [] -> head rs
+>   where
+>     variants t = case t of
+>         UnknownType -> [t, ScalarType "timestamp"]
+>         _ -> [t]
+>     -- similar to handling of superaggregates
+>     -- ToDo: move to a general library
+>     expandList:: (a -> [a]) -> [a] -> [[a]]
+>     expandList f' = foldr (liftM2 (:) . f') [[]]
+
+------------- precision and nullability of function application --------------
+
+uses matchApp for inferring basic types
+
+> matchAppExtra :: Dialect
+>                 -> Catalog
+>                 -> [NameComponent]
+>                 -> MatchAppLiteralList
+>                 -> [TypeExtra]
+>                 -> Either [TypeError] ([TypeExtra],TypeExtra)
+> matchAppExtra dialect cat nmcs lits tes = {-trace ("mae" ++ show (nmcs,tes)) $ -} do
+>     (ts',t') <- matchApp dialect cat nmcs $ map teType tes
+>     tes' <- joinArgsExtra appName tes $ zipWith addArgExtra tes ts'
+>     return (tes', addResultExtra appName tes' t' lits)
+>   where
+>     addArgExtra te t = te {teType = t}
+>     appName = case nmcs of
+>       [Nmc dd] -> map toLower dd
+>       _ -> ""
+
+precision and nullability of the result
+
+> addResultExtra:: String -> [TypeExtra] -> Type -> MatchAppLiteralList -> TypeExtra
+> addResultExtra appName tes t lits = checkPrecisionRelevance . checkResultPrecisionClass tesr
+>                                 $ TypeExtra t jp js jn
+>   where
+>     jp = if
+>       | appName == "||" -> Just $ sum $ mapMaybe tePrecision tesr
+>       | appName == "substring" ->
+>            -- Substring is an interesting case. If we have both the
+>            -- start and length as literals, we can figure out the resulting precision
+>            -- Otherwise, treat as before with joinPrecision
+>            let totalLen = joinPrecision $ map tePrecision tesr
+>            in case (map teType tesr) of
+>              [ScalarType "nvarchar"] -> totalLen
+>              _ ->
+>                  case lits of
+>                    (Nothing:(Just startPos):(Just len):_) -> do
+>                       totalLen' <- totalLen
+>                       return $ if startPos + len > totalLen' then totalLen' - startPos else len
+>                    _ -> totalLen
+
+>         -- precision of the result is unknown
+>       | appName `elem` ["replace"] -- is actually known for 2-argument "replace"
+>         -> Nothing
+>       | otherwise
+>         -> joinPrecision $ map tePrecision tesr
+>     js = joinScale $ map teScale tesr
+>     jn = if
+>       | appName `elem`
+>           ( ["isnotnull","isdate","isnumeric"]
+>               -- standard "is null" expression
+>             ++ ["isnull" | length tes == 1]
+>               -- currently, aggregate functions are handled as scalar functions
+>             ++ ["count","count_big"])
+>         -> False
+>       | appName `elem`
+>           ( ["coalesce","greatest","least"]
+>               -- 2-argument function "isnull" of SqlServer
+>               -- ImplicitCastToDo: isnull has quite complex cast rules,
+>               --    not really reflected here and in the cast of arguments
+>             ++ ["isnull" | length tes == 2]
+>               -- nullability of corresponding SqlServer function "charindex"
+>               --  may or may not differ, depending on database compatibility level
+>               -- I implement the level above 70, so it goes to the default case
+>             ++ ["strpos","position"])
+>         -> all teNullable tesr
+>         -- can produce null independently on the nullability of the arguments
+>         -- ImplicitCastToDo: check again: doesn't it depend on the presence of "else" part
+>       | appName `elem` ["case","decode","nullif","replicate"]
+>         -> True
+>         -- the default
+>       | appName `elem` ["substr","substring"] -> any teNullable tes
+>       | otherwise -> joinNullability $ map teNullable tesr
+>     -- arguments that participate in the inference of the result type
+>     tesr = case appName of
+>       "decode" -> caseResultTypes tes
+>           -- only the first argument influences precision and nullability
+>       _ | appName `elem` ["nullif","substr","substring","left","right","ltrim","rtrim","replicate","translate","like","notlike","rlike"]
+>           -> take 1 tes
+>           -- the first two arguments influence
+>         | appName `elem` ["charindex"]
+>           -> take 2 tes
+>           -- the first argument doesn't influence
+>         | appName `elem` ["datepart","datediff"]
+>           -> drop 1 tes
+>           -- the first two arguments don't influence
+>         | appName `elem` ["dateadd"]
+>           -> drop 2 tes
+>       -- the default case
+>         | otherwise -> tes
+>     -- tail is safe here because matchApp did all the checks
+>     caseResultTypes tes' = caseResultTypes' (tail tes') []
+>       where
+>         caseResultTypes' [] acc = acc
+>         caseResultTypes' [els] acc = els:acc
+>         caseResultTypes' (_:t':xs) acc = caseResultTypes' xs (t':acc)
+
+------------- cast of arguments --------------
+
+Bring relevant arguments of a function to common precision and nullability.
+The meaning of "relevant" is complicated:
+  - the list of arguments is split into partitions;
+  - precision and nullability is partition-wise joined;
+  - the results are broadcast back to the arguments that constituted partitions.
+The algorithm follows this outline.
+Examples:
+  - for binary operators, like "=", both arguments constitute a single partition;
+  - for some functions, like "substr", each argument belongs to its own partition;
+  - arguments of "case" and "decode" form two partitions which, except for the analyzed value
+    and the 'else' argument, are intervened with one another.
+Actually, partitions for precision and partitions for nullability can be different.
+Example:
+  "||": both arguments must be brought to common nullability, but remain with same precision.
+Additionaly:
+  Before splitting onto partitions, check each argument for:
+    - precision class of the original (before matchApp) argument;
+    - precision relevance.
+  After splitting onto partitions, check each precision partition:
+    - all arguments must have same precision class (return an error if they don't).
+
+What the is this function doing? What is it for?
+
+> joinArgsExtra:: String -> [TypeExtra] -> [TypeExtra] -> Either [TypeError] [TypeExtra]
+> joinArgsExtra "!odbc-left" _t0 t1 = Right t1
+> joinArgsExtra "!odbc-timestampdiff" _t0 t1 = Right t1
+> joinArgsExtra "!odbc-timestampadd" _t0 t1 = Right t1
+
+> joinArgsExtra appName tes0 tes1
+>     = liftM (uncurry $ zipWith3 combine tes) $ uncurry (liftM2 (,))
+>       $ (joinDim joinPrec partitionPrec &&& joinDim joinNull partitionNull) tes
+>   where
+>     -- checks and adjustments before partitioning
+>     tes = map checkPrecisionRelevance
+>           $ zipWith adjust tes0
+>           $ zipWith checkPrecisionClass tes0 tes1
+>       where
+>         adjust te0 te1 = te1{tePrecision = head $ adjustStringCastPrec (teType te1) [te0]}
+>     -- checks after partitioning
+>     checkPartition ptes = if length (nub ppcs) > 1
+>         then Left [InternalError $ printf "implicit cast: arguments of '%s' that belong to same partition are of different precision classes: %s -> %s" appName (show ptes) (show ppcs)]
+>         else return ptes
+>       where
+>         ppcs = map (precisionClass . teType) ptes
+>     -- the algorithm for a single partitioning dimension
+>     joinDim:: ([TypeExtra] -> [TypeExtra])
+>               -> ([TypeExtra] -> Either [TypeError]
+>                                         ([[TypeExtra]] -> [TypeExtra], [[TypeExtra]]))
+>               -> [TypeExtra] -> Either [TypeError] [TypeExtra]
+>     joinDim join' partitionArgs'
+>         = liftM (uncurry ($) . second (map join')) . partitionArgs'
+>     -- combine results for precision and nullability
+>     combine te tePrec teNull = te {
+>       tePrecision = tePrecision tePrec,
+>       teScale = teScale tePrec,
+>       teNullable = teNullable teNull
+>     }
+>     -- joins of precision and nullability partitions
+>     joinPrec tes' = map promote tes'
+>       where
+>         promote (TypeExtra t p s n) = TypeExtra t (p' `mplus` p) (s' `mplus` s) n
+>         p' = joinPrecision $ map tePrecision tes
+>         s' = joinScale $ map teScale tes
+>     joinNull tes' = map promote tes'
+>       where
+>         promote (TypeExtra t p s n) = TypeExtra t p s (n' || n)
+>         n' = joinNullability $ map teNullable tes
+>     -- the partitioning functions return partitions paired with a function
+>     --    that puts them back into their places
+>     -- because, in many cases, partitions for precision and for nullability are the same,
+>     --    the partitioning code for such cases is factored out
+>     partitionArgs:: [a] -> ([[a]] -> [a], [[a]])
+>     partitionArgs as = case () of
+>             -- functions whose arguments are independent
+>             --  instead of splitting into partitions, just return the original list
+>         _ | appName `elem`
+>               ( ["datepart","dateadd"]
+>                 ++ ["substr","substring","left","right","ltrim","rtrim"]
+>                 ++ ["replicate","like","notlike","rlike"]
+>                 ++ ["strpos","position","replace"]
+>                     -- Oracle joins the datatypes (needed for the comparison)
+>                 ++ ["nullif"]
+>                 -- SQream specific regex functions
+>                 ++ ["regexp_substr","regexp_count","regexp_instr"]
+>                 ++ ["string_agg"]
+>               )
+>             -> (const as, [])
+>             -- first argument is special, the rest are processed together
+>           | appName `elem` ["datediff"]
+>             -> (concat, pairToList $ splitAt 1 as)
+>           | appName `elem` ["decode"]
+>             ->  let (ws,ts) = decomposeDecodeTail (tail as) ([],[])
+>                 in (composeDecodePartitions, [head as :ws, ts])
+>             -- the default is to return a single partition
+>           | otherwise -> (concat, [as])
+>     partitionPrec as = secondM (mapM checkPartition) $ case () of
+>             -- independent arguments
+>         _ | appName `elem` ["||","concat","translate","charindex"]
+>             -> (const as, [])
+>             -- single partition
+>           | appName `elem`
+>               ( ["coalesce","greatest","least"]
+>                     -- ImplicitCastToDo: think how to handle this properly
+>                 ++ ["isnull" | length as == 2]
+>               )
+>             -> (concat, [as])
+>           | otherwise -> partitionArgs as
+>     partitionNull as = return $ case () of
+>         _ | appName `elem`
+>               ( ["coalesce","greatest","least"]
+>                 ++ ["isnull" | length as == 2]
+>               )
+>             -> (const as, [])
+>           | appName `elem` ["charindex"]
+>             -> (concat, pairToList $ splitAt 2 as)
+>           | otherwise -> partitionArgs as
+>     -- utility
+>     pairToList (x,y) = [x,y]
+>     decomposeDecodeTail [] acc = (reverse***reverse) acc
+>     decomposeDecodeTail [els] acc = (reverse.(els:)***reverse) acc
+>     decomposeDecodeTail (w:t:xs) acc = decomposeDecodeTail xs $ ((w:)***(t:)) acc
+>     composeDecodePartitions [t:ts,ws] = t : concat (transpose [ts,ws])
+>     -- redundant
+>     composeDecodePartitions xs = concat xs
+
+------------- precision class --------------
+
+This is a small library for checking whether inference of precision does make sense.
+It is used both in inference of precision of arguments and result of a function.
+
+It is theoretically possible that types belong to different precision classes,
+    but inference of precision still makes sense (consider, for instance,
+    conversion between string and decimal).
+  Such cases must be handled specially.
+
+> data PrecisionClass = String | Number | FlexiblePrecisionClass
+>       deriving (Eq,Show)
+>
+> precisionClass:: Type -> Maybe PrecisionClass
+> precisionClass (ScalarType tn)
+>   | tn `elem` ["text","varchar","nvarchar","char"] = Just String
+>   | tn `elem` ["int1","int2","int4","int8","float4","float8","numeric"] = Just Number
+>   | otherwise = Nothing
+> precisionClass UnknownType = Just FlexiblePrecisionClass
+> precisionClass _ = Nothing
+
+Do original and new type have compatible precision classes?
+Note: this function is not commutative.
+
+> infix 4 .~>.
+> (.~>.):: TypeExtra -> TypeExtra -> Bool
+> t0 .~>. t = Just FlexiblePrecisionClass `elem` [pc0,pc] || pc0 == pc
+>   where
+>     [pc0,pc] = map (precisionClass . teType) [t0,t]
+
+retreat to default when original and new type are incompatible
+
+> checkPrecisionClass:: TypeExtra -> TypeExtra -> TypeExtra
+> checkPrecisionClass t0 t = if t0 .~>. t then t else t{tePrecision = Nothing, teScale = Nothing}
+
+check precision class of result against precision classes of arguments
+
+> checkResultPrecisionClass:: [TypeExtra] -> TypeExtra -> TypeExtra
+> checkResultPrecisionClass tes t
+>   = if and $ map (.~>. t) tes then t else t{tePrecision = Nothing, teScale = Nothing}
+
+check whether precision/scale is relevant for a type (consider "round").
+
+> checkPrecisionRelevance:: TypeExtra -> TypeExtra
+> checkPrecisionRelevance te = if
+>   | Just String <- pc
+>     -> te{teScale = Nothing}
+>   | Just FlexiblePrecisionClass <- pc
+>     -> te
+>   | ScalarType tn <- t, tn == "numeric"
+>     -> te
+>   | otherwise
+>     -> te{tePrecision = Nothing, teScale = Nothing}
+>   where
+>     t = teType te
+>     pc = precisionClass t
+
+
+The purpose of the tcapplike wrapper is to partially fix up the
+keyword 'enums' in some of the ms style functions (like
+datepart). This is a horrible hack and will be fixed.
+
+> tcAppLike :: Dialect -> Catalog -> [NameComponent]
+>            -> [Maybe Int] -> [Maybe TypeExtra]
+>            -> Either [TypeError] ([TypeExtra],TypeExtra)
+
+> tcAppLike d cat anm@[Nmc dd] lits [_,a0,a1]
+>     | map toLower dd == "datediff" = do
+>   -- dodgy hack for datediff
+>   tys <- mapM (maybe (Left []) Right) [a0,a1]
+>   typeInt <- ScalarType <$> maybe (Left []) Right
+>              (ansiTypeNameToDialect d "int")
+>   let --Name _ ns = anm
+>   (ats,rt) <- matchAppExtra d cat anm lits (mkTypeExtraNN typeInt : tys)
+>   return (ats,rt)
+> tcAppLike d cat anm@[Nmc dd] lits [_,a0]
+>     | map toLower dd == "datepart" = do
+>   tys <- mapM (maybe (Left []) Right) [a0]
+>   typeInt <- ScalarType <$> maybe (Left []) Right
+>              (ansiTypeNameToDialect d "int")
+>   (ats,rt) <- matchAppExtra d cat anm lits (mkTypeExtraNN typeInt : tys)
+>   return (ats,rt)
+> tcAppLike d cat anm@[Nmc dd] lits [_,a0,a1]
+>     | map toLower dd == "dateadd" = do
+>   tys <- mapM (maybe (Left []) Right) [a0,a1]
+>   typeInt <- ScalarType <$> maybe (Left []) Right
+>              (ansiTypeNameToDialect d "int")
+>   (ats,rt) <- matchAppExtra d cat anm lits (mkTypeExtraNN typeInt : tys)
+>   return (ats,rt)
+
+> --tcAppLike d cat anm@(Name _ [Nmc dd]) a b
+> --    |  trace ("xz: " ++ show (a,b)) False = undefined
+
+> tcAppLike d cat anm@[Nmc dd] _ ts
+>     | map toLower dd == "!odbc-convert" = do
+>                  (tys :: [TypeExtra]) <- mapM (maybe (Left []) Right) ts
+>                  --let Name _ ns = anm
+>                  (ats,rt) <- matchAppExtra d cat anm [] tys
+>                  return (ats,rt)
+
+> tcAppLike d cat anm@[Nmc dd] _ [_,a0,a1]
+>     | map toLower dd `elem` ["!odbc-timestampadd","!odbc-timestampdiff"] = do
+>   tys <- mapM (maybe (Left []) Right) [a0,a1]
+>   --let Name _ ns = anm
+>   typeInt <- ScalarType <$> maybe (Left []) Right
+>              (ansiTypeNameToDialect d "int")
+>   (ats,rt) <- matchAppExtra d cat anm [] (mkTypeExtraNN typeInt : tys)
+>   return (ats,rt)
+
+> tcAppLike d cat anm lits teArgs = do
+>   -- get the types of the arguments
+>   -- then lookup in TypeConversion.matchAppExtra
+>   tys <- mapM (maybe (Left []) Right) teArgs
+>   (ats,rt) <- matchAppExtra d cat anm lits tys
+>   return (ats,rt)
+
+
+******************************************************************
+
+ findCallMatch :: Catalog -> String -> [Type] ->  Either [TypeError] OperatorPrototype
+ findCallMatch cat fnName' argsType =
+
+code interspersed with text cut and pasted from postgresql manual
+10.3. Functions
+
+Function Type Resolution
+
+Select the functions to be considered from the pg_proc system
+catalog. If a non-schema-qualified function name was used, the
+functions considered are those with the matching name and argument
+count that are visible in the current search path (see Section
+5.7.3). If a qualified function name was given, only functions in the
+specified schema are considered.
+
+[HsSqlPpp doesn't support schema stuff yet, so just get a list of all
+the functions with a matching name]
+
+>   {-let matchingNames = catGetOpsMatchingName cat nmcs
+>       exactMatches = filter (\(_,ts,_,_) -> ts == pts) matchingNames
+>   case exactMatches of
+>     [(_,tys,rt,_)] -> return (tys, rt)
+>     [] -> error $ "no matching fn: " ++ show nmcs
+>                   ++ "(" ++ intercalate "," (map show pts) ++ ")"
+>     _xs -> error "ambiguous"-}
+
+
+
+If the search path finds multiple functions of identical argument
+types, only the one appearing earliest in the path is
+considered. Functions of different argument types are considered on an
+equal footing regardless of search path position.
+
+If a function is declared with a VARIADIC array parameter, and the
+call does not use the VARIADIC keyword, then the function is treated
+as if the array parameter were replaced by one or more occurrences of
+its element type, as needed to match the call. After such expansion
+the function might have effective argument types identical to some
+non-variadic function. In that case the function appearing earlier in
+the search path is used, or if the two functions are in the same
+schema, the non-variadic one is preferred.
+
+Functions that have default values for parameters are considered to
+match any call that omits zero or more of the defaultable parameter
+positions. If more than one such function matches a call, the one
+appearing earliest in the search path is used. If there are two or
+more such functions in the same schema with identical parameter types
+in the non-defaulted positions (which is possible if they have
+different sets of defaultable parameters), the system will not be able
+to determine which to prefer, and so an "ambiguous function call"
+error will result if no better match to the call can be found.
+
+Check for a function accepting exactly the input argument types. If
+one exists (there can be only one exact match in the set of functions
+considered), use it. (Cases involving unknown will never find a match
+at this step.)
+
+If no exact match is found, see if the function call appears to be a
+special type conversion request. This happens if the function call has
+just one argument and the function name is the same as the (internal)
+name of some data type. Furthermore, the function argument must be
+either an unknown-type literal, or a type that is binary-coercible to
+the named data type, or a type that could be converted to the named
+data type by applying that type's I/O functions (that is, the
+conversion is either to or from one of the standard string
+types). When these conditions are met, the function call is treated as
+a form of CAST specification. [1]
+
+Look for the best match.
+
+Discard candidate functions for which the input types do not match and
+cannot be converted (using an implicit conversion) to match. unknown
+literals are assumed to be convertible to anything for this
+purpose. If only one candidate remains, use it; else continue to the
+next step.
+
+Run through all candidates and keep those with the most exact matches
+on input types. (Domains are considered the same as their base type
+for this purpose.) Keep all candidates if none have exact matches. If
+only one candidate remains, use it; else continue to the next step.
+
+Run through all candidates and keep those that accept preferred types
+(of the input data type's type category) at the most positions where
+type conversion will be required. Keep all candidates if none accept
+preferred types. If only one candidate remains, use it; else continue
+to the next step.
+
+If any input arguments are unknown, check the type categories accepted
+at those argument positions by the remaining candidates. At each
+position, select the string category if any candidate accepts that
+category. (This bias towards string is appropriate since an
+unknown-type literal looks like a string.) Otherwise, if all the
+remaining candidates accept the same type category, select that
+category; otherwise fail because the correct choice cannot be deduced
+without more clues. Now discard candidates that do not accept the
+selected type category. Furthermore, if any candidate accepts a
+preferred type in that category, discard candidates that accept
+non-preferred types for that argument.
+
+If only one candidate remains, use it. If no candidate or more than
+one candidate remains, then fail.
+
+
+
+
+exact match
+binop1unknownmatch
+polymorphic matches
+reachable
+mostexactmatches
+filteredforpreferred
+unknownmatchesbycat
+
+
+
+TODO: do a log monad, which can record the tests and then return this
+process along with the resolved function
+
+
+--------------------------------
+todo:
+
+> {-resolveResultSetType :: Catalog -> [Type] -> Either [TypeError] Type
+> resolveResultSetType _cat [] = error "resolveResultSetType: empty type set"
+> resolveResultSetType _cat (t:ts) =
+>   if all (==t) ts
+>   then Right t
+>   else Left [IncompatibleTypeSet (t:ts)]-}
+
+todo:
+
+assignmentCheck
diff --git a/src/Database/HsSqlPpp/Internals/TypeChecking/TypeConversion/TypeConversion2.lhs b/src/Database/HsSqlPpp/Internals/TypeChecking/TypeConversion/TypeConversion2.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/TypeChecking/TypeConversion/TypeConversion2.lhs
@@ -0,0 +1,550 @@
+
+
+TODO: most of this code will move to the internals type conversion.
+rewrite the code to be nice and literate explaining everything
+
+> {-# LANGUAGE OverloadedStrings,LambdaCase,MultiWayIf,PatternGuards #-}
+> module Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.TypeConversion2
+>        (matchApp,LitArg(..)) where
+
+TODO: explicit imports
+
+> import Control.Monad
+> --import Control.Applicative
+> --import Control.Arrow
+
+> import Data.Text ()
+> import qualified Data.Text as T
+> import Data.Maybe
+> import Data.List
+> import Data.Either
+> import Data.Char
+> import Control.Arrow
+
+> import Text.Show.Pretty
+> import Debug.Trace
+
+> import Database.HsSqlPpp.Internals.TypesInternal
+> import Database.HsSqlPpp.Internals.Catalog.CatalogInternal
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+> --import Database.HsSqlPpp.Internals.Catalog.DefaultTemplate1Catalog
+> --import Database.HsSqlPpp.Utils.Utils
+
+> -- import Database.HsSqlPpp.Internals.TypeChecking.OldTypeConversion
+> import Database.HsSqlPpp.Internals.Dialect
+> -- import qualified Database.HsSqlPpp.Internals.TypeChecking.SqlTypeConversion as TSQL
+
+
+three kinds of type conversion where we might have to insert implicit
+casts:
+
+function overload resolution
+result set type resolution
+is assignment valid
+
+The arg types take a LitArg since we want to say the result type of e.g.
+substring(x from 2 for 3) as varchar(3), but if we get
+substring(x from a for b) then we don't know the precision from the
+for part (but it can't be bigger than the x)
+
+It also supports stuff like odbc convert whose return type depends on
+the identifier in the second parameter.
+
+for the special cases for null and precision, have a map of functions
+from the function name to the special case transform function which
+modifies the return type. Then can try to isolate the special cases a
+little bit -> probably need some other special cases, add hooks and
+maps of functions for these too
+
+> data LitArg = NumLitArg String
+>             | StringLitArg String
+>             | NullLitArg
+>             | BooleanLitArg Bool
+>               deriving (Show,Eq)
+>               -- todo: add other literals if needed
+
+
+> type MyFunType = (CatName, [Type], Type, Bool)
+
+match app matches a function + argument types, and determines (using a
+bunch of hacks and special cases) the precision, scale and nullability
+of the result type also.
+
+> matchApp :: Dialect
+>          -> Catalog
+>          -> [NameComponent]
+>          -> [(TypeExtra, Maybe LitArg)]
+>          -> Either [TypeError] ([TypeExtra],TypeExtra)
+> matchApp d cat appName argTypes = do
+>      x <- findMatchingApp d cat appName
+>                    (map (first teType) argTypes)
+>      return $ fixNP x
+>   where
+
+todo: fix nulls and precision
+
+precision and scale:
+
+default is to match the precision and scale of any matching input args
+or to choose the default for that type
+
+for nulls: default is to assume function produces nullable if any
+input args are nullable, and doesn't produce nullable otherwise
+
+>     fixNP :: MyFunType -> ([TypeExtra],TypeExtra)
+>     fixNP (_,ts,r,_) =
+>         let anyInputsNull = isJust $ find (teNullable . fst) argTypes
+>             -- copy nullability of input types
+>             carryNulls = zipWith (\(a,_) b -> lt b $ teNullable a)
+>                          argTypes ts
+>         in (carryNulls, lt r anyInputsNull)
+>     lt ty n = TypeExtra ty Nothing Nothing n
+
+
+find matching app is the code which matches a function prototype to a
+list of input argument types, dealing with implicit casts and
+overloaded functions. It is based on the algorithm in postgresql.
+
+> findMatchingApp :: Dialect
+>                 -> Catalog
+>                 -> [NameComponent]
+>                 -> [(Type, Maybe LitArg)]
+>                 -> Either [TypeError] (CatName,[Type],Type,Bool)
+> findMatchingApp _d cat appName argTypes =
+>     (\case
+>         -- represents a short cut error
+>         Left (Left e) -> Left e
+>         -- represents a short cut valid result
+>         Left (Right r) -> Right r
+>         -- represents a normal result at the end
+>         Right r -> Right r) $ do
+>     let
+
+1. get all the candidates - matching by name
+
+
+todo: variadic stuff, default stuff
+todo: if there are multiple matches with different schemas
+     only keep the matches in the first schema in the search path
+
+todo: deal with case and with schemas
+
+todo: polymorphic
+
+>         nameMatches :: [MyFunType]
+>         nameMatches = catLookupFns cat appName'
+>         -- create a map from arg types to prototype
+>         nameMatchMap :: [([Type], MyFunType)]
+>         nameMatchMap = map (\v@(_,as,_,_) -> (as,v)) nameMatches
+>         -- the raw input types to match against
+>         rawArgTypes = map fst argTypes
+
+2. if there is one candidate with the exact args - choose it
+
+>         exactMatches :: [MyFunType]
+>         exactMatches = map snd $ flip filter nameMatchMap
+>                                       ((==rawArgTypes) . fst)
+
+if this is a binary operator, and one of the types is unknown and the
+other is known, and there is onne exact match if the unknown is made
+to match the known type, then select it
+
+>         oneKnown = case rawArgTypes of
+>                        [UnknownType,UnknownType] -> Nothing
+>                        [UnknownType,t] -> Just t
+>                        [t,UnknownType] -> Just t
+>                        _ -> Nothing
+>         binaryOpKnownUnknownMatches :: [MyFunType]
+>         binaryOpKnownUnknownMatches =
+>             case () of
+>                 _ | isOperatorName appName'
+>                   , Just t <- oneKnown
+>                   -> map snd $ flip filter nameMatchMap
+>                                       ((==[t,t]) . fst)
+>                   | otherwise -> []
+
+2.5 check for type conversion function?: function name is name of type
+    only has one argument, this type is unknown or castable to target
+
+>         typeConversionMatch :: [MyFunType]
+>         typeConversionMatch = case (appName', rawArgTypes) of
+>             _ -> [] -- todo
+
+3. discard candidates which cannot be reached by implicit casts
+   convert domains to base types
+   keep only candidates which have the most exact matches
+     if one: use it
+     if none: still consider them all
+
+>         reachableViaImplicitCasts :: [MyFunType]
+>         reachableViaImplicitCasts =
+>             let candReachableViaImplicitCasts as =
+>                     length rawArgTypes == length as
+>                     && and (zipWith canImplicitCastOrSame rawArgTypes as)
+>             in map snd $ flip filter nameMatchMap
+>                (candReachableViaImplicitCasts . fst)
+
+4. keep candidates which accept the most preferred types where type
+   conversion is needed: if one, use it
+   else continue with all
+
+>         acceptsMostPreferredTypes :: [MyFunType]
+>         acceptsMostPreferredTypes =
+>             let preferredTypeCounts :: [(Int,MyFunType)]
+>                 preferredTypeCounts = flip map reachableViaImplicitCasts
+>                     $ \v@(_,as,_,_) ->
+>                            (length $ filter id $
+>                             zipWith isCastToPreferred rawArgTypes as
+>                            ,v)
+>                 maxCount = maximum $ map fst preferredTypeCounts
+>             in map snd $ filter ((==maxCount) .fst) preferredTypeCounts
+
+Keep all candidates if none accept preferred types. If only one
+candidate remains, use it; else continue to the next step.
+
+>         acceptsMostPreferredNextStep :: [MyFunType]
+>         acceptsMostPreferredNextStep =
+>             if null acceptsMostPreferredTypes
+>             then reachableViaImplicitCasts
+>             else acceptsMostPreferredTypes
+
+5. if any input types are unknown:
+for each unknown
+
+a) select string cat for each position if any cands accept string in
+that position
+
+b) if all the cands accept the same category for that position, choose
+it, otherwise fail
+
+discard any candidates not matching the selected category (this can
+only happen if string was chosen for an unknown)
+
+for each unknown, if any cands accept the preferred type in that
+position, drop all the ones which don't accept that type in that
+position
+if one left: use it
+else: keep all for next
+
+
+transpose the arguments
+calculate the category for each argument:
+  will be just string if any strings
+  will be just cat if all the same cat
+  otherwise nothing
+
+This doesn't take into account which positions are unknown in the
+input arg list yet.
+
+>         transposedCandidateArgs = transpose $ map (\(_,x,_,_) -> x)
+>                                   acceptsMostPreferredNextStep
+
+>         argumentCategories :: [Maybe T.Text]
+>         argumentCategories =
+>             let resolveTypeSetCat ts =
+>                     case () of
+>                      _ | any (==UnknownType) ts -> Just "unk"
+>                        | Right (c:cs) <- mapM (catTypeCategory cat) ts
+>                        , all (==c) cs -> Just c
+>                        | otherwise -> Nothing
+>             in map resolveTypeSetCat transposedCandidateArgs
+
+then: zip with the unknown positions
+  if we get any pairs of unknown + nothing for the cat:
+  fail with ambiguous error
+
+>         chooseCat :: Type -> Maybe T.Text
+>                   -> Either [TypeError] (Maybe T.Text)
+>         chooseCat a x = case (a,x) of
+>              (UnknownType,Nothing) ->Left [AmbiguousOperator appName' rawArgTypes]
+>              (UnknownType,Just y) -> Right (Just y)
+>              (_,_) -> Right Nothing
+>     let _argumentCategoriesNeeded :: Either [TypeError] [Maybe T.Text]
+>         _argumentCategoriesNeeded =
+>             zipWithM chooseCat rawArgTypes argumentCategories
+
+TODO: filter the cands by argument categories needed
+keep the left, if we need to use bestPreferredMatches then the left
+escapes
+
+>         {-matchesPreferredCategories =
+>             let candMatches (_,ts,_,_) cn =
+>                     catTypeCategory-}
+
+then:
+  convert the list of just cat to a list of preferred types
+  do another transpose of the remaining functions and
+  zip with the preferred type
+  keep the preferred type as just if any cands match this preferred
+   type, otherwise set to nothing
+
+>     let myIsPreferred ty = either (const False) (const True)
+>                            $ catPreferredType cat ty
+>         choosePreferredType :: [Type] -> Maybe Type
+>         choosePreferredType ts =
+>             let pts = filter myIsPreferred ts
+>             in case pts of
+>                    (t:_) -> Just t
+>                    [] -> Nothing
+
+>         preferredTypes :: [Maybe Type]
+>         preferredTypes = map choosePreferredType transposedCandidateArgs
+
+
+now have a list of just/nothings with justs for the types which have
+to match
+
+filter the cands using this just list
+now have the final best prefered match list and can
+  either return one if there is one
+  return ambiguous if there is more than one ?is this possible
+  or return ambiguous with the previous list if none get through this
+    filter
+
+>         matchesPreferred (_,ts,_,_) =
+>             let f _ Nothing = True
+>                 f t (Just pt) = t == pt
+>             in and $ zipWith f ts preferredTypes
+>         bestPreferredMatches :: [MyFunType]
+>         bestPreferredMatches =
+>             filter matchesPreferred acceptsMostPreferredNextStep
+
+>         bestPreferredMatchesNextStep :: [MyFunType]
+>         bestPreferredMatchesNextStep =
+>             if null bestPreferredMatches
+>             then acceptsMostPreferredTypes
+>             else bestPreferredMatches
+
+6. if there are unknown and known, and all the knowns are the same,
+assume the unknowns to be this type. If there is one match, use it
+
+>         hasUnknown = isJust $ find (==UnknownType) rawArgTypes
+>         allKnownsType :: Maybe Type
+>         allKnownsType =
+>             let allNonUnknowns = filter (/=UnknownType) rawArgTypes
+>             in case allNonUnknowns of
+>                    [] -> Nothing
+>                    (x:xs) | all (==x) xs -> Just x
+>                           | otherwise -> Nothing
+>         allUnknownsMatchAllKnowns :: [MyFunType]
+>         allUnknownsMatchAllKnowns =
+>             [c | c@(_,as,_,_) <- bestPreferredMatchesNextStep
+>             , hasUnknown
+>             , t <- maybeToList allKnownsType
+>             , let tys = map (\x -> case x of
+>                              UnknownType -> t
+>                              _ -> x) rawArgTypes
+>             , as == tys
+>             ]
+
+>     let showl l = show (length l) ++ "\n" ++ ppShow l
+>     let _showProcess =
+>           "Name matches: " ++ showl nameMatches
+>           ++ "\n\nRaw arg types: " ++ ppShow rawArgTypes
+>           ++ "\n\nexactMatches: " ++ showl exactMatches
+>           ++ "\n\nbinaryOpKnownUnknownMatches: " ++ showl binaryOpKnownUnknownMatches
+>           ++ "\n\ntypeConversionMatches: " ++ showl typeConversionMatch
+>           ++ "\n\nreachableViaImplicitCasts: " ++ showl reachableViaImplicitCasts
+>           -- ++ "\n\npreferredTypeCounts: " ++ showl preferredTypeCounts
+>           ++ "\n\nacceptsMostPreferredTypes: " ++ showl acceptsMostPreferredTypes
+>           ++ "\n\nbestPreferredMatches: " ++ showl bestPreferredMatches
+>           ++ "\n\nallUnknownsMatchAllKnowns: " ++ showl allUnknownsMatchAllKnowns
+
+2. exact matches
+2.1 binary operator known/unknown special case
+2.5 typeConversion matches
+4. candidate which accepts most preferred types
+5. candidate matching preferred types
+6. unknowns match knowns
+
+>     let zeroOrOne x = case x of
+>               [] -> Right ()
+>               [a] -> Left (Right a)
+>               _ -> Left (Left [AmbiguousOperator appName' rawArgTypes])
+>         oneOrContinue x = case x of
+>               [a] -> Left (Right a)
+>               _ -> Right ()
+>     trace (_showProcess) $ do
+>         zeroOrOne exactMatches
+>         zeroOrOne typeConversionMatch
+>         oneOrContinue binaryOpKnownUnknownMatches
+>         oneOrContinue reachableViaImplicitCasts
+>         oneOrContinue acceptsMostPreferredTypes
+>         oneOrContinue bestPreferredMatches
+>         oneOrContinue allUnknownsMatchAllKnowns
+
+otherwise fail
+
+TODO:
+
+When the matching errors, what are the possibilities in user
+understandable terms?
+
+1. no functions with that name match
+(could return functions with a similar name + show types)
+
+2. have functions which match the name, but the number of args is
+wrong:
+
+list the functions + show types
+should this show similarly named functions? (what about highlighting
+ones with matching arg types?)
+
+3. have functions which have the right # args, but aren't reachable
+via implicit casts
+
+could list all the functions, does it make sense to highlight the ones
+which can be reached by explicit casts (or are there basically
+explicit casts for nearly all pairs of types?)
+should this show similarly named functions?
+should this show name matches with the wrong number of args
+
+4. I think the only other one that matters is that there are functions
+which match via implicit casts, but the system cannot pick a particlar
+one
+should it also list the other possibilities as above?
+
+Fix the error to contain this information.
+
+>         Left $ Left [NoMatchingOperator appName' rawArgTypes]
+
+
+>   where
+>     -- don't use last
+>     -- check for empty list
+>     appName' = case last appName of
+>                Nmc n -> T.pack $ map toLower n
+>                QNmc n -> T.pack n
+>                AntiNameComponent _ -> -- todo: use left instead of error
+>                  error "tried to find function matching an antinamecomponent"
+>     canImplicitCastOrSame :: Type -> Type -> Bool
+>     canImplicitCastOrSame from to =
+>         from == to || isRight (catCast cat ImplicitCastContext from to)
+>     -- check if casting type 'from' to type 'to' is casting
+>     -- to the 'from' type's prefered type in the 'from' type's
+>     -- category
+>     isCastToPreferred :: Type -> Type -> Bool
+>     isCastToPreferred from to = maybe False (const True) $ do
+>         when (from == to) Nothing
+>         when (isLeft (catPreferredType cat to)) Nothing
+>         t1 <- either (const Nothing) Just
+>               $ catTypeCategory cat from
+>         t2 <- either (const Nothing) Just
+>               $ catTypeCategory cat to
+>         if t1 == t2
+>           then Just ()
+>           else Nothing
+
+what are all the special cases currently:
+special cases for precision
+special cases for result null
+in OldTypeConverion.findCallMatch:
+   between, not between, greatest, least
+   rowctor
+   .
+   comparisons for composite/set types
+more stuff in TypeConversion.matchApp
+  sql server date stuff
+  decode
+  something to do with datetimes?
+  string precisions?:
+    ||, substring, replace
+  some nullability special cases?
+  jesus, more bullshit, no idea what it is all for
+    no tests and documentation as per usual
+SqlTypeConversions: special case for implicit casts from text types to
+  numeric (see if can handle in rule system)
+ScalarExprs.ag
+  needs implicit cast
+  implicit cast type
+  check the types (e.g. cast syntax should use this typeconversion
+   machinery)
+  tcAppLike: more mssql date shit
+
+  getmaybeintsfromliterals: also suggests only need to support int
+    literals in the matchapp function here
+
+on the way out:
+
+we have to add implicit casts for possible nullability and precision
+adjustments and work out the result type precision and nullability
+
+dealing with nullable: assume functions are strict, and never return
+null if none of the inputs are null. Every function which doesn't work
+this way will be special cased here.
+
+precision
+precision and scale apply to the following types:
+array-style types (will we need 2d arrays?)
+numeric
+strings
+byte arrays
+
+for numeric, the precision and scale for a result are always -1 which
+represents the text equivalent for numeric: unlimited scale and
+precision.
+
+the precision on a float is fake, and represents a weird short hand to
+one of two fixed types, float4 and float8
+
+the precision of char and varchar is the sum of all the precisions of
+these in the input by default, lots of special cases here. Also have
+literals to deal with.
+
+
+> --resolveResultSetType :: Catalog -> [TypeExtra] -> Either [TypeError] TypeExtra
+> --resolveResultSetType cat tys = undefined
+
+
+> --checkAssignmentValid :: Catalog -> Type -> Type -> Either [TypeError] ()
+> --checkAssignmentValid cat from to = undefined
+
+
+resolve result set types:
+numeric
+text
+domains
+time
+precision
+nullability
+
+used for union, intersect, except, case, array, values, greatest,
+least, join keys
+
+
+If all inputs are of the same type, and it is not unknown, resolve as
+that type.
+
+If any input is of a domain type, treat it as being of the domain's
+base type for all subsequent steps. [1]
+
+If all inputs are of type unknown, resolve as type text (the preferred
+type of the string category). Otherwise, unknown inputs are ignored.
+
+If the non-unknown inputs are not all of the same type category, fail.
+
+Choose the first non-unknown input type which is a preferred type in
+that category, if there is one.
+
+Otherwise, choose the last non-unknown input type that allows all the
+preceding non-unknown inputs to be implicitly converted to it. (There
+always is such a type, since at least the first type in the list must
+satisfy this condition.)
+
+Convert all inputs to the selected type. Fail if there is not a
+conversion from a given input to the selected type.
+
+
+
+checkassignmentvalid:
+
+
+
+
+
+also:
+text encoding, char set + collations, what else?
+
+
+TODO: get the list of all the hacks sqream does at the
+typechecking sql layer and move it here
diff --git a/src/Database/HsSqlPpp/Internals/TypeChecking/Utils.lhs b/src/Database/HsSqlPpp/Internals/TypeChecking/Utils.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Internals/TypeChecking/Utils.lhs
+++ /dev/null
@@ -1,127 +0,0 @@
-
-For extra utility functions to help with asts
-
-> module Database.HsSqlPpp.Internals.TypeChecking.Utils
->     (addExplicitCasts
->     ,canonicalizeTypeNames) where
-
-> import Data.Data
-> import Database.HsSqlPpp.Internals.AstInternal
-> import Data.Generics.Uniplate.Data
-> import Database.HsSqlPpp.Internals.AstAnnotation
-> import Database.HsSqlPpp.Internals.TypeType
-> import Control.Monad
-
-
-
-> -- | Run through a typechecked tree and add in explicit casts where
-> -- implicit casts are used to typecheck. Does function and operator
-> -- calls, case result expressions, and string, integer and float
-> -- literals at the moment, todo: union, array, greatest, least
-> addExplicitCasts :: Data a => a -> a
-> addExplicitCasts =
->   refix . tr . canonicalizeTypeNames
->   where
->     tr = transformBi $ \x -> case x of
->            FunCall a f as | Just p <- getProtoATys a
->                           , Just ats <- getTys as
->                           , p /= ats
->              -> FunCall a f $ zipWith3 addCastIfNeeded p ats as
->            Case a cs els | (Just f) <- doCase a cs els -> f
->            CaseSimple a v cs els | (Just f) <- doCaseSimple a v cs els -> f
->            i@(NumberLit a _) | Just t <- infType a -> castToT t i
->            i@(StringLit a _) | Just t <- infType a -> castToT t i
->            x1 -> x1
->     -- need to put the type annotation in the created cast to allow
->     -- adding explicit casts to continue up the tree
->     castToT t e = Cast ea {atype = Just t,infType = Just t} e $ typeName 1 t
->     getProtoATys :: Annotation -> Maybe [Type]
->     getProtoATys a = let p = fnProt a
->                      in flip fmap p $ \(_,t,_,_) -> t
->     getTys :: [ScalarExpr] -> Maybe [Type]
->     getTys = mapM $ atype . getAnnotation
->     addCastIfNeeded :: Type -> Type -> ScalarExpr -> ScalarExpr
->     addCastIfNeeded nt ot e =
->       if ot == nt
->       then e
->       else Cast ea e $ typeName 2 nt
->     -- not sure how to avoid inserting a cast for a literal which is
->     -- already being cast when using transformBi, so run through and
->     -- remove the suplerfluous casts in a second sweep
->     -- spot them when there is a cast of a cast of a literal
->     -- and the type of the inner cast is the same as the type of the literal
->     -- not sure if this pass can cause other problems
->     refix = transformBi $ \x -> case x of
->               Cast ca (Cast _ l t) t1 | isLiteral l
->                                       , Just lt <- infType $ getAnnotation l
->                                       , t == typeName 3 lt
->                 -> Cast ca l t1
->               x1 -> x1
->     isLiteral (NumberLit _ _) = True
->     isLiteral (StringLit _ _) = True
->     isLiteral _ = False
-
-
-> typeName :: Int -> Type -> TypeName
-> typeName _ (ScalarType t) = SimpleTypeName ea t
-> typeName i e = error $ "don't know how to convert " ++ show e ++ " to typename " ++ show i
-
-> ea :: Annotation
-> ea = emptyAnnotation
-
-> doCase :: Annotation -> [([ScalarExpr],ScalarExpr)] -> Maybe ScalarExpr -> Maybe ScalarExpr
-> doCase a whths els = do
->   (whths',els') <- doCaseStuff a whths els
->   return $ Case a whths' els'
-
-> doCaseSimple :: Annotation -> ScalarExpr -> [([ScalarExpr],ScalarExpr)] -> Maybe ScalarExpr -> Maybe ScalarExpr
-> doCaseSimple a v whths els = do
->   (whths',els') <- doCaseStuff a whths els
->   return $ CaseSimple a v whths' els'
-
-> doCaseStuff :: Annotation -> [([ScalarExpr],ScalarExpr)] -> Maybe ScalarExpr -> Maybe ([([ScalarExpr],ScalarExpr)],Maybe ScalarExpr)
-> doCaseStuff a whths els = do
->   --trace (show $ atype a) $ return ()
->   expectedType <- atype a
->   --trace (show $ map (atype . getAnnotation . snd) whths) $ return ()
->   thenTypes <- mapM (atype . getAnnotation . snd) whths
->   --trace (show els) $ return ()
->   thenAndElseTypes <- case els of
->                         Nothing -> return thenTypes
->                         Just els' -> fmap (:thenTypes) $ atype $ getAnnotation els'
->   --trace ("checking cast: " ++ show expectedType ++ " " ++ show thenAndElseTypes)
->   when (all (==expectedType) thenAndElseTypes) Nothing
->   return (map (fixWhTh expectedType) whths
->          ,castElse expectedType)
->   where
->     castElse et = case els of
->                     Nothing -> Nothing
->                     Just els' | Just t' <- atype $ getAnnotation els
->                               , t' /= et
->                       -> Just (Cast ea els' $ typeName 4 et)
->                               | otherwise -> els
->     fixWhTh :: Type -> ([ScalarExpr],ScalarExpr) -> ([ScalarExpr],ScalarExpr)
->     fixWhTh et (whs,th) | Just t' <- atype $ getAnnotation th
->                         , t' /= et = (whs, Cast ea th $ typeName 5 et)
->                         | otherwise = (whs,th)
-
-> -- bit crap, this function is called canonicalizeTypeNames
-> -- and it uses a function called canonicalizeTypeName
-
-> -- | Convert all the typenames in the ast to canonical form
-> -- e.g. int -> int4
-> canonicalizeTypeNames :: Data a => a -> a
-> canonicalizeTypeNames = fixTypes . fixTypeNames
->   where
->     fixTypes =
->       transformBi $ \x -> case x of
->         ScalarType t -> ScalarType $ ct t
->         x1 -> x1
->     fixTypeNames =
->       transformBi $ \x -> case x of
->         SimpleTypeName a t -> SimpleTypeName a $ ct t
->         PrecTypeName a t i -> PrecTypeName a (ct t) i
->         Prec2TypeName a t i0 i1 -> Prec2TypeName a (ct t) i0 i1
->         x1 -> x1
->     ct = canonicalizeTypeName
-
diff --git a/src/Database/HsSqlPpp/Internals/TypeType.lhs b/src/Database/HsSqlPpp/Internals/TypeType.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Internals/TypeType.lhs
+++ /dev/null
@@ -1,422 +0,0 @@
-
-This file contains the data type Type. It is kept separate so you can
-compile the types and function information from the database
-separately to AstInternal.ag.
-
-Types overview:
-
-Regular types: scalarType, arrayType, composite type, domaintype
-we can use these anywhere.
-
-~~~~
-semi first class types: row, unknownstringlit (called unknown in pg) -
-these can be used in some places, but not others, in particular an
-expression can have this type or select can have a row with these
-type, but a view can't have a column with this type (so a select can
-be valid on it's own but not as a view. Not sure if Row types can be
-variables, unknownstringlit definitely can't. (Update, seems a view
-can have a column with type unknown.)
-
-pseudo types - mirror pg pseudo types
-Internal, LanguageHandler, Opaque probably won't ever be properly supported
-Not sure exactly what Any is, can't use it in functions like the other any types?
- - update: seems that Any is like AnyElement, but multiple Anys don't
-   have to have the same type.
-AnyElement, AnyArray, AnyEnum, AnyNonArray - used to implement polymorphic functions,
-  can only be used in these functions as params, return type (and local vars?).
-Cstring - treated as variant of text?
-record -dynamically typed, depends where it is used, i think is used
-for type inference in function return types (so you don't have to
-write the correct type, the compiler fills it in), and as a dynamically
-typed variable in functions, where it can take any composite typed
-value.
-void is used for functions which return nothing
-trigger is a tag to say a function is used in triggers, used as a
-return type only
-typecheckfailed is used to represent the type of anything which the code
-is currently unable to type check, this usage should disappear at some
-point, and then it will only represent code which doesn't type check
-because of a mistake.
-
-The Type type identifies the type of a node, but doesn't necessarily
-describe the type.
-
-Typing relational valued expressions:
-use SetOfType combined with composite type for now, see if it works
-out. If not, will have to add another type.
-~~~~
-
-> {-# LANGUAGE FlexibleInstances,DeriveDataTypeable #-}
->
-> module Database.HsSqlPpp.Internals.TypeType where
->
-> import Control.Monad.Trans.Error
-> --import Control.Monad.Error
->
-> import Data.Data
-> import Data.Generics.Uniplate.Data
-> import Data.Char
-
-> data Type = ScalarType String
->           | ArrayType Type
->           | SetOfType Type
->             --three variations, choose better name for rowctor
->             --refer to composite type in catalog
->           | NamedCompositeType String
->             --refer to composite type either in catalog or one generated on fly
->           | CompositeType [(String,Type)]
->             --refer to anonymous composite type: the fields have no names
->             --these three types are equality and assign compatible if the fields
->             --are ignoring the names, so the fields have to be in the same order.
->           | AnonymousRecordType [Type] -- was rowctor
->           | PgRecord (Maybe Type) -- can only hold namedcomposite, composite or anonymousrecord
->           | DomainType String
->           | EnumType String
->           | Pseudo PseudoType
->           | UnknownType -- represents a string literal
->                              -- token whose type isn't yet
->                              -- determined
->             deriving (Eq,Show,Ord,Typeable,Data)
->
-> data PseudoType = Any
->                 | AnyArray
->                 | AnyElement
->                 | AnyEnum
->                 | AnyNonArray
->                 | Cstring
->                 | Record
->                 | TriggerRecord
->                 | Trigger
->                 | Void
->                 | Internal
->                 | LanguageHandler
->                 | Opaque
->                 | FdwHandler
->                   deriving (Eq,Show,Ord,Typeable,Data)
-
-this list will need reviewing, probably refactor to a completely
-different set of infos, also will want to add more information to
-these, and to provide a way of converting into a user friendly
-string. It is intended for this code to produce highly useful errors
-later on down the line.
-
->                    -- mostly expected,got
-> data TypeError = WrongTypes Type [Type]
->                | UnknownTypeError Type
->                | UnknownTypeName String
->                | NoMatchingOperator String [Type]
->                | TypelessEmptyArray
->                | IncompatibleTypeSet [Type]
->                | IncompatibleTypes Type Type
->                | ValuesListsMustBeSameLength
->                | NoRowsGivenForValues
->                | UnrecognisedIdentifier String
->                | UnrecognisedRelation String
->                | UnrecognisedCorrelationName String
->                | BadStarExpand
->                | AmbiguousIdentifier String
->                | ContextError String
->                | MissingJoinAttribute
->                | ExpressionMustBeBool
->                | WrongNumberOfColumns
->                | ExpectedDomainType Type
->                | DomainDefNotFound Type
->                | BadCatalogUpdate String
->                | TypeAlreadyExists Type
->                | AnyAllError String
->                | InternalError String
->                | FromToTypesNotSame Type Type
->                | WrongNumberOfAliasCols Int Int
->                 --shoved in to humour the Either Monad
->                | MiscError String
->                  deriving (Eq,Show,Ord,Typeable,Data)
->
-
- > instance Error ([TypeError]) where
- >   noMsg = [MiscError "Unknown error"]
- >   strMsg str = [MiscError str]
-
-> instance ErrorList TypeError where
->    listMsg s = [MiscError s]
-
-
-=== canonical type name support
-
-Introduce some aliases to protect client code if/when the ast
-canonical names are changed:
-
-> typeSmallInt,typeBigInt,typeInt,typeNumeric,typeFloat4,
->   typeFloat8,typeVarChar,typeChar,typeBool,typeDate,
->   typeInterval :: Type
-> typeSmallInt = ScalarType "int2"
-> typeBigInt = ScalarType "int8"
-> typeInt = ScalarType "int4"
-> typeNumeric = ScalarType "numeric"
-> typeFloat4 = ScalarType "float4"
-> typeFloat8 = ScalarType "float8"
-> typeVarChar = ScalarType "varchar"
-> typeChar = ScalarType "char"
-> typeBool = ScalarType "bool"
-> typeDate = ScalarType "date"
-> typeInterval = ScalarType "interval"
-
-this converts the name of a type to its canonical name:
-try to follow the names that pg uses in a dump
-this converts the name of a type to its canonical name:
-try to follow the names that pg uses in a dump
-
-> canonicalizeTypeName :: String -> String
-> canonicalizeTypeName s' =
->   case () of
->                   _ | s `elem` smallIntNames -> "int2"
->                     | s `elem` intNames -> "int4"
->                     | s `elem` bigIntNames -> "int8"
->                     | s `elem` numericNames -> "numeric"
->                     | s `elem` float4Names -> "float4"
->                     | s `elem` float8Names -> "float8"
->                     | s `elem` varcharNames -> "varchar"
->                     | s `elem` charNames -> "char"
->                     | s `elem` boolNames -> "bool"
->                     | otherwise -> s
->   where
->       smallIntNames = ["int2", "smallint"]
->       intNames = ["int4", "integer", "int", "serial"]
->       bigIntNames = ["int8", "bigint"]
->       numericNames = ["numeric", "decimal"]
->       float4Names = ["real", "float4"]
->       float8Names = ["double precision", "float"]
->       varcharNames = ["character varying", "varchar"]
->       charNames = ["character", "char"]
->       boolNames = ["boolean", "bool"]
->       s = map toLower s'
->
-> canonicalizeTypes :: Data a => a -> a
-> canonicalizeTypes =
->   transformBi $ \x ->
->       case x of
->         ScalarType s -> ScalarType $ canonicalizeTypeName s
->         x1 -> x1
-
-random notes on pg types:
-
-~~~~
-
-== domains:
-the point of domains is you can't put constraints on types, but you
-can wrap a type up in a domain and put a constraint on it there.
-
-== literals/selectors
-
-source strings are parsed as unknown type: they can be implicitly cast
-to almost any type in the right context.
-
-rows ctors can also be implicitly cast to any composite type matching
-the elements (now sure how exactly are they matched? - number of
-elements, type compatibility of elements, just by context?).
-
-string literals are not checked for valid syntax currently, but this
-will probably change so you can type check string literals statically.
-Postgres defers all checking to runtime, because it has to cope with
-custom data types. This code will allow adding a grammar checker for
-each type so you can optionally check the string lits statically.
-
-== notes on type checking types
-
-=== basic type checking
-Currently can lookup type names against a default template1 list of
-types, or against the current list in a database (which is read before
-processing and sql code).
-
-todo: collect type names from current source file to check against
-A lot of the infrastructure to do this is already in place. You also
-need to do this for all other definitions, etc.
-
-=== Type aliases
-
-Some types in postgresql have multiple names. I think this is
-hardcoded in the pg parser.
-
-For the canonical name in this code, you use the name given in the
-postgresql pg_type catalog relvar.
-
-TODO: Change the ast canonical names: where there is a choice, prefer
-the sql standard name, where there are multiple sql standard names,
-choose the most concise or common one, so the ast will use different
-canonical names to postgresql.
-
-planned ast canonical names:
-numbers:
-int2, int4/integer, int8 -> smallint, int, bigint
-numeric, decimal -> numeric
-float(1) to float(24), real -> float(24)
-float, float(25) to float(53), double precision -> float
-serial, serial4 -> int
-bigserial, serial8 -> bigint
-character varying(n), varchar(n)-> varchar(n)
-character(n), char(n) -> char(n)
-
-TODO:
-
-what about PrecTypeName? - need to fix the ast and parser (found out
-these are called type modifiers in pg)
-
-also, what can setof be applied to - don't know if it can apply to an
-array or setof type
-
-array types have to match an exact array type in the catalog, so we
-can't create an arbitrary array of any type. Not sure if this is
-handled quite correctly in this code.
-
-~~~~
-
---------------------------------------------------------------------------------
-
-utilities for working with Types
-
-These may indicate that the haskell type system isn't being used very well.
-
-> isArrayType :: Type -> Bool
-> isArrayType (ArrayType _) = True
-> isArrayType _ = False
->
-> isDomainType :: Type -> Bool
-> isDomainType (DomainType _) = True
-> isDomainType _ = False
->
-> isCompositeType :: Type -> Bool
-> isCompositeType (CompositeType _) = True
-> isCompositeType (NamedCompositeType _) = True
-> isCompositeType (AnonymousRecordType _) = True
-> isCompositeType (PgRecord _) = True
-> isCompositeType _ = False
->
-> isCompositeOrSetOfCompositeType :: Type -> Bool
-> isCompositeOrSetOfCompositeType (SetOfType a) = isCompositeType a
-> isCompositeOrSetOfCompositeType a = isCompositeType a
->
-> unwrapArray :: Type -> Either [TypeError] Type
-> unwrapArray (ArrayType t) = Right t
-> unwrapArray x = Left [InternalError $ "can't get types from non array " ++ show x]
->
-> unwrapSetOfWhenComposite :: Type -> Either [TypeError] Type
-> unwrapSetOfWhenComposite (SetOfType a@(CompositeType _)) = Right a
-> unwrapSetOfWhenComposite x = Left [InternalError $ "tried to unwrapSetOfWhenComposite on " ++ show x]
->
-> unwrapSetOfComposite :: Type -> Either [TypeError]  [(String,Type)]
-> unwrapSetOfComposite (SetOfType (CompositeType a)) = Right a
-> unwrapSetOfComposite x = Left [InternalError $ "tried to unwrapSetOfComposite on " ++ show x]
->
-> unwrapSetOf :: Type -> Either [TypeError] Type
-> unwrapSetOf (SetOfType a) = Right a
-> unwrapSetOf x = Left [InternalError $ "tried to unwrapSetOf on " ++ show x]
->
-> unwrapComposite :: Type -> Either [TypeError] [(String,Type)]
-> unwrapComposite (CompositeType a) = Right a
-> unwrapComposite x = Left [InternalError $ "cannot unwrapComposite on " ++ show x]
->
-> consComposite :: (String,Type) -> Type -> Either [TypeError] Type
-> consComposite l (CompositeType a) = Right $ CompositeType (l:a)
-> consComposite a b = Left [InternalError $ "called consComposite on " ++ show (a,b)]
->
-> unwrapRowCtor :: Type -> Either [TypeError] [Type]
-> unwrapRowCtor (AnonymousRecordType a) = Right a
-> unwrapRowCtor x = Left [InternalError $ "cannot unwrapRowCtor on " ++ show x]
-
---------------------------------------------------------------------------------
-
-~~~~
-new plan for types:
-
-The type annotations attached to nodes will be either typecheckfailed 'type'
-this will allow chaining type check failed more robustly. Type errors don't change.
-
-the sql type type will be changed so you can track the different
-contexts where different sql types can be used, split to use different
-sets of types so you can use the haskell type system to enforce these
-contexts.
-
-rename type to sqltype, too confusing otherwise
-new set of sqltypes: (these aren't in one haskell type anymore)
-scalar type - corresponds to sqltypes in pg which aren't one of the
-  other types (no easy way to define this)
-array type
-setof type : can be applied to scalar, domain, ... but not all types
-composite types are changed:
-namedcomposite string
-composite [(string,type)] -> what types can appear in the attribute list?
-anonymousrecord [type] -> what types can appear here? -> this
-represents a row expression type, which can be returned in select
-expressions (but not as a column in a view), and is used in other places
-domaintype : what types are allowable as the base type?
-pseudo types: these are used for arguments and return values for function prototypes only
-any*, record - just means pg infers the return type which will be a composite type (namedcomposite, composite or anonymousrecord), trigger: just a tag, void: just a tag, any*: polymorphic functions, ignore cstring, internal, language handler and opaque.
-issue: a variable declaration can be a polymorphic type in a polymorphic function, but you can't use the other pseudo types so need to split these
-a variable declared as type record IS NOT the same thing as the pseudo record type, I've finally worked out.
-so our plpgsqlrecordtype is plpgsqlrecordtype (Nothing|one of the three composite types)
-
-typechecking polymorphic functions: will have to relax the type
-checking to some degree. want to check against each usage of the
-polymorphic function in the source, so substitute in the actual types
-and check the function.
-
-contexts:
-function prototypes: args and return type
-function calls: args and return
-variable declaration in plpgsql
-attribute in a select expression
-attribute in a view (less permissive than a select expression), also create table as?
-attribute in a table, type (is this the same list as for composite and anonymous records? - can nest anonymous records)
-base type for domain
-cast expression
-insert: targetatts are same set of types as attributes in a table
-update: targets can be attr types or anonymous records of attr types for rowset style assign (x,y) = selectexp
-assignment statement: type on left same set as type in a for, types in select into, etc?
-return statement
-return query statement
-expressions in a raise statement
-expressions in execute, anything else?
-types used inside select expression checking:
-  selectlist, trefs, groupby, orderby, limit, offset, where, having
-expressions:
-what can an identifiers type be?
-what can the type of an Expression node be?
-  scalar: integerlit,floatlit
-  stringlit: what can an unknown resolve to (not quite everything)
-  booleanlit: scalar
-  nulllit: same as stringlit?
-  positionalarg: any type that a function arg can have
-  cast: any type you can cast to
-  identifier: ?
-  case, casesimple: any type in the rhs expressions, what are these?
-  exists: scalar
-  funcall: any type a function return type can have
-  inpredicate: scalar
-  windowfn: ?
-  liftoperator: booleans only?
-
-problem: can't get types using gettypeannotation function and support
-different valid combinations of types
-
-
-new notes
-type contexts - these all have different possible types
-function return type
-function parameter type
-OLD & NEW
-declared variable
-attribute in create table
-attribute create type
-column in select expression
-column in view
-column in insert
-item in set in update: includes row type with contained types restricted
-placeholder
-id lookups in local bindings
-typenames??
-
-create list of each type for each context
-create wrapper types which convert from other types to either
-  typeerror type for bad type for context
-
-~~~~
-
diff --git a/src/Database/HsSqlPpp/Internals/TypesInternal.lhs b/src/Database/HsSqlPpp/Internals/TypesInternal.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/TypesInternal.lhs
@@ -0,0 +1,273 @@
+
+
+Type identifiers and anonymous types
+
+Basic type identified by name
+These can be quoted or unquoted, and with or without schema
+
+unknown type: this is used for the types of literals in a kind of poor
+mans type inference, modelled on postgresql's behaviour. Dialects can
+choose not to use this approach and give a literal a type based only
+on its syntax (and thus the dialect would never use the unknown
+type. (The direct unknown typing isn't quite implemented yet).
+
+any types
+
+these are used to implement a kind of poor man's polymorphism. based
+on the any types in postgresql. These are used for polymorphic
+udfs. This is separate to overloading functions.
+
+anonymous composite type
+
+this represents a tuple of types, all, some or none of which can have
+field names. This is used for composite types which are created on the
+fly and don't have a name in the catalog or environment. Maybe this
+should be changed so they are given a temporary name to reduce the
+special cases
+
+tref type
+
+this is an internal type used by the typechecker (todo: can this be
+hidden?) Maybe could add optional correlation names to the field names
+in anonymous composite type and reuse that?
+
+setof?
+record?
+void?
+
+typeextra
+
+ugly way to add nullability and precision to a type. This should get a
+big rethink
+
+step 1 todo:
+combine composite and anonymous composite types
+combine scalartype, domaintype, enum, named composite type
+
+get rid of explicit array types and figure out a better way to handle
+them
+
+Split the errors into another module, and in the public api
+The errors should contain not contain 'Type's.
+
+figure out a better way of handling nullability, precision, scale than
+the typeextra
+
+> {-# LANGUAGE FlexibleInstances,DeriveDataTypeable,OverloadedStrings #-}
+>
+> module Database.HsSqlPpp.Internals.TypesInternal where
+>
+> import Data.Data
+> --import Data.Generics.Uniplate.Data
+> --import Data.Char
+> import Data.Text (Text)
+> --import qualified Data.Text as T
+> --import Database.HsSqlPpp.Internals.Dialect
+> --import Data.List
+> --import Debug.Trace
+
+> --import Control.Monad.Error
+> --import Control.Monad.Except
+> --import Control.Monad.Trans.Except
+
+where should precision and nullability go?
+
+
+TODO:
+rename UnknownType to ScalarType "!unknown" ? or something else?
+do we need separate entries for domain and enums?
+think of a better way to implement array types - get rid of the
+  special casing which is based on a postgresql implementation detail
+get rid of pseudo types, maybe use ScalarType or SpecialType String
+  which is dialect specific?
+
+Maybe there should be a concept of a typeid, and a typedescription?
+So the typeid is used everywhere and is just a string or something,
+and the typedescription is got from the catalog/environment when
+needed in the typechecking?
+
+
+> -- | Standard types of things. This covers all the usual postgres types
+> -- plus some extra ones added for use by the hssqlppp typechecker
+> data Type = -- | basic type of a scalar value. These are either built in types
+>             -- in postgres, or implemented in C or similar
+>             ScalarType Text
+>           -- | a domain type is used for a constraint on a table column which
+>           -- would used on multiple columns on a table or in multiple tables,
+>           -- using a domain type is a way of just writing the constraint once
+>           | DomainType Text
+>           -- | enum type, not really supported in hssqlppp yet
+>           | EnumType Text
+>           -- | String literals in postgres have an unknown type. The effective
+>           -- type is determined using what seems to amount to some simple ad hoc rules
+>           -- based on the context of the string literal. Hssqlppp also treats
+>           -- ? placeholders and nulls the same way, so they have UnknownType,
+>           -- not sure how closely this matches postgres
+>           | UnknownType
+>           -- | postgres automatically creates an array type for every scalar type
+>           -- (plus some other types?) If there is no array type for a type in the
+>           -- catalog, then you can't work with arrays of that type
+>           | ArrayType Type
+>           -- | refer to composite type in catalog by name. not sure if this needs
+>           -- to exist along with CompositeType
+>           | NamedCompositeType Text
+>           -- | refer to composite type by structure
+>           | CompositeType [(Text,TypeExtra)]
+>           -- | CompositeTypeExtra [(Text,TypeExtra)]
+>           -- | hack to support the environment for a tref
+>           | TrefType [((Text,Text),TypeExtra)]
+>           -- | the fields are anonymous as well as the type itself
+>           | AnonymousCompositeType [Type]
+>           -- | The pseudo type is used for types which only appear
+>           -- as argument or return types in function definitions and/or
+>           -- are used only in plpgsql and not regular sql. hssqlppp also
+>           -- follows this usage for the types used in hssqlppp which don't
+>           -- have an exact counterpart in postgres
+>           | Pseudo PseudoType
+>             deriving (Eq,Show,Ord,Typeable,Data)
+>
+
+> -- | Quick fix to add precision and nullable information to the
+> -- annotation types. This approach should be revisited, maybe this
+> -- information should be in the Type type?
+> data TypeExtra = TypeExtra {teType :: Type
+>                            ,tePrecision :: Maybe Int
+>                            ,teScale :: Maybe Int
+>                            ,teNullable :: Bool}
+>                deriving (Eq,Ord,Show,Typeable,Data)
+> mkTypeExtra :: Type -> TypeExtra
+> mkTypeExtra t = TypeExtra t Nothing Nothing True
+> mkTypeExtraNN :: Type -> TypeExtra
+> mkTypeExtraNN t = TypeExtra t Nothing Nothing False
+> mkNullable:: TypeExtra -> TypeExtra
+> mkNullable te = te{teNullable=True}
+
+> -- | Pseudo types: mainly used for the argument and return types of
+> -- functions. The weird undocumented types are just used to represent
+> -- functions with those types which are in the postgres default catalog
+> data PseudoType =
+>                 -- | setof is used for set returning functions
+>                   SetOfType Type
+>                   -- | used to represent polymorphic functions, all the
+>                   -- AnyElement parameters and the return type if
+>                   -- AnyElement must be the same type for a given function
+>                   -- call invocation.
+>                 | AnyElement
+>                   -- | like AnyElement, but the type must be an array type
+>                 | AnyArray
+>                   -- | like AnyElement, but the type must be an enum type
+>                 | AnyEnum
+>                   -- | like AnyElement, but the type must be a non array type
+>                 | AnyNonArray
+>                 | AnyRange
+>                   -- | Any drops the restriction that all the Any types must
+>                   -- be the same type
+>                 | Any
+>                 -- | record types are used in plpgsql for a sort of dynamic
+>                 -- typing or rough polymorphism substitute. They can refer to
+>                 -- values of named composite type, composite type or
+>                 -- anonymous composite type, not sure if non composite types as well.
+>                 | Record (Maybe Type)
+>                 -- | presumably used for the types of OLD and NEW in a trigger
+>                 -- function. Hssqlppp will probably use the Record type above
+>                 -- for these.
+>                 --  | TriggerRecord
+>                 --  | Trigger
+>                 -- | cstring - a C string
+>                 --  | Cstring
+>                 -- | represents the return type of a function which doesn't return
+>                 -- anything. Not sure if it is used anywhere else
+>                 | Void
+>                 --  | Internal
+>                 --  | LanguageHandler
+>                 --  | Opaque
+>                 --  | FdwHandler
+>                   deriving (Eq,Show,Ord,Typeable,Data)
+
+TODO idea
+
+> {-data Type = -- | A normal type identified by name. Includes scalar
+>             -- types, domain types, enums, (non-anonymous)
+>             -- structured types
+>             Type (Maybe Text,Text)
+>              -- | represents a unknown type like in postgres. Used
+>              -- for literals in some dialects and a few other places
+>           | UnknownType
+>           | ArrayType Type
+>           | CompositeType [(Text,TypeExtra)]
+>           -- | hack to support the environment for a tref
+>           | TrefType [((Text,Text),TypeExtra)]
+>           -- | the fields are anonymous as well as the type itself
+>           | AnonymousCompositeType [Type]
+>           | SetOfType Type
+>             -- | record types are used in plpgsql for a sort of dynamic
+>             -- typing or rough polymorphism substitute. They can refer to
+>             -- values of named composite type, composite type or
+>             -- anonymous composite type, not sure if non composite types as well.
+>           | Record (Maybe Type)
+>             deriving (Eq,Show,Ord,Typeable,Data)-}
+
+
+The possible type errors. This is a bit unorganised, at some point if
+better error messages are wanted, then a lot more information could be
+added.
+
+> data TypeError = {-
+>                | UnknownTypeError Type
+>                | UnknownTypeName String
+>                | NoMatchingOperator String [Type]
+>                | TypelessEmptyArray
+>                | IncompatibleTypeSet [Type]
+>                | IncompatibleTypes Type Type
+>                | ValuesListsMustBeSameLength
+>                | NoRowsGivenForValues
+>                | UnrecognisedIdentifier String
+>                | UnrecognisedRelation String
+>                | UnrecognisedCorrelationName String
+>                | BadStarExpand
+>                | ContextError String
+>                | MissingJoinAttribute
+>                | ExpressionMustBeBool
+>                | WrongNumberOfColumns
+>                | ExpectedDomainType Type
+>                | BadCatalogUpdate String
+>                | TypeAlreadyExists Type
+>                | AnyAllError String
+>                | InternalError String
+>                | FromToTypesNotSame Type Type
+>                | WrongNumberOfAliasCols Int Int
+
+type conversion errors
+
+>                | -} NoMatchingOperator Text [Type]
+>                | AmbiguousOperator Text [Type]
+>                | TypelessEmptyArray
+>                | IncompatibleTypeSet [Type]
+>                | IncompatibleTypes Type Type
+>                | WrongNumberOfColumns
+>                | WrongTypes Type [Type]
+>                | IncompatibleUnionTypes Type Type
+
+
+old catalog type errors: to be replaced when the catalog code is
+gutted and rewritten
+
+>                | TypeAlreadyExists Type
+>                | SchemaAlreadyExists Text
+>                | BadCatalogUpdate Text
+>                | UnrecognisedRelation (Text,Text)
+>                | DomainDefNotFound Type
+>                | TypeNotKnown Type
+>                | UnknownTypeName Text
+>                | UnrecognisedIdentifier Text
+>                | UnrecognisedCorrelationName Text
+>                | SchemadColumnName Text
+>                | DbSchemadColumnName Text
+>                | BadStarExpand
+>                | InternalError String
+>                | AmbiguousIdentifier Text
+>                | OdbcFuncBadContent
+>                | DuplicateColumnName Text
+>                | TooManyColumnsInInsert
+>                  deriving (Eq,Show,Ord,Typeable,Data)
+>
diff --git a/src/Database/HsSqlPpp/Internals/Utils.lhs b/src/Database/HsSqlPpp/Internals/Utils.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Internals/Utils.lhs
@@ -0,0 +1,81 @@
+
+This file contains some generic utility stuff
+
+> {-# LANGUAGE TupleSections #-}
+> {-# LANGUAGE FlexibleContexts #-}
+> module Database.HsSqlPpp.Internals.Utils where
+>
+> import Control.Arrow
+> import Control.Applicative
+> import Data.List
+> import Data.Char
+
+> infixl 9 |>
+> (|>) :: (a -> b) -> (b -> c) -> a -> c
+> (|>) = flip (.)
+>
+> both :: (a->b) -> (a,a) -> (b,b)
+> both fn = fn *** fn
+>
+> (<:>) :: (Applicative f) =>
+>          f a -> f [a] -> f [a]
+> (<:>) a b = (:) <$> a <*> b
+
+> firstM :: Functor f => (t -> f a) -> (t, t1) -> f (a, t1)
+> firstM f (a,b) = (,b) <$> f a
+
+> secondM :: Functor f => (t -> f a) -> (t1, t) -> f (t1, a)
+> secondM f (a,b) = (a,) <$> f b
+
+> replace :: (Eq a) => [a] -> [a] -> [a] -> [a]
+> replace _ _ [] = []
+> replace old new xs@(y:ys) =
+>   case stripPrefix old xs of
+>     Nothing -> y : replace old new ys
+>     Just ys' -> new ++ replace old new ys'
+>
+> split :: Char -> String -> [String]
+> split _ ""                =  []
+> split c s                 =  let (l, s') = break (== c) s
+>                            in  l : case s' of
+>                                            [] -> []
+>                                            (_:s'') -> split c s''
+>
+> npartition :: Eq b => (a -> b) -> [a] -> [(b,[a])]
+> npartition keyf =
+>   np []
+>   where
+>     np = foldl (\acc p -> insertWith (++) (keyf p) [p] acc)
+>
+> insertWith :: Eq k => (a -> a -> a) -> k -> a -> [(k,a)] -> [(k,a)]
+> insertWith ac k v m =
+>     case lookup k m of
+>       Nothing -> m ++ [(k,v)]
+>       Just v' -> let nv = ac v' v
+>                  in map (\p@(k1,_) -> if k1 == k
+>                                       then (k1,nv)
+>                                       else p) m
+
+This should preserve order, so in the result, the keys (k in
+[(k,[a],[b])]) are ordered by their first appearance in as, then bs,
+and the values are ordered the matches in the same order as they
+appear in the two lists ([a] and [b] in [(k,[a],[b])])
+
+> joinLists :: Eq k => (a -> k) -> (b -> k)
+>              -> [a] -> [b] -> [(k,[a],[b])]
+> joinLists ka kb as bs =
+>     let -- arrange the two lists by key
+>         kasps = npartition ka as
+>         kbsps = npartition kb bs
+>         -- get the list of keys
+>         ks = nub $ map fst kasps ++ map fst kbsps
+>         -- put together the two lists by key
+>     in flip map ks $ \k ->
+>         (k, getem k kasps, getem k kbsps)
+>     where
+>       getem :: Eq k => k -> [(k,[a])] -> [a]
+>       getem k = concatMap snd . filter ((==k) . fst)
+
+> trim :: String -> String
+> trim = f . f
+>    where f = reverse . dropWhile isSpace
diff --git a/src/Database/HsSqlPpp/Lex.lhs b/src/Database/HsSqlPpp/Lex.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Lex.lhs
@@ -0,0 +1,15 @@
+
+> {-# LANGUAGE TupleSections,OverloadedStrings #-}
+> module Database.HsSqlPpp.Lex
+>     (Token(..)
+>     ,prettyToken
+>     ,lexToken
+>     ,lexTokens
+>     ,Dialect(..)
+>     ,ansiDialect
+>     ) where
+
+> import Database.HsSqlPpp.Internals.LexInternal
+> import Database.HsSqlPpp.Internals.Dialect
+> import Database.HsSqlPpp.Dialects.Ansi
+
diff --git a/src/Database/HsSqlPpp/Parse.lhs b/src/Database/HsSqlPpp/Parse.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Parse.lhs
@@ -0,0 +1,31 @@
+
+Forward the public part of ParserInternal
+
+> -- | Functions to parse SQL.
+
+> module Database.HsSqlPpp.Parse
+>     (-- * Main
+>      parseStatements
+>     ,parseProcSQL
+>     ,parseQueryExpr
+>     ,parseScalarExpr
+>      -- * Parsing options
+>     ,ParseFlags(..)
+>     ,defaultParseFlags
+>     ,Dialect(..)
+>     ,ansiDialect
+>      -- * errors
+>     ,ParseErrorExtra(..)
+>      -- * internals
+>     ,parseName
+>     ,parseNameComponent
+
+>     ) where
+>
+> import Database.HsSqlPpp.Internals.ParseInternal
+> import Database.HsSqlPpp.Internals.ParseErrors
+> import Database.HsSqlPpp.Dialects.Ansi
+> import Database.HsSqlPpp.Internals.Dialect
+
+> defaultParseFlags :: ParseFlags
+> defaultParseFlags = ParseFlags {pfDialect = ansiDialect}
diff --git a/src/Database/HsSqlPpp/Parser.lhs b/src/Database/HsSqlPpp/Parser.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Parser.lhs
+++ /dev/null
@@ -1,18 +0,0 @@
-
-Forward the public part of ParserInternal
-
-> -- | Functions to parse SQL.
-> module Database.HsSqlPpp.Parser (
->              -- * Main
->               parseStatements
->              ,parseStatementsWithPosition
->              ,parseStatementsFromFile
->              ,parseQueryExpr
->              -- * Testing
->              ,parseScalarExpr
->              ,parsePlpgsql
->              -- * errors
->              ,ParseErrorExtra(..)
->              )
->     where
-> import Database.HsSqlPpp.Parsing.ParserInternal
diff --git a/src/Database/HsSqlPpp/Parsing/Lexer.lhs b/src/Database/HsSqlPpp/Parsing/Lexer.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Parsing/Lexer.lhs
+++ /dev/null
@@ -1,362 +0,0 @@
-
-This file contains the lexer for sql source text.
-
-Lexicon:
-
-~~~~
-string
-identifier or keyword
-symbols - operators and ;,()[]
-positional arg
-int
-float
-copy payload (used to lex copy from stdin data)
-~~~~
-
-> module Database.HsSqlPpp.Parsing.Lexer (
->               Token
->              ,Tok(..)
->              ,lexSqlFile
->              ,lexSqlText
->              ,lexSqlTextWithPosition
->              ,identifierString
->              ,LexState
->              ) where
-> import Text.Parsec hiding(many, optional, (<|>))
-> import qualified Text.Parsec.Token as P
-> import Text.Parsec.Language
-> --import Text.Parsec.String
-> import Text.Parsec.Pos
->
-> import Control.Applicative
-> import Control.Monad.Identity
-
-> import Data.Maybe
->
-> import Database.HsSqlPpp.Parsing.ParseErrors
-> import Database.HsSqlPpp.Utils.Utils
-> -- import Database.HsSqlPpp.Ast.Name
-
-================================================================================
-
-= data types
-
-> type Token = (SourcePos, Tok)
->
-> data Tok = StringTok String String --delim, value (delim will one of
->                                    --', $$, $[stuff]$
-
->          | IdStringTok String -- either a identifier component (without .) or a *
->          | QIdStringTok String -- same as IdStringTok with quotes
-
->          | SymbolTok String -- operators, and ()[],;: and also .
->                             -- '*' is currently always lexed as an id
->                             --   rather than an operator
->                             -- this gets fixed in the parsing stage
-
->          | PositionalArgTok Integer -- used for $1, etc.
-
-Use a numbertok with a string to parse numbers. This is mainly so that
-numeric constants can be parsed accurately - if they are parsed to
-floats in the ast then converted back to numeric, then the accuracy
-can be lost (e.g. something like "0.2" parsing to 0.199999999 float.
-
->          | NumberTok String
-
->          | CopyPayloadTok String -- support copy from stdin; with inline data
->            deriving (Eq,Show)
->
-> type LexState = [Tok]
-> type Parser = ParsecT String LexState Identity
->
-> lexSqlFile :: FilePath -> IO (Either ParseErrorExtra [Token])
-> lexSqlFile f = do
->   te <- readFile f
->   let x = runParser sqlTokens [] f te
->   return $ toParseErrorExtra x Nothing te
->
-> lexSqlText :: String -> String -> Either ParseErrorExtra [Token]
-> lexSqlText f s = toParseErrorExtra (runParser sqlTokens [] f s) Nothing s
->
-> lexSqlTextWithPosition :: String -> Int -> Int -> String
->                        -> Either ParseErrorExtra [Token]
-> lexSqlTextWithPosition f l c s =
->   toParseErrorExtra (runParser (do
->                                 setPosition (newPos f l c)
->                                 sqlTokens) [] f s) (Just (l,c)) s
-
-================================================================================
-
-= lexers
-
-lexer for tokens, contains a hack for copy from stdin with inline
-table data.
-
-> sqlTokens :: Parser [Token]
-> sqlTokens =
->   setState [] >>
->   whiteSpace >>
->   many sqlToken <* eof
-
-Lexer for an individual token.
-
-Could lex lazily and when the lexer reads a copy from stdin statement,
-it switches lexers to lex the inline table data, then switches
-back. Don't know how to do this in parsec, or even if it is possible,
-so as a work around, you use the state to trap if we've just seen 'from
-stdin;', if so, you read the copy payload as one big token, otherwise
-we read a normal token.
-
-> sqlToken :: Parser Token
-> sqlToken = do
->            sp <- getPosition
->            sta <- getState
->            t <- if sta == [ft,st,mt]
->                 then copyPayload
->                 else try sqlNumber
->                  <|> try sqlString
->                  <|> try idString
->                  <|> try qidString
->                  <|> try positionalArg
->                  <|> try sqlSymbol
->            updateState $ \stt ->
->              case () of
->                      _ | stt == [] && t == ft -> [ft]
->                        | stt == [ft] && t == st -> [ft,st]
->                        | stt == [ft,st] && t == mt -> [ft,st,mt]
->                        | otherwise -> []
->
->            return (sp,t)
->            where
->              ft = IdStringTok "from"
->              st = IdStringTok "stdin"
->              mt = SymbolTok ";"
-
-== specialized token parsers
-
-> sqlString :: Parser Tok
-> sqlString = stringQuotes <|> stringLD
->   where
->     --parse a string delimited by single quotes
->     stringQuotes = StringTok "\'" <$> stringPar
->     stringPar = optional (char 'E') *> char '\''
->                 *> readQuoteEscape <* whiteSpace
->     --(readquoteescape reads the trailing ')
-
-have to read two consecutive single quotes as a quote character
-instead of the end of the string, probably an easier way to do this
-
-other escapes (e.g. \n \t) are left unprocessed
-
->     readQuoteEscape = do
->                       x <- anyChar
->                       if x == '\''
->                         then try ((x:) <$> (char '\'' *> readQuoteEscape))
->                              <|> return ""
->                         else (x:) <$> readQuoteEscape
-
-parse a dollar quoted string
-
->     stringLD = do
->                -- cope with $$ as well as $[identifier]$
->                tag <- try (char '$' *> ((char '$' *> return "")
->                                    <|> (identifierString <* char '$')))
->                s <- lexeme $ manyTill anyChar
->                       (try $ char '$' <* string tag <* char '$')
->                return $ StringTok ("$" ++ tag ++ "$") s
->
-> idString :: Parser Tok
-> idString = IdStringTok <$> identifierString
-
-> qidString :: Parser Tok
-> qidString = QIdStringTok <$> qidentifierString
-
-
->
-> positionalArg :: Parser Tok
-> positionalArg = char '$' >> PositionalArgTok <$> integer
-
-
-Lexing symbols:
-
-~~~~
-approach 1:
-try to keep multi symbol operators as single lexical items
-(e.g. "==", "~=="
-
-approach 2:
-make each character a separate element
-e.g. == lexes to ['=', '=']
-then the parser sorts this out
-
-Sort of using approach 1 at the moment, see below
-
-== notes on symbols in pg operators
-pg symbols can be made from:
-
-=_*/<>=~!@#%^&|`?
-
-no --, /* in symbols
-
-can't end in + or - unless contains
-~!@#%^&|?
-
-Most of this isn't relevant for the current lexer.
-
-== sql symbols for this lexer:
-
-sql symbol is one of
-()[],; - single character
-+-*/<>=~!@#%^&|`? string - one or more of these, parsed until hit char
-which isn't one of these (including whitespace). This will parse some
-standard sql expressions wrongly at the moment, work around is to add
-whitespace e.g. i think 3*-4 is valid sql, should lex as '3' '*' '-'
-'4', but will currently lex as '3' '*-' '4'. This is planned to be
-fixed in the parser.
-.. := :: : - other special cases
-A single * will lex as an identifier rather than a symbol, the parser
-deals with this.
-
-~~~~
-
-> sqlSymbol :: Parser Tok
-> sqlSymbol =
->   SymbolTok <$> lexeme (choice [
->                          replicate 1 <$> oneOf "()[],;"
->                         ,try $ string ".."
->                         ,string "."
->                         ,try $ string "::"
->                         ,try $ string ":="
->                         ,string ":"
->                         ,try $ string "$(" -- antiquote standard splice
->                         ,try $ string "$s(" -- antiquote string splice
->                         ,string "$i(" -- antiquote identifier splice
->                         ,many1 (oneOf "+-*/<>=~!@#%^&|`?")
->                         ])
->
-
-parse a number:
-digits
-digits.[digits][e[+-]digits]
-[digits].digits[e[+-]digits]
-digitse[+-]digits
-
-I'm sure the implementation can be simpler than this
-
-> sqlNumber :: Parser Tok
-> sqlNumber = NumberTok <$> lexeme (
->   choice [do
->           -- starts with digits
->           d <- digits
->           suff <- choice [-- complete fractional part
->                           try fracPart
->                          ,-- dot followed by optional exp
->                           -- check for .. symbol
->                           choice [try $ do
->                                         _ <- lookAhead $ string ".."
->                                         return []
->                                  ,do
->                                   _ <- char '.'
->                                   e <- optionMaybe expn
->                                   return $ concat $ catMaybes
->                                     [Just "."
->                                     ,e]
->                                   ]
->                          ,--no dot then expn
->                           expn
->                           -- just an integer
->                          ,return ""
->                          ]
->           return $ d ++ suff
->          ,fracPart
->          ])
->   where
->      fracPart = do
->           _ <- char '.'
->           d <- digits
->           e <- optionMaybe expn
->           return $ concat $ catMaybes
->             [Just "."
->             ,Just d
->             ,e]
->      expn = do
->        _ <- char 'e'
->        s <- optionMaybe (char '+' <|> char '-')
->        d <- digits
->        return $ concat $ catMaybes [Just "e"
->                                    ,fmap (:[]) s
->                                    ,Just d]
->      digits = many1 digit
-
-================================================================================
-
-additional parser bits and pieces
-
-include * in identifier strings during lexing. This parser is also
-used for keywords, so identifiers and keywords aren't distinguished
-until during proper parsing, and * isn't really examined until type
-checking
-
-> identifierString :: Parser String
-> identifierString = lexeme $ (letter <|> char '_')
->                             <:> many (alphaNum <|> char '_')
-
-todo:
-select adrelid as "a""a" from pg_attrdef;
-creates a column named: 'a"a' with a double quote in it
-
-> qidentifierString :: Parser String
-> qidentifierString = lexeme $ char '"' *> many (noneOf "\"") <* char '"'
-
-
-parse the block of inline data for a copy from stdin, ends with \. on
-its own on a line
-
-> copyPayload :: Parser Tok
-> copyPayload = CopyPayloadTok <$> lexeme (getLinesTillMatches "\\.\n")
->   where
->     getLinesTillMatches s = do
->                             x <- getALine
->                             if x == s
->                               then return ""
->                               else (x++) <$> getLinesTillMatches s
->     getALine = (++"\n") <$> manyTill anyChar (try newline)
->
-
-================================================================================
-
-= parsec pass throughs
-
-> --symbol :: String -> Parser String
-> --symbol = P.symbol lexer
->
-
-> integer :: Parser Integer
-> integer = lexeme $ P.integer lexer
-
-> whiteSpace :: Parser ()
-> whiteSpace = P.whiteSpace lexer
->
-> lexeme :: Parser a -> Parser a
-> lexeme = P.lexeme lexer
-
-this lexer isn't really used as much as it could be, probably some of
-the fields are not used at all (like identifier and operator stuff)
-
-> lexer :: P.GenTokenParser String LexState Identity
-> lexer = P.makeTokenParser (emptyDef {
->                             P.commentStart = "/*"
->                            ,P.commentEnd = "*/"
->                            ,P.commentLine = "--"
->                            ,P.nestedComments = False
->                            ,P.identStart = letter <|> char '_'
->                            ,P.identLetter    = alphaNum <|> oneOf "_"
->                            ,P.opStart        = P.opLetter emptyDef
->                            ,P.opLetter       = oneOf opLetters
->                            ,P.reservedOpNames= []
->                            ,P.reservedNames  = []
->                            ,P.caseSensitive  = False
->                            })
->
-> opLetters :: String
-> opLetters = ".:^*/%+-<>=|!"
diff --git a/src/Database/HsSqlPpp/Parsing/ParseErrors.lhs b/src/Database/HsSqlPpp/Parsing/ParseErrors.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Parsing/ParseErrors.lhs
+++ /dev/null
@@ -1,76 +0,0 @@
-
-convert error messages to show source text fragment with little hat,
-plus output error location in emacs friendly format.
-
->
-> module Database.HsSqlPpp.Parsing.ParseErrors
->     (toParseErrorExtra
->     ,ParseErrorExtra(..)) where
->
-> import Text.Parsec
-> import Control.Monad.Error
->
-> showPE :: ParseError -> Maybe (Int,Int) -> String -> String
-> showPE pe sp src = show pe ++ "\n" ++ pePosToEmacs pe
->                    ++ "\n" ++ peToContext pe sp src
->
-> pePosToEmacs :: ParseError -> String
-> pePosToEmacs pe = let p = errorPos pe
->                       f = sourceName p
->                       l = sourceLine p
->                       c = sourceColumn p
->                   in f ++ ":" ++ show l ++ ":" ++ show c ++ ":"
->
-> peToContext :: ParseError -> Maybe (Int,Int) -> String -> String
-> peToContext pe sp src =
->      let ls = lines src
->          line = safeGet ls(lineNo - 1)
->          prelines = map (safeGet ls) [(lineNo - 5) .. (lineNo - 2)]
->          postlines = map (safeGet ls) [lineNo .. (lineNo + 5)]
->          caretLine = replicate (colNo - 1) ' ' ++ "^"
->          errorHighlightText = prelines
->                               ++ [line, caretLine, "ERROR HERE"]
->                               ++ postlines
->     in "\nContext:\n"
->        ++ unlines (trimLines errorHighlightText) ++ "\n"
->     where
->       safeGet a i = if i < 0 || i >= length a
->                       then ""
->                       else a !! i
->       trimLines = trimStartLines . reverse . trimStartLines . reverse
->       trimStartLines = dropWhile (=="")
->       pos = errorPos pe
->       lineNo = sourceLine pos - adjLine
->       colNo = sourceColumn pos
->       adjLine = case sp of
->                         Just (l, _) -> l - 1
->                         Nothing -> 0
->
-> -- | Simple wrapper to allow showing the source context of a ParseError
-> data ParseErrorExtra =
->        ParseErrorExtra {
->                        -- | wrapped error
->                        parseErrorError :: ParseError
->                        -- | source position
->                        -- adjustment to get the
->                        -- context bit in error
->                        -- messages right - this is
->                        -- the same as what is passed
->                        -- into parseSqlWithPosition
->                        ,parseErrorPosition :: Maybe (Int, Int)
->                        -- | sql source
->                        ,parseErrorSqlSource :: String
->                        }
->
-> instance Show ParseErrorExtra where
->     show (ParseErrorExtra pe sp src) = showPE pe sp src
->
-> instance Error ParseErrorExtra where
->   noMsg = ParseErrorExtra (error "instance Error ParseErrorExtra") Nothing "unknown"
->   strMsg = ParseErrorExtra (error "instance Error ParseErrorExtra") Nothing
->
-> toParseErrorExtra :: Either ParseError b -> Maybe (Int,Int) -> String
->                   -> Either ParseErrorExtra b
-> toParseErrorExtra a sp src = case a of
->                                Left pe -> Left $ ParseErrorExtra pe sp src
->                                Right x -> Right x
diff --git a/src/Database/HsSqlPpp/Parsing/ParserInternal.lhs b/src/Database/HsSqlPpp/Parsing/ParserInternal.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Parsing/ParserInternal.lhs
+++ /dev/null
@@ -1,1884 +0,0 @@
-
-The main file for parsing sql, uses parsec. Not sure if parsec is the
-right choice, but it seems to do the job pretty well at the moment.
-
-> {-# LANGUAGE FlexibleContexts,ExplicitForAll,TupleSections #-}
-> -- | Functions to parse SQL.
-> module Database.HsSqlPpp.Parsing.ParserInternal
->     (-- * Main
->      parseStatements
->     ,parseStatementsWithPosition
->     ,parseStatementsFromFile
->     ,parseQueryExpr
->     ,parsePlpgsqlWithPosition
->      -- * Testing
->     ,parseScalarExpr
->     ,parseScalarExprWithPosition
->     ,parsePlpgsql
->      -- * errors
->     ,ParseErrorExtra(..)
->      -- other helpers for internal use
->     ,tableAttribute
->     ,keyword
->     ,parens
->     ,symbol
->     ,idString
->     ,commaSep1
->     ,commaSep
->     ) where
->
-> import Text.Parsec hiding(many, optional, (<|>), string, label)
-> import Text.Parsec.Expr
-> import Text.Parsec.String
-> import Text.Parsec.Perm
->
-> import Control.Applicative
-> import Control.Monad.Identity
->
-> import Data.Maybe
-> import Data.Char
->
-> import Data.Generics.Uniplate.Data
-> import Data.Data hiding (Prefix,Infix)
->
-> import Database.HsSqlPpp.Parsing.Lexer
-> import Database.HsSqlPpp.Parsing.ParseErrors
-> import Database.HsSqlPpp.Ast
-> import Database.HsSqlPpp.Annotation as A
-> import Database.HsSqlPpp.Utils.Utils
-> import Database.HsSqlPpp.Catalog
-> --import Debug.Trace
-
---------------------------------------------------------------------------------
-
-Top level parsing functions
-===========================
-
-> parseStatements :: String -- ^ filename to use in errors
->                 -> String -- ^ a string containing the sql to parse
->                 -> Either ParseErrorExtra [Statement]
-> parseStatements f s =
->   parseIt l sqlStatements f Nothing s startState
->   where l = lexSqlText f s
->
-> parseStatementsWithPosition :: FilePath -- ^ filename to use in errors
->                             -> Int -- ^ adjust line number in errors by adding this
->                             -> Int -- ^ adjust column in errors by adding this
->                             -> String -- ^ a string containing the sql to parse
->                             -> Either ParseErrorExtra [Statement]
-> parseStatementsWithPosition f l c s =
->   parseIt lx sqlStatements f (Just (l,c)) s startState
->   where lx = lexSqlText f s
-> --parseAntiSql f l c s
->
-> parseStatementsFromFile :: FilePath -- ^ file name of file containing sql
->                         -> IO (Either ParseErrorExtra [Statement])
-> parseStatementsFromFile fn = do
->   sc <- readFile fn
->   x <- lexSqlFile fn
->   return $ parseIt x sqlStatements fn Nothing sc startState
->
-
-> parseQueryExpr :: String -- ^ filename to use in errors
->                -> String -- ^ a string containing the sql to parse
->                -> Either ParseErrorExtra QueryExpr
-> parseQueryExpr f s =
->   parseIt l pqe f Nothing s startState
->   where
->     l = lexSqlText f s
->     pqe :: SParser QueryExpr
->     pqe = do
->           (QueryStatement _ q) <- queryStatement
->           _ <- optional (symbol ";")
->           eof
->           return q
-
-> -- | Parse expression fragment, used for testing purposes
-> parseScalarExpr :: String -- ^ filename for error messages
->                 -> String -- ^ sql string containing a single expression,
->                           -- with no trailing ';'
->                 -> Either ParseErrorExtra ScalarExpr
-> parseScalarExpr f s =
->   parseIt l (expr <* eof) f Nothing s startState
->   where l = lexSqlText f s
->
-> -- | Parse plpgsql statements, used for testing purposes -
-> -- this can be used to parse a list of plpgsql statements which
-> -- aren't contained in a create function.
-> -- (The produced ast won't pass a type check.)
-> parsePlpgsql :: String
->              -> String
->              -> Either ParseErrorExtra [Statement]
-> parsePlpgsql f s =
->   parseIt l p f Nothing s startState
->   where
->     l = lexSqlText f s
->     p = many plPgsqlStatement <* eof
->
-> parsePlpgsqlWithPosition :: String
->                  -> Int
->                  -> Int
->                  -> String
->                  -> Either ParseErrorExtra [Statement]
-> parsePlpgsqlWithPosition f l c s =
->   parseIt lx p f ps s startState
->   where
->     lx = lexSqlText f s
->     p = many plPgsqlStatement <* eof
->     ps = Just (l,c)
->
-> parseScalarExprWithPosition :: String
->                     -> Int
->                     -> Int
->                     -> String
->                     -> Either ParseErrorExtra ScalarExpr
-> parseScalarExprWithPosition f l c s =
->   parseIt lx p f ps s startState
->   where
->     lx = lexSqlText f s
->     p = expr <* eof
->     ps = Just (l,c)
->
-> -- utility function to do error handling in one place
-> parseIt :: forall t s u b.(Stream s Identity t, Data b) =>
->            Either ParseErrorExtra s
->         -> Parsec s u b
->         -> SourceName
->         -> Maybe (Int,Int)
->         -> String
->         -> u
->         -> Either ParseErrorExtra b
-> parseIt lexed parser fn sp src ss =
->     case lexed of
->                Left er -> Left er
->                Right toks -> let r1 = runParser parser ss fn toks
->                              in case toParseErrorExtra r1 sp src of
->                                   Left er -> Left er
->                                   Right t -> Right $ fixupTree t
-
-
---------------------------------------------------------------------------------
-
-> type SParser =  GenParser Token ParseState
-
-Parsing top level statements
-============================
-
-> sqlStatements :: SParser [Statement]
-> sqlStatements = many (sqlStatement True) <* eof
->
-> sqlStatement :: Bool -> SParser Statement
-> sqlStatement reqSemi =
->    (choice [
->      antiStatement
->     ,queryStatement
->     ,insert
->     ,update
->     ,delete
->     ,truncateSt
->     ,copy
->     ,set
->     ,notify
->     ,keyword "create" *>
->              choice [
->                 createTable
->                ,createSequence
->                ,createType
->                ,createFunction
->                ,createView
->                ,createDomain
->                ,createLanguage
->                ,createTrigger]
->     ,keyword "alter" *>
->              choice [
->                 alterSequence
->                ,alterTable]
->     ,keyword "drop" *>
->              choice [
->                 dropSomething
->                ,dropFunction]]
->     <* (if reqSemi
->           then symbol ";" >> return ()
->           else optional (symbol ";") >> return ()))
->    <|> copyData
-
---------------------------------------------------------------------------------
-
-statement flavour parsers
-=========================
-
-top level/sql statements first
-
-select
-------
-
-select parser, parses things starting with the keyword 'select'
-
-supports plpgsql 'select into' only for the variants which look like
-'select into ([targets]) [columnNames] from ...
-or
-'select [columnNames] into ([targets]) from ...
-This should be changed so it can only parse an into clause when
-expecting a plpgsql statement.
-
-recurses to support parsing excepts, unions, etc.
-this recursion needs refactoring cos it's a mess
-
-> queryStatement :: SParser Statement
-> queryStatement = QueryStatement <$> pos <*> pQueryExpr
->
-> into :: SParser (Statement -> Statement)
-> into = do
->   p <- pos <* keyword "into"
->   st <- option False (True <$ keyword "strict")
->   is <- commaSep1 name
->   return $ \s -> Into p st is s
-
-> intoQueryStatement :: SParser Statement
-> intoQueryStatement = do
->   (i,_) <- pQueryExprX True
->   case i of
->     Nothing -> fail "not into"
->     Just s -> return s
-
-> pQueryExpr :: SParser QueryExpr
-> pQueryExpr = snd <$> pQueryExprX False
-
-bit convoluted to parse the into part
-
-> pQueryExprX :: Bool -> SParser (Maybe Statement, QueryExpr)
-> pQueryExprX allowInto =
->   ((Nothing,) <$> with)
->   <|>  buildExpressionParser combTable selFactor
->   where
->         selFactor = choice [try ((Nothing,) <$> (parens pQueryExpr))
->                            ,selQuerySpec
->                            ,(Nothing,) <$> values]
->         with = WithQueryExpr <$> (pos <* keyword "with")
->                              <*> commaSep1 withQuery
->                              <*> pQueryExpr
->         withQuery = WithQuery <$> pos
->                               <*> nameComponent
->                               <*> tryOptionMaybe (parens $ commaSep nameComponent)
->                               <*> (keyword "as" *> parens pQueryExpr)
->         combTable =
->            [map makeOp [(Except, keyword "except")
->                        ,(Intersect, keyword "intersect")
->                        ,(UnionAll, try (keyword "union" *> keyword "all"))
->                        ,(Union, keyword "union")]]
->         makeOp (c,p) =
->            Infix (do
->                   cmb <- CombineQueryExpr
->                          <$> pos
->                          <*> (c <$ p)
->                   return $ \s0 s1 -> (Nothing, cmb (snd s0) (snd s1))
->                  ) AssocLeft
->         selQuerySpec = do
->           p <- pos <* keyword "select"
->           d <- option Dupes (Distinct <$ keyword "distinct")
->           -- hacky parsing of sql server 'top n' style select
->           -- quiz: what happens when you use top n and limit at the same time?
->           tp <- optionMaybe $ try
->                 $ keyword "top" *> (NumberLit <$> pos <*> (show <$> integer))
->           -- todo: work out how to make this work properly - need to return
->           -- the into
->           (sl,intoBit) <- if allowInto
->                           then permute ((,)
->                                         <$$> try selectList
->                                         <|?> (Nothing, Just <$> into))
->                           else (,Nothing) <$> selectList
->           s <- Select p d sl
->                    <$> option [] from
->                    <*> optionMaybe whereClause
->                    <*> option [] groupBy
->                    <*> optionMaybe having
->                    <*> orderBy
->                    <*> option tp (Just <$> limit)
->                    <*> optionMaybe offset
->           return (case intoBit of
->                       Just f -> Just $ f $ QueryStatement p s
->                       Nothing -> Nothing
->                  ,s)
->         from = keyword "from" *> commaSep1 tableRef
->         groupBy = keyword "group" *> keyword "by"
->                   *> commaSep1 expr
->         having = keyword "having" *> expr
->         limit = keyword "limit" *> expr
->         offset = keyword "offset" *> expr
->         values = Values <$> (pos <* keyword "values")
->                         <*> commaSep1 (parens $ commaSep1 expr)
-
-> orderBy :: SParser [(ScalarExpr,Direction)]
-> orderBy = option []
->             (keyword "order" *> keyword "by"
->                              *> commaSep1 oneOrder)
->           where
->             oneOrder = (,) <$> expr
->                        <*> option Asc (choice [
->                                         Asc <$ keyword "asc"
->                                        ,Desc <$ keyword "desc"])
-
-
-table refs
-have to cope with:
-a simple tableref i.e just a name
-an aliased table ref e.g. select a.b from tbl as a
-a sub select e.g. select a from (select b from c)
- - these are handled in nonJoinTref
-then you combine by seeing if there is a join looking prefix
-
-> tableRef :: SParser TableRef
-> tableRef =
->   trefTerm >>= maybeParseAnotherJoin
->   where
->         maybeParseAnotherJoin tr1 =
->           choice [
->                 do
->                   p2 <- pos
->                   (nat,jt) <- joinKw
->                   JoinTref p2 tr1 nat jt
->                                    <$> trefTerm
->                                    <*> onExpr
->                                    <*> palias
->                     >>= maybeParseAnotherJoin
->                ,return tr1]
->         trefTerm = nonJoinTref
->                    <|> try (parens tableRef)
->         nonJoinTref = try $ optParens $ do
->                   p2 <- pos
->                   choice [
->                          SubTref p2
->                          <$> parens pQueryExpr
->                          <*> palias
->                         ,FunTref p2
->                          <$> try (identifier >>= functionCallSuffix)
->                          <*> palias
->                         ,Tref p2
->                          <$> nonKeywordName
->                          <*> palias]
->         joinKw :: SParser (Natural, JoinType)
->         joinKw = do
->              --look for the join flavour first
->              n <- option Unnatural (Natural <$ keyword "natural")
->              jt <- choice [
->                     LeftOuter <$ try (keyword "left"
->                                       *> optional (keyword "outer"))
->                    ,RightOuter <$ try (keyword "right"
->                                        *> optional (keyword "outer"))
->                    ,FullOuter <$ try (keyword "full"
->                                       *> optional (keyword "outer"))
->                    ,Cross <$ keyword "cross"
->                    ,Inner <$ optional (keyword "inner")]
->              --recurse back to tref to read the table
->              keyword "join"
->              return (n,jt)
->         onExpr = choice [
->                  Just <$> (JoinOn <$> pos <*> (keyword "on" *> expr))
->                 ,Just <$> (JoinUsing <$> pos
->                            <*> (keyword "using" *> columnNameList))
->                 ,return Nothing]
->         palias = do
->            p <- pos
->            option (NoAlias p)
->                    (try $ optionalSuffix
->                       (TableAlias p) (optional (keyword "as") *> nonKeywordNc)
->                       (FullAlias p) () (parens $ commaSep1 nameComponent))
->
-> optParens :: SParser a
->           -> SParser a
-> optParens p = try (parens p) <|> p
-
-
-insert, update and delete
--------------------------
-
-insert statement: supports option column name list,
-multiple rows to insert and insert from select statements
-
-> insert :: SParser Statement
-> insert = Insert
->          <$> pos <* keyword "insert" <* keyword "into"
->          <*> name
->          <*> option [] (try columnNameList)
->          <*> pQueryExpr
->          <*> tryOptionMaybe returning
->
-> update :: SParser Statement
-> update = Update
->          <$> pos <* keyword "update"
->          <*> name
->          <*> (keyword "set" *> commaSep1 setClause)
->          <*> option [] (keyword "from" *> commaSep1 tableRef)
->          <*> tryOptionMaybe whereClause
->          <*> tryOptionMaybe returning
->     where
->       setClause =
->         choice [do
->           p <- pos
->           l <- parens (commaSep1 nameComponent)
->           symbol "="
->           r <- parens (commaSep1 expr)
->           return $ MultiSetClause p l $ FunCall p (nm p "!rowctor") r
->         ,do
->           p <- pos
->           l <- nameComponent
->           symbol "="
->           r <- expr
->           return $ SetClause p l r]
-
-> nm :: Annotation -> String -> Name
-> nm a s = Name a [Nmc s]
-
-> delete :: SParser Statement
-> delete = Delete
->          <$> pos <* keyword "delete" <* keyword "from"
->          <*> name
->          <*> option [] (keyword "using" *> commaSep1 tableRef)
->          <*> tryOptionMaybe whereClause
->          <*> tryOptionMaybe returning
->
-
-other dml-type stuff
---------------------
-
-> truncateSt :: SParser Statement
-> truncateSt =
->            Truncate
->            <$> pos <* keyword "truncate" <* optional (keyword "table")
->            <*> commaSep1 name
->            <*> option ContinueIdentity (choice [
->                                 ContinueIdentity <$ (keyword "continue"
->                                                      <* keyword "identity")
->                                ,RestartIdentity <$ (keyword "restart"
->                                                     <* keyword "identity")])
->            <*> cascade
->
-> copy :: SParser Statement
-> copy = do
->        p <- pos
->        keyword "copy"
->        tableName <- name
->        cols <- option [] (parens $ commaSep1 nameComponent)
->        keyword "from"
->        src <- choice [
->                CopyFilename <$> extrStr <$> stringLit
->               ,Stdin <$ keyword "stdin"]
->        return $ Copy p tableName cols src
->
-> copyData :: SParser Statement
-> copyData = CopyData <$> pos <*> mytoken (\tok ->
->                                         case tok of
->                                                  CopyPayloadTok n -> Just n
->                                                  _ -> Nothing)
->
-
---------------------------------------------------------------------------------
-
-misc
-====
-
-> set :: SParser Statement
-> set = Set <$> pos
->           <*> (keyword "set" *> idString)
->           <*> ((keyword "to" <|> symbol "=") *>
->               commaSep1 sv)
->       where
->         sv = choice [
->               SetStr <$> pos <*> stringN
->              ,SetId <$> pos <*> idString
->              ,SetNum <$> pos <*> (try (fromInteger <$> integer)
->                                   <|> (read <$> numString))]
->
-> notify :: SParser Statement
-> notify = Notify <$> pos
->                 <*> (keyword "notify" *> idString)
-
---------------------------------------------------------------------------------
-
-ddl
-===
-
-> createTable :: SParser Statement
-> createTable = do
->   p <- pos
->   keyword "table"
->   tname <- name
->   choice [
->      CreateTableAs p tname <$> (keyword "as" *> pQueryExpr)
->     ,uncurry (CreateTable p tname) <$> readAttsAndCons]
->   where
->     --parse our unordered list of attribute defs or constraints, for
->     --each line want to try the constraint parser first, then the
->     --attribute parser, so you need the swap to feed them in the
->     --right order into createtable
->     readAttsAndCons = parens (swap <$> multiPerm
->                                          (try tableConstraint)
->                                          tableAttribute
->                                          (symbol ","))
->                       where swap (a,b) = (b,a)
->
-> tableAttribute :: SParser AttributeDef
-> tableAttribute = AttributeDef
->                <$> pos
->                <*> nameComponent
->                <*> typeName
->                <*> tryOptionMaybe (keyword "default" *> expr)
->                <*> many rowConstraint
->   where
->     rowConstraint = do
->        p <- pos
->        cn <- option "" (keyword "constraint" *> idString)
->        choice [
->           RowUniqueConstraint p cn <$ keyword "unique"
->          ,RowPrimaryKeyConstraint p cn <$ keyword "primary" <* keyword "key"
->          ,RowCheckConstraint p cn <$> (keyword "check" *> parens expr)
->          ,NullConstraint p cn <$ keyword "null"
->          ,NotNullConstraint p cn <$ (keyword "not" <* keyword "null")
->          ,RowReferenceConstraint p cn
->          <$> (keyword "references" *> name)
->          <*> option Nothing (try $ parens $ Just <$> nameComponent)
->          <*> onDelete
->          <*> onUpdate
->          ]
-
-
->
-> onDelete,onUpdate :: SParser Cascade
-> onDelete = onSomething "delete"
-> onUpdate = onSomething "update"
->
-> onSomething :: String -> SParser Cascade
-> onSomething k = option Restrict $ try $ keyword "on"
->                 *> keyword k *> cascade
->
-> tableConstraint :: SParser Constraint
-> tableConstraint = do
->                 p <- pos
->                 cn <- option "" (keyword "constraint" *> option "" conName)
->                 choice [
->                    UniqueConstraint p cn
->                    <$> try (keyword "unique" *> optParens columnNameList)
->                    ,PrimaryKeyConstraint p cn
->                    <$> try (keyword "primary" *> keyword "key"
->                                     *> choice [
->                                             (:[]) <$> nameComponent
->                                            ,parens (commaSep1 nameComponent)])
->                    ,CheckConstraint p cn
->                    <$>try (keyword "check" *> parens expr)
->                    ,ReferenceConstraint p cn
->                    <$> try (keyword "foreign" *> keyword "key"
->                             *> parens (commaSep1 nameComponent))
->                    <*> (keyword "references" *> name)
->                    <*> option [] (parens $ commaSep1 nameComponent)
->                    <*> onUpdate
->                    <*> onDelete]
->                 where
->                   conName = try $ do
->                             x <- idString
->                             if map toLower x `elem` [
->                                     "unique"
->                                    ,"primary"
->                                    ,"check"
->                                    ,"foreign"
->                                    ,"references"]
->                               then fail "not keyword (constraint name)"
->                               else return x
->
-> alterTable :: SParser Statement
-> alterTable = AlterTable <$> (pos <* keyword "table"
->                              <* optional (keyword "only"))
->                         <*> name
->                         <*> many1 action
->              where action = choice [
->                              AlterColumnDefault
->                              <$> (pos <* keyword "alter" <* keyword "column")
->                              <*> nameComponent
->                              <*> (keyword "set" *> keyword "default" *> expr)
->                             ,AddConstraint
->                              <$> (pos <* keyword "add")
->                              <*> tableConstraint]
->
-> createType :: SParser Statement
-> createType = CreateType
->              <$> pos <* keyword "type"
->              <*> name
->              <*> (keyword "as" *> parens (commaSep1 typeAtt))
->   where
->     typeAtt = TypeAttDef <$> pos <*> nameComponent <*> typeName
->
-> createSequence :: SParser Statement
-> createSequence = do
->   p <- pos
->   keyword "sequence"
->   snm <- name
->   (stw, incr, mx, mn, c) <-
->      permute ((,,,,) <$?> (1,startWith)
->                      <|?> (1,increment)
->                      <|?> ((2::Integer) ^ (63::Integer) - 1, maxi)
->                      <|?> (1, mini)
->                      <|?> (1, cache))
->   return $ CreateSequence p snm incr mn mx stw c
->   where
->     startWith = keyword "start" *> optional (keyword "with") *> integer
->     increment = keyword "increment" *> optional (keyword "by") *> integer
->     maxi = (2::Integer) ^ (63::Integer) - 1
->            <$ try (keyword "no" <* keyword "maxvalue")
->     mini = 1 <$ try (keyword "no" <* keyword "minvalue")
->     cache = keyword "cache" *> integer
->
-> alterSequence :: SParser Statement
-> alterSequence = AlterSequence <$> pos
->                               <*> (keyword "sequence" *> name)
->                               <*> (keyword "owned"
->                                    *> keyword "by"
->                                    *> name)
-
-create function, support sql functions and plpgsql functions. Parses
-the body in both cases and provides a statement list for the body
-rather than just a string.
-
-> createFunction :: SParser Statement
-> createFunction = do
->   p <- pos
->   rep <- choice [NoReplace <$ keyword "function"
->                 ,Replace <$ mapM_ keyword ["or", "replace", "function"]
->                 ]
->   fnName <- name
->   params <- parens $ commaSep param
->   retType <- keyword "returns" *> typeName
->   ((bodypos,body), lang,vol) <-
->     permute ((,,) <$$> parseAs
->                   <||> readLang
->                   <|?> (Volatile,pVol))
->   case parseBody lang body bodypos of
->        Left er -> fail er
->        Right b ->
->          return $ CreateFunction p fnName params retType rep lang b vol
->     where
->         parseAs = do
->                    keyword "as"
->                    bodypos <- toMySp <$> getPosition
->                    body <- stringLit
->                    return (bodypos,body)
->         pVol = matchAKeyword [("volatile", Volatile)
->                              ,("stable", Stable)
->                              ,("immutable", Immutable)]
->         readLang = keyword "language" *> matchAKeyword [("plpgsql", Plpgsql)
->                                                        ,("sql",Sql)]
->         parseBody :: Language -> ScalarExpr -> MySourcePos
->                   -> Either String FnBody
->         parseBody lang body (fileName,line,col) =
->             case parseIt
->                   (lexSqlTextWithPosition fileName line col (extrStr body))
->                   (functionBody lang)
->                   fileName
->                   (Just (line,col))
->                   (extrStr body)
->                   () of
->                      Left er@(ParseErrorExtra _ _ _) -> Left $ show er
->                      Right body' -> Right body'
->         -- sql function is just a list of statements, the last one
->         -- has the trailing semicolon optional
->         functionBody Sql = do
->            p <- pos
->            a <- many (try $ sqlStatement True)
->            -- this makes my head hurt, should probably write out
->            -- more longhand
->            SqlFnBody p <$> option a ((\b -> a++[b]) <$> sqlStatement False)
->         -- plpgsql function has an optional declare section, plus
->         -- the statements are enclosed in begin ... end; (semi colon
->         -- after end is optional)
->         functionBody Plpgsql =
->             PlpgsqlFnBody <$> pos <*> do
->                    p <- pos
->                    l <- label
->                    block p l <* optional (symbol ";") <* eof
-
-params to a function
-
-> param :: SParser ParamDef
-> param = choice [
->          try (ParamDef <$> pos <*> nameComponent <*> typeName)
->         ,ParamDefTp <$> pos <*> typeName]
-
-variable declarations in a plpgsql function
-
-> varDef :: SParser VarDef
-> varDef = do
->   p <- pos
->   a <- nameComponent
->   choice [do
->           keyword "alias"
->           keyword "for"
->           choice [
->             VarAlias p a <$> name
->            ,ParamAlias p a <$> liftPositionalArgTok]
->          ,VarDef p a
->           <$> typeName
->           <*> tryOptionMaybe ((symbol ":=" <|> symbol "=")*> expr)
->           ]
->     <* symbol ";"
->
-> createView :: SParser Statement
-> createView = CreateView
->              <$> pos <* keyword "view"
->              <*> name
->              <*> tryOptionMaybe (parens $ commaSep nameComponent)
->              <*> (keyword "as" *> pQueryExpr)
-
->
-> createDomain :: SParser Statement
-> createDomain = CreateDomain
->                <$> pos <* keyword "domain"
->                <*> name
->                <*> (tryOptionMaybe (keyword "as") *> typeName)
->                <*> option "" (keyword "constraint" *> idString)
->                <*> tryOptionMaybe (keyword "check" *> parens expr)
->
-> dropSomething :: SParser Statement
-> dropSomething = do
->   p <- pos
->   x <- try (choice [
->                  Domain <$ keyword "domain"
->                 ,Type <$ keyword "type"
->                 ,Table <$ keyword "table"
->                 ,View <$ keyword "view"
->             ])
->   (i,e,r) <- parseDrop name
->   return $ DropSomething p x i e r
->
-> dropFunction :: SParser Statement
-> dropFunction = do
->                p <- pos
->                keyword "function"
->                (i,e,r) <- parseDrop pFun
->                return $ DropFunction p i e r
->                where
->                  pFun = (,) <$> name
->                             <*> parens (commaSep typeName)
->
-> parseDrop :: SParser a
->           -> SParser (IfExists, [a], Cascade)
-> parseDrop p = (,,)
->               <$> ifExists
->               <*> commaSep1 p
->               <*> cascade
->     where
->       ifExists = option Require
->                  (try $ IfExists <$ (keyword "if"
->                                      *> keyword "exists"))
->
-> createLanguage :: SParser Statement
-> createLanguage =
->   CreateLanguage <$> pos
->                  <*> (optional (keyword "procedural") *>
->                       keyword "language" *>
->                       idString)
->
-> createTrigger :: SParser Statement
-> createTrigger =
->   CreateTrigger <$> pos
->                 <*> (keyword "trigger" *> nameComponent)
->                 <*> twhen
->                 <*> tevents
->                 <*> (keyword "on" *> name)
->                 <*> tfiring
->                 <*> (keyword "execute" *> keyword "procedure"
->                      *> name)
->                 <*> parens (commaSep expr)
->   where
->     twhen = choice [TriggerBefore <$ keyword "before"
->                    ,TriggerAfter <$ keyword "after"]
->     tevents :: SParser [TriggerEvent]
->     tevents = sepBy1 (choice [
->                          AntiTriggerEvent <$> splice
->                         ,TInsert <$ keyword "insert"
->                         ,TUpdate <$ keyword "update"
->                         ,TDelete <$ keyword "delete"]) (keyword "or")
->     tfiring = option EachStatement
->                 (keyword "for" *> optional (keyword "each") *>
->                 choice [
->                   EachRow <$ keyword "row"
->                  ,EachStatement <$ keyword "statement"])
-
-anti statement
---------------
-
-> antiStatement :: SParser Statement
-> antiStatement = AntiStatement <$> splice
-
---------------------------------------------------------------------------------
-
-component parsers for sql statements
-====================================
-
-> whereClause :: SParser ScalarExpr
-> whereClause = keyword "where" *> expr
-
-selectlist and selectitem: the bit between select and from
-check for into either before the whole list of select columns
-or after the whole list
-
-> selectList :: SParser SelectList
-> selectList = SelectList <$> pos
->              <*> itemList
->     {-pos >>= \p ->
->     choice [
->         --flip (SelectList p) <$> readInto <*> itemList
->        SelectList p <$> itemList] -- <*> option [] readInto]-}
->   where
->     --readInto = keyword "into" *> commaSep1 qName
->     itemList = commaSep1 selectItem
->     selectItem = pos >>= \p ->
->                  optionalSuffix
->                    (SelExp p) (starExpr <|> expr)
->                    (SelectItem p) () (keyword "as" *> nameComponent)
-
-should try to factor this into the standard expr parse (use a flag) so
-that can left factor the 'name component . '  part and avoid the try
-
-> starExpr :: SParser ScalarExpr
-> starExpr = choice [Star <$> pos <* symbol "*"
->                   ,try $ do
->                          p <- pos
->                          nc <- nameComponent
->                          symbol "."
->                          symbol "*"
->                          return $ QStar p nc]
-
->
-> returning :: SParser SelectList
-> returning = keyword "returning" *> selectList
->
-> columnNameList :: SParser [NameComponent]
-> columnNameList = parens $ commaSep1 nameComponent
->
-> typeName :: SParser TypeName
-> typeName =
->   choice [
->      SetOfTypeName <$> pos <*> (keyword "setof" *> typeName)
->     ,otherTypeName]
->   where
->     otherTypeName = do
->        p <- pos
->        s <- map toLower <$> pTypeNameString
->        choice [try (Prec2TypeName p s
->                     <$> (symbol "(" *> integer)
->                     <*> (symbol "," *> integer <* symbol ")"))
->               ,PrecTypeName p s <$> parens integer
->               ,arrayTypeName p s
->               ,return $ SimpleTypeName p s]
->     arrayTypeName p s = ArrayTypeName p (SimpleTypeName p s)
->                         <$ symbol "[" <* symbol "]"
->     --todo: add special cases for the other type names with spaces in them
->     pTypeNameString = ("double precision" <$ try (keyword "double"
->                                                   <* keyword "precision"))
->                       <|> idString
->
-> cascade :: SParser Cascade
-> cascade = option Restrict (choice [
->                             Restrict <$ keyword "restrict"
->                            ,Cascade <$ keyword "cascade"])
-
---------------------------------------------------------------------------------
-
-plpgsql statements
-==================
-
-> plPgsqlStatement :: SParser Statement
-> plPgsqlStatement =
->    choice [
->      -- modified sql statements
->      choice [
->         try intoQueryStatement
->        ,choice [insert
->                ,update
->                ,delete] >>= intoSuffix
->        ] <* symbol ";"
->     -- regular sql statements
->     ,sqlStatement True
->     -- regular plpgsql statements
->     ,choice [
->           continue
->          ,execute >>= intoSuffix
->          ,caseStatement
->          ,assignment
->          ,ifStatement
->          ,returnSt
->          ,raise
->          ,perform
->          ,labelPrefixed
->          ,nullStatement
->          ,exitStatement]
->          <* symbol ";"
->     ]
->    where
->      intoSuffix e =
->        option e (try $ do
->                  i <- into
->                  return $ i e)
->      labelPrefixed = do
->        p <- pos
->        l <- label
->        choice [block p l
->               ,forStatement p l
->               ,whileStatement p l
->               ,loopStatement p l]
-
-> label :: SParser (Maybe String)
-> label = optional (symbol "<<" *> idString <* symbol ">>")
->
-> block :: Annotation -> Maybe String -> SParser Statement
-> block p l = Block p l
->             <$> option [] declarePart
->             <*> statementPart
->         where
->           statementPart = keyword "begin"
->                     *> many plPgsqlStatement
->                     <* keyword "end"
->           declarePart = keyword "declare"
->                         *> manyTill (try varDef) (lookAhead $ keyword "begin")
->
->
-> nullStatement :: SParser Statement
-> nullStatement = NullStatement <$> (pos <* keyword "null")
->
-> exitStatement :: SParser Statement
-> exitStatement = ExitStatement <$> (pos <* keyword "exit")
->                               <*> optional idString
->
->
-> continue :: SParser Statement
-> continue = ContinueStatement <$> (pos <* keyword "continue")
->                              <*> optional idString
->
-> perform :: SParser Statement
-> perform = Perform <$> (pos <* keyword "perform") <*> expr
->
-> execute :: SParser Statement
-> execute = Execute <$> (pos <* keyword "execute")
->          <*> expr
->          {-pos >>= \p ->  >>
->           optionalSuffix
->             (Execute p) expr
->             (ExecuteInto p) () readInto
->     where
->       readInto = keyword "into" *> commaSep1 idString-}
->
-> assignment :: SParser Statement
-> assignment = Assignment
->              <$> pos
->              -- put the := in the first try to attempt to get a
->              -- better error if the code looks like malformed
->              -- assignment statement
->              <*> try (name <* (symbol ":=" <|> symbol "="))
->              <*> expr
->
-> returnSt :: SParser Statement
-> returnSt = pos >>= \p -> keyword "return" >>
->            choice [
->             ReturnNext p <$> (keyword "next" *> expr)
->            ,ReturnQuery p <$> (keyword "query" *> pQueryExpr)
->            ,Return p <$> tryOptionMaybe expr]
->
-> raise :: SParser Statement
-> raise = pos >>= \p -> keyword "raise" >>
->         Raise p
->         <$> raiseType
->         <*> (extrStr <$> stringLit)
->         <*> option [] (symbol "," *> commaSep1 expr)
->         where
->           raiseType = matchAKeyword [("notice", RNotice)
->                                      ,("exception", RException)
->                                      ,("error", RError)]
->
-> forStatement :: Annotation -> Maybe String -> SParser Statement
-> forStatement p l = do
->                keyword "for"
->                start <- nameComponent
->                keyword "in"
->                choice [ForQueryStatement p l start
->                        <$> try pQueryExpr <*> theRest
->                       ,ForIntegerStatement p l start
->                               <$> expr
->                               <*> (symbol ".." *> expr)
->                               <*> theRest]
->   where
->     theRest = keyword "loop" *> many plPgsqlStatement
->               <* keyword "end" <* keyword "loop"
->
-> whileStatement :: Annotation -> Maybe String -> SParser Statement
-> whileStatement p l = WhileStatement p l
->                      <$> (keyword "while" *> expr <* keyword "loop")
->                      <*> many plPgsqlStatement <* keyword "end" <* keyword "loop"
-> loopStatement :: Annotation -> Maybe String -> SParser Statement
-> loopStatement p l = LoopStatement p l
->                     <$> (keyword "loop" *> many plPgsqlStatement <* keyword "end" <* keyword "loop")
->
-
->
-> ifStatement :: SParser Statement
-> ifStatement = If
->               <$> (pos <* keyword "if")
->               <*> (ifPart <:> elseifParts)
->               <*> (elsePart <* endIf)
->   where
->     ifPart = expr <.> (thn *> many plPgsqlStatement)
->     elseifParts = many ((elseif *> expr) <.> (thn *> many plPgsqlStatement))
->     elsePart = option [] (keyword "else" *> many plPgsqlStatement)
->     endIf = keyword "end" <* keyword "if"
->     thn = keyword "then"
->     elseif = keyword "elseif" <|> keyword "elsif"
->     --might as well throw this in as well after all that
->     -- can't do <,> unfortunately, so use <.> instead
->     (<.>) a b = (,) <$> a <*> b
->
-> caseStatement :: SParser Statement
-> caseStatement = do
->     p <- pos
->     keyword "case"
->     choice [try (CaseStatementSimple p
->                  <$> expr
->                  <*> many whenSt
->                  <*> option [] (keyword "else" *> many plPgsqlStatement)
->                         <* keyword "end" <* keyword "case")
->            ,CaseStatement p
->                  <$> many whenSt
->                  <*> option [] (keyword "else" *> many plPgsqlStatement)
->                         <* keyword "end" <* keyword "case"]
->     where
->       whenSt = keyword "when" >>
->                (,) <$> commaSep1 expr
->                    <*> (keyword "then" *> many plPgsqlStatement)
-
---------------------------------------------------------------------------------
-
-expressions
-===========
-
-This is the bit that makes it the most obvious that I don't really
-know haskell, parsing theory or parsec ... robbed a parsing example
-from haskell-cafe and mainly just kept changing it until it seemed to
-work
-
-> expr :: SParser ScalarExpr
-> expr = buildExpressionParser table factor
->        <?> "expression"
-
->
-> factor :: SParser ScalarExpr
-> factor =
-
-First job is to take care of forms which start like a vanilla
-expression, and then add a suffix on
-
->   fct >>= tryExprSuffix
->   where
->     tryExprSuffix e =
->       option e (choice (map (\f -> f e)
->                                  [inPredicateSuffix
->                                  ,functionCallSuffix
->                                  ,windowFnSuffix
->                                  ,castSuffix
->                                  ,betweenSuffix
->                                  ,arraySubSuffix
->                                  ,qualIdSuffix])
->                 >>= tryExprSuffix)
->     fct = choice [
-
-order these so the ones which can be valid prefixes of others appear
-further down the list (used to be a lot more important when there
-wasn't a separate lexer), probably want to refactor this to use the
-optionalsuffix parsers to improve speed.
-
-One little speed optimisation, to help with pretty printed code which
-can contain a lot of parens - check for nested ((
-This little addition speeds up ./ParseFile.lhs sqltestfiles/system.sql
-on my system from ~4 minutes to ~4 seconds (most of the 4s is probably
-compilation overhead).
-
->        --try (lookAhead (symbol "(" >> symbol "(")) >> parens expr
-
-start with the factors which start with parens - eliminate scalar
-subqueries since they're easy to distinguish from the others then do in
-predicate before row constructor, since an in predicate can start with
-a row constructor looking thing, then finally vanilla parens
-
->       --,
->        scalarSubQuery
->       ,try rowCtor
->       ,parens expr
-
-try a few random things which can't start a different expression
-
->       ,positionalArg
->       ,placeholder
->       ,stringLit
->       ,numberLit
-
-put the factors which start with keywords before the ones which start
-with a function, so you don't try an parse a keyword as a function name
-
->       ,caseScalarExpr
->       ,exists
->       ,booleanLit
->       ,nullLit
->       ,arrayLit
->       ,castKeyword
->       ,try substring -- use try cos there is also a regular function called substring
->       ,extract
-
->       ,try interval
->       ,try typedStringLit
->       ,antiScalarExpr
->       ,identifier
->       ]
-
-operator table
---------------
-
-proper hacky, but sort of does the job
-the 'missing' notes refer to pg operators which aren't yet supported,
-or supported in a different way (e.g. cast uses the type name parser
-for one of it's argument, not the expression parser - I don't know if
-there is a better way of doing this but there usually is in parsec)
-
-pg's operator table is on this page:
-http://www.postgresql.org/docs/8.4/interactive/sql-syntax-lexical.html#SQL-SYNTAX-OPERATORS
-
-will probably need something more custom to handle full range of sql
-syntactical novelty, in particular the precedence rules mix these
-operators up with irregular syntax operators, you can create new
-operators during parsing, and some operators are prefix/postfix or
-binary depending on the types of their operands (how do you parse
-something like this?)
-
-The full list of operators from a standard template1 database should
-be used here.
-
-> tableAB :: Bool -> [[Operator [Token] ParseState Identity ScalarExpr]]
-> tableAB isB = [[{-binary "." AssocLeft-}]
->          --[binary "::" (BinOpCall Cast) AssocLeft]
->          --missing [] for array element select
->         ,[prefix "-" "u-"]
->         ,[binary "^" AssocLeft]
->         ,[binary "*" AssocLeft
->          ,idHackBinary "*" AssocLeft
->          ,binary "/" AssocLeft
->          ,binary "%" AssocLeft]
->         ,[binary "+" AssocLeft
->          ,binary "-" AssocLeft]
->          --should be is isnull and notnull
->         ,[postfixks ["is", "not", "null"] "!isnotnull"
->          ,postfixks ["is", "null"] "!isnull"]
->          --other operators all added in this list according to the pg docs:
->         ,[binary "<->" AssocNone
->          ,binary "<=" AssocRight
->          ,binary ">=" AssocRight
->          ,binary "||" AssocLeft
->          ,prefix "@" "@"
->          ]
->          --in should be here, but is treated as a factor instead
->          --between
->          --overlaps
->         ,[binaryk "like" "!like" AssocNone
->          ,binaryks ["not","like"] "!notlike" AssocNone
->          ,binarycust (symbol "!=") "<>" AssocNone]
->          --(also ilike similar)
->         ,[binary "<" AssocNone
->          ,binary ">" AssocNone]
->         ,[binary "=" AssocRight
->          ,binary "<>" AssocNone]
->         ,[notNot
->          ,prefixk "not" "!not"
->          ]
->         ,let x = [binaryk "or" "!or" AssocLeft]
->          in if isB
->             then x
->             else binaryk "and" "!and" AssocLeft : x
->          ]
->     where
->       binary s = binarycust (symbol s) s
->       -- '*' is lexed as an id token rather than a symbol token, so
->       -- work around here
->       idHackBinary s = binarycust (keyword s) s
->       binaryk = binarycust . keyword
->       binaryks = binarycust . mapM_ keyword
->       prefix = unaryCust Prefix . symbol
->       prefixk = unaryCust Prefix . keyword
->       postfixks = unaryCust Postfix . mapM_ keyword
->       binarycust opParse t =
->         Infix $ try $ do
->              f <- FunCall <$> pos <*> (nm emptyAnnotation t <$ opParse)
->              return (\l m -> f [l,m])
->       unaryCust ctor opParse t =
->         ctor $ try $ do
->           f <- FunCall <$> pos <*> (nm emptyAnnotation t <$ opParse)
->           return (\l -> f [l])
->       -- hack - haven't worked out why parsec buildexpression parser won't
->       -- parse something like "not not EXPR" without parens so hack here
->       notNot =
->         Prefix (try $ do
->                       p1 <- pos
->                       keyword "not"
->                       p2 <- pos
->                       keyword "not"
->                       return (\l -> FunCall p1 (nm p1 "!not")
->                                     [FunCall p2 (nm p2 "!not") [l]]))
-
-From postgresql src/backend/parser/gram.y
-
-~~~~~
-
- * We have two expression types: a_expr is the unrestricted kind, and
- * b_expr is a subset that must be used in some places to avoid shift/reduce
- * conflicts.  For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
- * because that use of AND conflicts with AND as a boolean operator.  So,
- * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
- *
- * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
- * always be used by surrounding it with parens.
-
-~~~~~
-
-> table :: [[Operator [Token] ParseState Identity ScalarExpr]]
-> table = tableAB False
-
-> tableB :: [[Operator [Token] ParseState Identity ScalarExpr]]
-> tableB = tableAB True
-
-use the same factors
-
-> b_expr :: SParser ScalarExpr
-> b_expr = buildExpressionParser tableB factor
->        <?> "expression"
->
-
-factor parsers
---------------
-
-I think the lookahead is used in an attempt to help the error messages.
-
-> scalarSubQuery :: SParser ScalarExpr
-> scalarSubQuery = try (symbol "(" *> lookAhead (keyword "select"
->                                                <|> keyword "with")) >>
->                  ScalarSubQuery
->                  <$> pos
->                  <*> pQueryExpr <* symbol ")"
-
-in predicate - an identifier or row constructor followed by 'in'
-then a list of expressions or a subselect
-
-> inPredicateSuffix :: ScalarExpr -> SParser ScalarExpr
-> inPredicateSuffix e = try $
->   InPredicate
->   <$> pos
->   <*> return e
->   <*> option True (False <$ keyword "not")
->   <*> (keyword "in" *> parens ((InQueryExpr <$> pos <*> pQueryExpr)
->                                <|>
->                                (InList <$> pos <*> commaSep1 expr)))
-
-row ctor: one of
-
-* row ()
-* row (expr)
-* row (expr, expr1, ...)
-* (expr, expr2,...) [implicit (no row keyword) version, at least two elements
-                   must be present]
-
-* (expr) parses to just expr rather than row(expr)
-* and () is a syntax error.
-
-> rowCtor :: SParser ScalarExpr
-> rowCtor = FunCall
->           <$> pos
->           <*> (nm <$> pos <*> return "!rowctor")
->           <*> choice [
->            keyword "row" *> parens (commaSep expr)
->           ,parens $ commaSep2 expr]
->
-> numberLit :: SParser ScalarExpr
-> numberLit = NumberLit <$> pos <*> numString
->
-
-> integer :: SParser Integer
-> integer = do
->   l <- numString
->   guard (all (`elem` digChars) l)
->   return $ read l
->   where
->     digChars = concatMap show [(0::Int)..9]
-
->
-> caseScalarExpr :: SParser ScalarExpr
-> caseScalarExpr = do
->   p <- pos
->   keyword "case"
->   choice [
->              try $ CaseSimple p <$> expr
->                                 <*> many whenParse
->                                 <*> tryOptionMaybe (keyword "else" *> expr)
->                                         <* keyword "end"
->             ,Case p <$> many whenParse
->                     <*> tryOptionMaybe (keyword "else" *> expr)
->                             <* keyword "end"]
->   where
->     whenParse = (,) <$> (keyword "when" *> commaSep1 expr)
->                     <*> (keyword "then" *> expr)
->
-> exists :: SParser ScalarExpr
-> exists = Exists <$> pos <* keyword "exists" <*> parens pQueryExpr
->
-
-> booleanLit :: SParser ScalarExpr
-> booleanLit = BooleanLit <$> pos <*> (True <$ keyword "true"
->                                      <|> False <$ keyword "false")
-
->
-> nullLit :: SParser ScalarExpr
-> nullLit = NullLit <$> pos <* keyword "null"
->
-> arrayLit :: SParser ScalarExpr
-> arrayLit = FunCall <$> pos <* keyword "array"
->                    <*> (nm <$> pos <*> return "!arrayctor")
->                    <*> squares (commaSep expr)
->
-> arraySubSuffix :: ScalarExpr -> SParser ScalarExpr
-> arraySubSuffix e = case e of
->                      Identifier _ (Nmc "array") -> fail "can't use array \
->                                                         \as identifier name"
->                      _ -> FunCall <$> pos
->                                   <*> (nm <$> pos <*> return "!arraysub")
->                                   <*> ((e:) <$> squares (commaSep1 expr))
->
-> windowFnSuffix :: ScalarExpr -> SParser ScalarExpr
-> windowFnSuffix e = WindowFn <$> pos <*> return e
->                    <*> (keyword "over"
->                         *> (symbol "(" *> option [] partitionBy))
->                    <*> orderBy
->                    <*> frm
->                    <* symbol ")"
->   where
->     partitionBy = keyword "partition" *> keyword "by" *> commaSep1 expr
->     frm = option FrameUnboundedPreceding $ choice
->                                          $ map (\(a,b) -> a <$ try (ks b)) [
->            (FrameUnboundedPreceding, ["range","unbounded","preceding"])
->           ,(FrameUnboundedPreceding, ["range"
->                                      ,"between"
->                                      ,"unbounded"
->                                      ,"preceding"
->                                      ,"and"
->                                      ,"current"
->                                      ,"row"])
->           ,(FrameUnboundedFull, ["range"
->                                 ,"between"
->                                 ,"unbounded"
->                                 ,"preceding"
->                                 ,"and"
->                                 ,"unbounded"
->                                 ,"following"])
->           ,(FrameUnboundedFull, ["rows"
->                                 ,"between"
->                                 ,"unbounded"
->                                 ,"preceding"
->                                 ,"and"
->                                 ,"unbounded"
->                                 ,"following"])
->           ,(FrameRowsUnboundedPreceding, ["rows","unbounded","preceding"])
->           ,(FrameRowsUnboundedPreceding, ["rows"
->                                          ,"between"
->                                          ,"unbounded"
->                                          ,"preceding"
->                                          ,"and"
->                                          ,"current"
->                                          ,"row"])]
->     ks = mapM keyword
->
-> betweenSuffix :: ScalarExpr -> SParser ScalarExpr
-> betweenSuffix a = do
->   p <- pos
->   keyword "between"
->   b <- b_expr
->   keyword "and"
->   c <- b_expr
->   return $ FunCall p (nm p "!between") [a,b,c]
-
-handles aggregate business as well
-
-can use a * in aggregate calls and in window functions.  This
-represents a call to an aggregate which has no parameters, so count(*)
-actually means count():
-
-select count() from pg_attrdef;
-ERROR:  count(*) must be used to call a parameterless aggregate function
-LINE 1: select count() from pg_attrdef;
-
-But you can't write it as count() ... ?
-
-You cannot use * together with either distinct or order by, and it
-cannot be qualified.
-
-This parser is used as the prefix of the window function parser so
-both are handled here. This will parse non aggregate calls containing
-a single * argument without error - this will have to be caught during
-typechecking. It also parses the aggregate extras (distinct and order
-by) for non aggregate calls without error, so this also will need to
-be caught during typechecking. The typechecker doesn't really do much
-checking with aggregates at the moment so should fix it all together.
-
-> functionCallSuffix :: ScalarExpr -> SParser ScalarExpr
-> functionCallSuffix (Identifier _ (Nmc fnName)) = do
->   p <- pos
->   (di,as,ob) <- parens
->                 $ choice [ -- handle a single *
->                           (Nothing,,[]) <$> ((:[]) <$> (Star <$> pos <* symbol "*"))
->                          ,(,,)
->                           <$> optionMaybe
->                                (choice [Distinct <$ keyword "distinct"
->                                        ,Dupes <$ keyword "all"])
->                           <*> commaSep expr
->                           <*> orderBy]
->   return $ case (di,ob) of
->     (Nothing,[]) -> FunCall p (nm p fnName) as
->     (d,o) -> AggregateFn p (fromMaybe Dupes d) (FunCall p (nm p fnName) as) o
-> --hack for antiquoted function name
-> functionCallSuffix (AntiScalarExpr n) =
->   functionCallSuffix (Identifier emptyAnnotation (Nmc $ "$(" ++ n ++ ")"))
-> functionCallSuffix s =
->   fail $ "cannot make functioncall from " ++ show s
->
-> castKeyword :: SParser ScalarExpr
-> castKeyword = Cast
->               <$> pos <* keyword "cast" <* symbol "("
->               <*> expr
->               <*> (keyword "as" *> typeName <* symbol ")")
->
-> castSuffix :: ScalarExpr -> SParser ScalarExpr
-> castSuffix ex = pos >>= \p -> Cast p ex <$> (symbol "::" *> typeName)
-
-> typedStringLit :: SParser ScalarExpr
-> typedStringLit = TypedStringLit
->                  <$> pos
->                  <*> typeName
->                  <*> (extrStr <$> stringLit)
-
-> extract :: SParser ScalarExpr
-> extract = try $ do
->   p <- pos
->   _ <- keyword "extract"
->   _ <- symbol "("
->   f <- extractField
->   _ <- keyword "from"
->   e <- expr
->   _ <- symbol ")"
->   return $ Extract p f e
->   where
->     extractField =
->       choice [ExtractCentury <$ keyword "century"
->              ,ExtractDay <$ keyword "day"
->              ,ExtractDecade <$ keyword "decade"
->              ,ExtractDow <$ keyword "dow"
->              ,ExtractDoy <$ keyword "doy"
->              ,ExtractEpoch <$ keyword "epoch"
->              ,ExtractHour <$ keyword "hour"
->              ,ExtractIsodow <$ keyword "isodow"
->              ,ExtractIsoyear <$ keyword "isoyear"
->              ,ExtractMicroseconds <$ keyword "microseconds"
->              ,ExtractMillennium <$ keyword "millennium"
->              ,ExtractMilliseconds <$ keyword "milliseconds"
->              ,ExtractMinute <$ keyword "minute"
->              ,ExtractMonth <$ keyword "month"
->              ,ExtractQuarter <$ keyword "quarter"
->              ,ExtractSecond <$ keyword "second"
->              ,ExtractTimezone <$ keyword "timezone"
->              ,ExtractTimezoneHour <$ keyword "timezone_hour"
->              ,ExtractTimezoneMinute <$ keyword "timezone_minute"
->              ,ExtractWeek <$ keyword "week"
->              ,ExtractYear <$ keyword "year"]
-
-> interval :: SParser ScalarExpr
-> interval = Interval
->            <$> pos
->            <*> (keyword "interval" *> (extrStr <$> stringLit))
->            <*> intervalField
->            <*> tryOptionMaybe (parens (fromInteger <$> integer))
->   where
->     intervalField =
->         choice [IntervalYear <$ keyword "year"
->                ,IntervalMonth <$ keyword "month"
->                ,IntervalDay <$ keyword "day"
->                ,IntervalHour <$ keyword "hour"
->                ,IntervalMinute <$ keyword "minut"
->                ,IntervalSecond <$ keyword "second"
->                {-,IntervalYearToMonth <$ keyword "day"
->                ,IntervalDayToHour <$ keyword "day"
->                ,IntervalDayToMinute <$ keyword "day"
->                ,IntervalDayToSecond <$ keyword "day"
->                ,IntervalHourToMinute <$ keyword "day"
->                ,IntervalHourToSecond <$ keyword "day"
->                ,IntervalMinuteToSecond <$ keyword "day"-}]
->
-> substring :: SParser ScalarExpr
-> substring = do
->             p <- pos
->             keyword "substring"
->             symbol "("
->             a <- expr
->             keyword "from"
->             b <- expr
->             keyword "for"
->             c <- expr
->             symbol ")"
->             return $ FunCall p (nm p "!substring") [a,b,c]
->
-
-------------------------------------------------------------
-
-identifier wasteland
-
-> qualIdSuffix :: ScalarExpr -> SParser ScalarExpr
-> qualIdSuffix (Identifier p i) = do
->     i1 <- symbol "." *> nameComponent
->     return $ QIdentifier p [i,i1]
-> qualIdSuffix e = do
->     p <- pos
->     i1 <- symbol "." *> nameComponent
->     return $ FunCall p (nm p ".") [e,Identifier p i1]
-
-
-> identifier :: SParser ScalarExpr
-> identifier = Identifier <$> pos <*> nameComponent
->
-
-bit hacky, avoid a bunch of keywords. Not exactly sure which keywords
-should be in the blacklist, and where this parser should be used
-instead of the full parser which allows keywords. Also not sure if
-keywords used in qualified names should be rejected the same as
-keywords which are unqualified.
-
-> nonKeywordNc :: SParser NameComponent
-> nonKeywordNc = do
->   x <- nameComponent
->   if x `elem` badKeywords
->     then fail "not keyword (NameComponent)"
->     else return x
->   where
->     badKeywords = map Nmc
->                   ["as"
->                   ,"where"
->                   ,"except"
->                   ,"union"
->                   ,"intersect"
->                   ,"loop"
->                   ,"inner"
->                   ,"on"
->                   ,"left"
->                   ,"right"
->                   ,"full"
->                   ,"cross"
->                   ,"join"
->                   ,"natural"
->                   ,"order"
->                   ,"group"
->                   ,"limit"
->                   ,"using"
->                   ,"from"]
-
-
-> nonKeywordNcs :: SParser [NameComponent]
-> nonKeywordNcs = sepBy1 nonKeywordNc (symbol ".")
-
-> ncs :: SParser [NameComponent]
-> ncs = sepBy1 nameComponent (symbol ".")
-
-> name :: SParser Name
-> name = Name <$> pos <*> ncs
-
-> nonKeywordName :: SParser Name
-> nonKeywordName = Name <$> pos <*> nonKeywordNcs
-
-> nameComponent :: SParser NameComponent
-> nameComponent = choice [Nmc <$> idString
->                        ,QNmc <$> qidString
->                        ,Nmc <$> spliceD
->                        ,Nmc <$> ssplice]
->                 where
->                   ssplice = (\s -> "$i(" ++ s ++ ")") <$>
->                               (symbol "$i(" *> idString <* symbol ")")
-
-
---------------------------------------------------------------------------------
-
-Utility parsers
-===============
-
-tokeny things
--------------
-
-keyword has to not be immediately followed by letters or numbers
-(symbols and whitespace are ok) so you know that we aren't reading an
-identifier which happens to start with a complete keyword
-
-> keyword :: String -> SParser ()
-> keyword k = mytoken (\tok ->
->                                case tok of
->                                IdStringTok i | lcase k == lcase i -> Just ()
->                                _ -> Nothing)
->                       where
->                         lcase = map toLower
->
-> idString :: SParser String
-> idString =
->     choice [(\l -> "$(" ++ l ++ ")")
->             <$> (symbol "$(" *> idString <* symbol ")")
->            ,ids
->            ]
->   where
->     ids = mytoken (\tok -> case tok of
->                                      IdStringTok "not" -> Nothing
->                                      IdStringTok i -> Just i
->                                      -- have to go through and fix every
->                                      -- use of idString to make this work correctly
->                                      -- idstring is used LOADS
->                                      -- lots of places in the ast probably need fixing
->                                      _ -> Nothing)
-> qidString :: SParser String
-> qidString =
->     choice [(\l -> "$(" ++ l ++ ")")
->             <$> (symbol "$(" *> idString <* symbol ")")
->            ,ids
->            ]
->   where
->     ids = mytoken (\tok -> case tok of
->                                      QIdStringTok i -> Just i
->                                      _ -> Nothing)
-
-
->
-> spliceD :: SParser String
-> spliceD = (\x -> "$(" ++ x ++ ")") <$> splice
->
-> splice :: SParser String
-> splice = symbol "$(" *> idString <* symbol ")"
->
-> symbol :: String -> SParser ()
-> symbol c = mytoken (\tok -> case tok of
->                                    SymbolTok s | c==s -> Just ()
->                                    _           -> Nothing)
->
-> liftPositionalArgTok :: SParser Integer
-> liftPositionalArgTok =
->   mytoken (\tok -> case tok of
->                    PositionalArgTok n -> Just n
->                    _ -> Nothing)
-
-> positionalArg :: SParser ScalarExpr
-> positionalArg = PositionalArg <$> pos <*> liftPositionalArgTok
->
-> antiScalarExpr :: SParser ScalarExpr
-> antiScalarExpr = AntiScalarExpr <$> splice
->
-> placeholder :: SParser ScalarExpr
-> placeholder = (Placeholder <$> pos) <* symbol "?"
->
-> numString :: SParser String
-> numString = mytoken (\tok -> case tok of
->                                     NumberTok n -> Just n
->                                     _ -> Nothing)
-
->
-> liftStringTok :: SParser String
-> liftStringTok = mytoken (\tok ->
->                   case tok of
->                            StringTok _ s -> Just s
->                            _ -> Nothing)
-
-> stringLit :: SParser ScalarExpr
-> stringLit = (StringLit <$> pos <*> liftStringTok)
->             <|>
->             (StringLit <$> pos <*> ssplice)
->              where
->                ssplice = (\s -> "$s(" ++ s ++ ")") <$>
->                            (symbol "$s(" *> idString <* symbol ")")
->
-> stringN :: SParser String
-> stringN = mytoken (\tok ->
->                   case tok of
->                            StringTok _ s -> Just s
->                            _ -> Nothing)
-
-> extrStr :: ScalarExpr -> String
-> extrStr (StringLit _ s) = s
-> extrStr x =
->   error $ "internal error: extrStr not supported for this type " ++ show x
-
-== combinatory things
-
-> parens :: SParser a
->        -> SParser a
-> parens = between (symbol "(") (symbol ")")
->
-> squares :: SParser a
->        -> SParser a
-> squares = between (symbol "[") (symbol "]")
->
-> tryOptionMaybe :: (Stream s m t) =>
->              ParsecT s u m a -> ParsecT s u m (Maybe a)
-> tryOptionMaybe p = try (optionMaybe p) <|> return Nothing
->
-> commaSep2 :: SParser a
->           -> SParser [a]
-> commaSep2 p = sepBy2 p (symbol ",")
->
-> sepBy2 :: (Stream s m t) =>
->           ParsecT s u m a -> ParsecT s u m b -> ParsecT s u m [a]
-> sepBy2 p sep = (p <* sep) <:> sepBy1 p sep
->
-> commaSep :: SParser a
->          -> SParser [a]
-> commaSep p = sepBy p (symbol ",")
->
-> commaSep1 :: SParser a
->           -> SParser [a]
-> commaSep1 p = sepBy1 p (symbol ",")
-
-pass a list of pairs of strings and values
-try each pair k,v in turn,
-if keyword k matches then return v
-doesn't really add a lot of value
-
-> matchAKeyword :: [(String, a)] -> SParser a
-> matchAKeyword [] = fail "no matches"
-> matchAKeyword ((k,v):kvs) = v <$ keyword k <|> matchAKeyword kvs
-
-optionalSuffix
-
-parse the start of something -> parseResultA,
-then parse an optional suffix -> parseResultB
-if this second parser succeeds, return fn2 parseResultA parseResultB
-else return fn1 parseResultA
-
-e.g.
-parsing an identifier in a select list can be
-fieldName
-or
-fieldName as alias
-so you can pass
-* IdentifierCtor
-* identifier (returns aval)
-* AliasedIdentifierCtor
-* () - looks like a place holder, probably a crap idea
-* parser for (as b) (returns bval)
-as the args, which I like to ident like:
-parseOptionalSuffix
-  IdentifierCtor identifierParser
-  AliasedIdentifierCtor () asAliasParser
-and you get either
-* IdentifierCtor identifierValue
-or
-* AliasedIdentifierCtor identifierValue aliasValue
-as the result depending on whether the asAliasParser
-succeeds or not.
-
-probably this concept already exists under a better name in parsing
-theory
-
-> optionalSuffix :: (Stream s m t2) =>
->                   (t1 -> b)
->                -> ParsecT s u m t1
->                -> (t1 -> a -> b)
->                -> ()
->                -> ParsecT s u m a
->                -> ParsecT s u m b
-> optionalSuffix c1 p1 c2 _ p2 = do
->   x <- p1
->   option (c1 x) (c2 x <$> try p2)
-
-
-couldn't work how to to perms so just did this hack instead
-e.g.
-a1,a2,b1,b2,a2,b3,b4 parses to ([a1,a2,a3],[b1,b2,b3,b4])
-
-> multiPerm :: (Stream s m t) =>
->                ParsecT s u m a1
->             -> ParsecT s u m a
->             -> ParsecT s u m sep
->             -> ParsecT s u m ([a1], [a])
->
-> multiPerm p1 p2 sep = do
->   (r1, r2) <- unzip <$> sepBy1 parseAorB sep
->   return (catMaybes r1, catMaybes r2)
->   where
->     parseAorB = choice [
->                   (\x -> (Just x,Nothing)) <$> p1
->                  ,(\y -> (Nothing, Just y)) <$> p2]
-
-== position stuff
-
-simple wrapper for parsec source positions, probably not really useful
-
-> type MySourcePos = (String,Int,Int)
->
-> toMySp :: SourcePos -> MySourcePos
-> toMySp sp = (sourceName sp,sourceLine sp,sourceColumn sp)
-
-parser combinator to return the current position as an ast annotation
-
-> pos :: SParser Annotation
-> pos =
->   (\a -> emptyAnnotation {asrc=Just a}) <$> toMySp <$> getPosition
-
-== lexer stuff
-
-> mytoken :: (Tok -> Maybe a) -> SParser a
-> mytoken test
->   = token showToken posToken testToken
->   where
->   showToken (_,tok)   = show tok
->   posToken  (posi,_)  = posi
->   testToken (_,tok)   = test tok
-
---------------------------------------------------------------------------------
-
-= fixup tree
-
-this is where some generics code is used to transform the parse trees
-to alter the nodes used where it's too difficult to do whilst
-parsing. The only item at the moment that needs this treatment is the
-any/some/all construct which looks like this:
-expr operator [any|some|all] (expr)
-
-This gets parsed as
-funcall operator [expr1,funcall [any|some|all] [expr2,...]]
-and you want to transform it to
-liftoperator operator any|some|all [expr1, expr2,...]
-not doing anything if the funcall name isn't any,some,all
-any other checks are left to the type checking stage
-(e.g. there can only be one expression in the expr2 part, and it must
-be an array or subselect, etc)
-
-> fixupTree :: Data a => a -> a
-> fixupTree =
->     transformBi $ \x ->
->       case x of
->              FunCall an op (expr1:FunCall _ fn expr2s:expr3s)
->                | Name _ [Nmc opnm] <- op
->                , isOperatorName opnm
->                , Name _ [Nmc fnm] <- fn
->                , Just flav <- case map toLower fnm of
->                                  "any" -> Just LiftAny
->                                  "some" -> Just LiftAny
->                                  "all" -> Just LiftAll
->                                  _ -> Nothing
->                -> LiftOperator an opnm flav (expr1:expr2s ++ expr3s)
->              x1 -> x1
-
---------------------------------------------------------------------------------
-
-Parse state not currently used. Use these placeholders to add some.
-
-> type ParseState = ()
->
-> startState :: ()
-> startState = ()
diff --git a/src/Database/HsSqlPpp/Pretty.lhs b/src/Database/HsSqlPpp/Pretty.lhs
--- a/src/Database/HsSqlPpp/Pretty.lhs
+++ b/src/Database/HsSqlPpp/Pretty.lhs
@@ -1,936 +1,21 @@
-
-
-> {- | Functions to convert sql asts to valid SQL source code. Includes
->    a function - 'printSqlAnn' - to output the annotations from a tree
->    in comments in the outputted SQL source.
->
->    Produces sort of readable code, but mainly just written to produce
->    reparsable text. Could do with some work to make the outputted text
->    layout better.
-> -}
-> {-# LANGUAGE PatternGuards #-}
-> module Database.HsSqlPpp.Pretty (
->                       --convert a sql ast to text
->                       printStatements
->                      ,printStatementsAnn
->                      ,printQueryExpr
->                       --convert a single expression parse node to text
->                      ,printScalarExpr
->                      ,printQueryExprNice
->                      )
+> module Database.HsSqlPpp.Pretty
+>     (--convert a sql ast to text
+>      prettyStatements
+>     --,printStatementsAnn
+>     ,prettyQueryExpr
+>      --convert a single expression parse node to text
+>     ,prettyScalarExpr
+>     ,PrettyFlags(..)
+>     ,defaultPrettyFlags
+>     ,Dialect(..)
+>     ,ansiDialect
+>     )
 >     where
->
-> import Text.PrettyPrint
-> --import Data.Char
-> --import Data.List
-> import Data.Maybe
->
-> import Database.HsSqlPpp.Ast -- hiding (ncStr)
-> import Database.HsSqlPpp.Annotation
-> import Database.HsSqlPpp.Catalog
-> import Database.HsSqlPpp.Utils.Utils
 
---------------------------------------------------------------------------------
-
-Public functions
-
-> -- | convert an ast back to valid SQL source, it's also almost human readable.
-> printStatements :: StatementList -> String
-> printStatements = printStatementsAnn (const "")
->
-> -- | convert the ast back to valid source, and convert any annotations to
-> -- text using the function provided and interpolate the output of
-> -- this function(inside comments) with the SQL source.
-> printStatementsAnn :: (Annotation -> String) -> StatementList -> String
-> printStatementsAnn f ast = render $ vcat (map (statement False True f) ast) <> text "\n"
->
-
-> printQueryExpr :: QueryExpr -> String
-> printQueryExpr ast = render (queryExpr False True True Nothing ast <> statementEnd True)
-
-> -- | Testing function, pretty print an expression
-> printScalarExpr :: ScalarExpr -> String
-> printScalarExpr = render . scalExpr False
-
-
-> -- | Try harder to make the output human readable, not necessary correct
-> -- sql output at the moment
-> printQueryExprNice :: QueryExpr -> String
-> printQueryExprNice ast = render (queryExpr True True True Nothing ast <> statementEnd True)
-
-
--------------------------------------------------------------------------------
-
-Conversion routines - convert Sql asts into Docs
-
-> -- Statements
->
-> statement :: Bool -> Bool -> (Annotation -> String) -> Statement -> Doc
-> statement _nice _se _ca (AntiStatement s) = text $ "$(" ++ s ++ ")"
->
-> -- selects
->
-> statement nice se ca (QueryStatement ann s) =
->   annot ca ann <+>
->   queryExpr nice True True Nothing s <> statementEnd se
->
-> --dml
->
-> statement nice se pa (Insert ann tb atts idata rt) =
->   annot pa ann <+>
->   text "insert into" <+> name tb
->   <+> ifNotEmpty (parens . sepCsvMap nmc) atts
->   $+$ queryExpr nice True True Nothing idata
->   $+$ returning nice rt
->   <> statementEnd se
->
-> statement nice se ca (Update ann tb scs fr wh rt) =
->    annot ca ann <+>
->    text "update" <+> name tb <+> text "set"
->    <+> sepCsvMap (set nice) scs
->    <+> ifNotEmpty (\_ -> text "from" <+> sepCsvMap (tref nice) fr) fr
->    <+> whr nice wh
->    $+$ returning nice rt <> statementEnd se
->
-> statement nice se ca (Delete ann tbl us wh rt) =
->    annot ca ann <+>
->    text "delete from" <+> name tbl
->    <+> ifNotEmpty (\_ -> text "using" <+> sepCsvMap (tref nice) us) us
->    <+> whr nice wh
->    $+$ returning nice rt
->    <> statementEnd se
->
-> statement _nice se ca (Truncate ann names ri casc) =
->     annot ca ann <+>
->     text "truncate"
->     <+> sepCsvMap name names
->     <+> text (case ri of
->                       RestartIdentity -> "restart identity"
->                       ContinueIdentity -> "continue identity")
->     <+> cascade casc
->     <> statementEnd se
->
-> -- ddl
->
-> statement nice se ca (CreateTable ann tbl atts cns) =
->     annot ca ann <+>
->     text "create table"
->     <+> name tbl <+> lparen
->     $+$ nest 2 (vcat (csv (map attrDef atts ++ map (constraint nice) cns)))
->     $+$ rparen <> statementEnd se
->     where
->       attrDef (AttributeDef _ n t def cons) =
->         nmc n <+> typeName t
->         <+> maybePrint (\e -> text "default" <+> scalExpr nice e) def
->         <+> hsep (map cCons cons)
->       cCons (NullConstraint _ cn) =
->         mname cn <+> text "null"
->       cCons (NotNullConstraint _ cn) =
->         mname cn <+> text "not null"
->       cCons (RowCheckConstraint _ cn ew) =
->         mname cn <+> text "check" <+> parens (scalExpr nice ew)
->       cCons (RowUniqueConstraint _ cn) =
->         mname cn <+> text "unique"
->       cCons (RowPrimaryKeyConstraint _ cn) =
->         mname cn <+> text "primary key"
->       cCons (RowReferenceConstraint _ cn tb att ondel onupd) =
->         mname cn <+> text "references" <+> name tb
->         <+> maybePrint (parens . nmc) att
->         <+> text "on delete" <+> cascade ondel
->         <+> text "on update" <+> cascade onupd
->
-> statement nice se ca (AlterTable ann nm act) =
->     annot ca ann <+>
->     text "alter table" <+> name nm
->     <+> hcatCsvMap alterAction act <> statementEnd se
->     where
->       alterAction (AlterColumnDefault _ cnm def) =
->           text "alter column" <+> nmc cnm
->           <+> text "set default" <+> scalExpr nice def
->       alterAction (AddConstraint _ con) =
->           text "add " <+> constraint nice con
->
-> statement _nice se ca (CreateSequence ann nm incr _ _ start cache) =
->     annot ca ann <+>
->     text "create sequence" <+> name nm <+>
->     text "increment" <+> text (show incr) <+>
->     text "no minvalue" <+>
->     text "no maxvalue" <+>
->     text "start" <+> text (show start) <+>
->     text "cache" <+> text (show cache) <> statementEnd se
->
-> statement _nice se ca (AlterSequence ann nm o) =
->     annot ca ann <+>
->     text "alter sequence" <+> name nm
->     <+> text "owned by" <+> name o <> statementEnd se
->
-> statement nice se ca (CreateTableAs ann t sel) =
->     annot ca ann <+>
->     text "create table"
->     <+> name t <+> text "as"
->     $+$ queryExpr nice True True Nothing sel
->     <> statementEnd se
->
-> statement nice se ca (CreateFunction ann nm args retType rep lang body vol) =
->     annot ca ann <+>
->     text ("create " ++ (case rep of
->                          Replace -> "or replace "
->                          _ -> "") ++ "function")
->     <+> name nm
->     <+> parens (sepCsvMap paramDefn args)
->     <+> text "returns" <+> typeName retType <+> text "as" <+> text "$$"
->     $+$ functionBody body
->     $+$ text "$$" <+> text "language"
->     <+> text (case lang of
->                         Sql -> "sql"
->                         Plpgsql -> "plpgsql")
->     <+> text (case vol of
->                        Volatile -> "volatile"
->                        Stable -> "stable"
->                        Immutable -> "immutable")
->     <> statementEnd se
->     where
->       functionBody (SqlFnBody ann1 sts) =
->         annot ca ann1 <+>
->         nestedStatements nice ca sts
->       functionBody (PlpgsqlFnBody ann1 blk) =
->           annot ca ann1 <+>
->           statement nice True ca blk
->       paramDefn (ParamDef _ n t) = nmc n <+> typeName t
->       paramDefn  (ParamDefTp _ t) = typeName t
->
-> statement nice se ca (Block ann lb decls sts) =
->   annot ca ann <+>
->   label lb <>
->   ifNotEmpty (\l -> text "declare"
->                   $+$ nest 2 (vcat $ map varDefn l)) decls
->   $+$ text "begin"
->   $+$ nestedStatements nice ca sts
->   $+$ text "end" <> statementEnd se
->   where
->       varDefn (VarDef _ n t v) =
->         nmc n <+> typeName t
->         <+> maybePrint (\x -> text ":=" <+> scalExpr nice x) v <> semi
->       varDefn (VarAlias _ n n1) =
->         nmc n <+> text "alias for" <+> name n1 <> semi
->       varDefn (ParamAlias _ n p) =
->         nmc n <+> text "alias for $" <> text (show p) <> semi
->
->
-> statement nice se ca (CreateView ann nm cols sel) =
->     annot ca ann <+>
->     text "create view" <+> name nm
->     <> case cols of
->          Nothing -> empty
->          Just cs -> parens (sepCsvMap nmc cs)
->     <+> text "as"
->     $+$ nest 2 (queryExpr nice True True Nothing sel) <> statementEnd se
->
-> statement nice se ca (CreateDomain ann nm tp n ex) =
->     annot ca ann <+>
->     text "create domain" <+> name nm <+> text "as"
->     <+> typeName tp <+> cname <+> checkExp ex <> statementEnd se
->     where
->       checkExp = maybePrint (\e -> text "check" <+> parens (scalExpr nice e))
->       cname = if n == ""
->                then empty
->                else text "constraint" <+> text n
->
-> statement _nice se ca (DropFunction ann ifE fns casc) =
->   annot ca ann <+>
->   text "drop function"
->   <+> ifExists ifE
->   <+> sepCsvMap doFunction fns
->   <+> cascade casc
->   <> statementEnd se
->   where
->     doFunction (nm,types) =
->       name nm <> parens (sepCsvMap typeName types)
->
-> statement _nice se ca (DropSomething ann dropType ifE names casc) =
->     annot ca ann <+>
->     text "drop"
->     <+> text (case dropType of
->                 Table -> "table"
->                 View -> "view"
->                 Domain -> "domain"
->                 Type -> "type")
->     <+> ifExists ifE
->     <+> sepCsvMap name names
->     <+> cascade casc
->     <> statementEnd se
->
-> statement _nice se ca (CreateType ann nm atts) =
->     annot ca ann <+>
->     text "create type" <+> name nm <+> text "as" <+> lparen
->     $+$ nest 2 (vcat (csv
->           (map (\(TypeAttDef _ n t) -> nmc n <+> typeName t)  atts)))
->     $+$ rparen <> statementEnd se
->
-> statement _nice se ca (CreateLanguage ann nm) =
->     annot ca ann <+>
->     text "create language" <+> text nm <> statementEnd se
->
-> statement nice se ca (CreateTrigger ann nm wh events tbl firing fnName fnArgs) =
->     annot ca ann <+>
->     text "create trigger" <+> nmc nm
->     <+> text (case wh of
->                       TriggerBefore -> "before"
->                       TriggerAfter -> "after")
->     <+> evs
->     <+> text "on" <+> name tbl
->     <+> text "for" <+> text (case firing of
->                                         EachRow -> "row"
->                                         EachStatement -> "statement")
->     <+> text "execute procedure" <+> name fnName
->     <> parens (sepCsvMap (scalExpr nice) fnArgs) <> statementEnd se
->     where
->       evs = sep $ punctuate (text " or ") $ map
->             (text . (\e -> case e of
->                                 TInsert -> "insert"
->                                 TUpdate -> "update"
->                                 TDelete -> "delete"
->                                 AntiTriggerEvent s -> "$(" ++ s ++ ")")) events
->
-> -- plpgsql
->
-> statement _nice se ca (NullStatement ann) =
->   annot ca ann <+> text "null" <> statementEnd se
-> statement _nice se ca (ExitStatement ann lb) =
->   annot ca ann <+> text "exit"
->     <+> maybe empty text lb <> statementEnd se
->
-
-> statement nice se ca (Into ann str is (QueryStatement _ q)) =
->   annot ca ann <+>
->   queryExpr nice True True (Just (str,is)) q <> statementEnd se
-
-
-> statement nice se ca (Into ann str into st) =
->   annot ca ann <+>
->   statement nice False ca st
->   <+> text "into"
->   <> (if str
->       then empty <+> text "strict"
->       else empty)
->   <+> sepCsvMap name into
->   <> statementEnd se
->   --fixme, should be insert,update,delete,execute
-
-> statement nice se ca (Assignment ann nm val) =
->     annot ca ann <+>
->     name nm <+> text ":=" <+> scalExpr nice val <> statementEnd se
->
-> statement nice se ca (Return ann ex) =
->     annot ca ann <+>
->     text "return" <+> maybePrint (scalExpr nice) ex <> statementEnd se
->
-> statement nice se ca (ReturnNext ann ex) =
->     annot ca ann <+>
->     text "return" <+> text "next" <+> scalExpr nice ex <> statementEnd se
->
-> statement nice se ca (ReturnQuery ann sel) =
->     annot ca ann <+>
->     text "return" <+> text "query"
->     <+> queryExpr nice True True Nothing sel <> statementEnd se
->
-> statement nice se ca (Raise ann rt st exps) =
->     annot ca ann <+>
->     text "raise"
->     <+> case rt of
->                 RNotice -> text "notice"
->                 RException -> text "exception"
->                 RError -> text "error"
->     <+> scalExpr nice (StringLit emptyAnnotation st)
->     <> ifNotEmpty (\e -> comma <+> csvExp nice e) exps
->     <> statementEnd se
->
-> statement nice se ca (ForQueryStatement ann lb i sel stmts) =
->     annot ca ann <+>
->     label lb <>
->     text "for" <+> nmc i <+> text "in"
->     <+> queryExpr nice True True Nothing sel <+> text "loop"
->     $+$ nestedStatements nice ca stmts
->     $+$ text "end loop" <> statementEnd se
->
-> statement nice se ca (ForIntegerStatement ann lb var st en stmts) =
->     annot ca ann <+>
->     label lb <>
->     text "for" <+> nmc var <+> text "in"
->     <+> scalExpr nice st <+> text ".." <+> scalExpr nice en <+> text "loop"
->     $+$ nestedStatements nice ca stmts
->     $+$ text "end loop" <> statementEnd se
->
-> statement nice se ca (WhileStatement ann lb ex stmts) =
->     annot ca ann <+>
->     label lb <>
->     text "while" <+> scalExpr nice ex <+> text "loop"
->     $+$ nestedStatements nice ca stmts
->     $+$ text "end loop" <> statementEnd se
-> statement nice se ca (LoopStatement ann lb stmts) =
->     annot ca ann <+>
->     label lb <>
->     text "loop"
->     $+$ nestedStatements nice ca stmts
->     $+$ text "end loop" <> statementEnd se
->
-> statement _nice se ca (ContinueStatement ann lb) =
->     annot ca ann <+> text "continue"
->       <+> maybe empty text lb <> statementEnd se
-> statement nice se ca (Perform ann f@(FunCall _ _ _)) =
->     annot ca ann <+>
->     text "perform" <+> scalExpr nice f <> statementEnd se
-> statement _ _ _ (Perform _ x) =
->    error $ "internal error: statement not supported for " ++ show x
->
-> statement _nice se ca (Copy ann tb cols src) =
->     annot ca ann <+>
->     text "copy" <+> name tb
->     <+> ifNotEmpty (parens . sepCsvMap nmc) cols
->     <+> text "from"
->     <+> case src of
->                  CopyFilename s -> quotes $ text s <> statementEnd se
->                  Stdin -> text "stdin" <> text ";"
->
-> statement _ _ ca (CopyData ann s) =
->     annot ca ann <+>
->     text s <> text "\\." <> newline
->
-> statement nice se ca (If ann conds els) =
->    annot ca ann <+>
->    text "if" <+> constraintd (head conds)
->    $+$ vcat (map (\c -> text "elseif" <+> constraintd c) $ tail conds)
->    $+$ ifNotEmpty (\e -> text "else" $+$ nestedStatements nice ca e) els
->    $+$ text "end if" <> statementEnd se
->     where
->       constraintd (ex, sts) = scalExpr nice ex <+> text "then"
->                            $+$ nestedStatements nice ca sts
-> statement nice se ca (Execute ann s) =
->     annot ca ann <+>
->     text "execute" <+> scalExpr nice s <> statementEnd se
->
->
-> statement nice se ca (CaseStatementSimple ann c conds els) =
->     annot ca ann <+>
->     text "case" <+> scalExpr nice c
->     $+$ nest 2 (
->                 vcat (map (uncurry whenStatement) conds)
->                 $+$ elseStatement els
->                 ) $+$ text "end case" <> statementEnd se
->     where
->       whenStatement ex sts = text "when" <+> sepCsvMap (scalExpr nice) ex
->                           <+> text "then" $+$ nestedStatements nice ca sts
->       elseStatement = ifNotEmpty (\s -> text "else"
->                                      $+$ nestedStatements nice ca s)
-> statement nice se ca (CaseStatement ann conds els) =
->     annot ca ann <+>
->     text "case"
->     $+$ nest 2 (
->                 vcat (map (uncurry whenStatement) conds)
->                 $+$ elseStatement els
->                 ) $+$ text "end case" <> statementEnd se
->     where
->       whenStatement ex sts = text "when" <+> sepCsvMap (scalExpr nice) ex
->                           <+> text "then" $+$ nestedStatements nice ca sts
->       elseStatement = ifNotEmpty (\s -> text "else"
->                                      $+$ nestedStatements nice ca s)
-
->
-> -- misc
->
-> statement _nice se _ (Set _ n vs) =
->   text "set" <+> text n <+> text "="
->   <+> sepCsvMap (text . dv) vs <> statementEnd se
->   where
->     dv (SetStr _ s) = "'" ++ s ++ "'"
->     dv (SetId _ i) = i
->     dv (SetNum _ nm) = show nm
->
-> statement _nice se _ (Notify _ n) =
->   text "notify" <+> text n  <> statementEnd se
->
-> statementEnd :: Bool -> Doc
-> statementEnd b = if b
->                  then semi <> newline
->                  else empty
-
--------------------------------------------------------------------------------
-
-Statement components
-
-> -- selects
->
-> queryExpr :: Bool -> Bool -> Bool -> Maybe (Bool,[Name]) -> QueryExpr -> Doc
-> queryExpr nice writeSelect _ intoi (Select _ dis l tb wh grp hav
->                                     order lim off) =
->   (text (if writeSelect then "select" else "")
->          <+> (case dis of
->                  Dupes -> empty
->                  Distinct -> text "distinct"))
->   $+$ nest 2 (vcat $ catMaybes
->   [fmap (\(str,is) -> text "into"
->                       <+> (if str
->                            then text "strict"
->                            else empty)
->                       <+> sepCsvMap name is) intoi
->   ,Just $ nest 2 $ selectList nice l
->   ,Just $ if null tb
->           then empty
->           else text "from" $+$ nest 2 (sepCsvMap (tref nice) tb)
->   ,Just $ whr nice wh
->   ,case grp of
->      [] -> Nothing
->      g -> Just $ text "group by" $+$ nest 2 (sepCsvMap (scalExpr nice) g)
->   ,flip fmap hav $ \h -> text "having" $+$ nest 2 (scalExpr nice h)
->   ,Just $ orderBy nice order
->   ,flip fmap lim $ \lm -> text "limit" <+> scalExpr nice lm
->   ,flip fmap off $ \offs -> text "offset" <+> scalExpr nice offs
->   ])
->
-> queryExpr nice writeSelect topLev _ (CombineQueryExpr _ tp s1 s2) =
->   let p = queryExpr nice writeSelect False Nothing  s1
->           $+$ (case tp of
->                        Except -> text "except"
->                        Union -> text "union"
->                        UnionAll -> text "union" <+> text "all"
->                        Intersect -> text "intersect")
->           $+$ queryExpr nice True False Nothing s2
->   in if topLev then p else parens p
-> queryExpr nice _ _ _ (Values _ expss) =
->   text "values" $$ nest 2 (vcat $ csv $ map (parens . csvExp nice) expss)
-> queryExpr nice _ _ _ (WithQueryExpr _ wqs ex) =
->   text "with" $$ nest 2 (vcat $ csv $ map pwq wqs)
->        $+$ queryExpr nice True False Nothing ex
->   where
->     pwq (WithQuery _ nm cs ex1) =
->       nmc nm <> case cs of
->                    Nothing -> empty
->                    Just cs' -> parens $ sepCsvMap nmc cs'
->       <+> text "as"
->       <+> parens (queryExpr nice True False Nothing ex1)
-
-> name :: Name -> Doc
-> name (Name _ ns) = nmcs ns
-
-> nmcs :: [NameComponent] -> Doc
-> nmcs ns = hcat $ punctuate (text ".") $ map nmc ns
-
-> nmc :: NameComponent -> Doc
-> nmc (Nmc ns) = text ns
-> nmc (QNmc ns) = doubleQuotes $ text ns
-
->
-> tref :: Bool -> TableRef -> Doc
-> {-tref nice (Tref _ f@(SQIdentifier _ t) (TableAlias _ ta))
->   | nice, last t == ta = name f
->   -- slightly bad hack:
-> tref nice (Tref _ f@(SQIdentifier _ t) (FullAlias _ ta _))
->   | nice, last t == ta = name f-}
-
-> tref nice (Tref _ f a) = name f <+> trefAlias nice a
-> tref nice (JoinTref _ t1 nat jt t2 ex a) =
->         parens (tref nice t1
->         $+$ (case nat of
->                       Natural -> text "natural"
->                       Unnatural -> empty)
->         <+> text (case jt of
->                           Inner -> "inner"
->                           Cross -> "cross"
->                           LeftOuter -> "left outer"
->                           RightOuter -> "right outer"
->                           FullOuter -> "full outer")
->         <+> text "join"
->         <+> tref nice t2
->         <+> maybePrint (nest 2 . joinScalarExpr) ex
->         <+> trefAlias nice a)
->         where
->           joinScalarExpr (JoinOn _ e) = text "on" <+> scalExpr nice e
->           joinScalarExpr (JoinUsing _ ids) =
->               text "using" <+> parens (sepCsvMap nmc ids)
->
-> tref nice (SubTref _ sub alias) =
->         parens (queryExpr nice True True Nothing sub)
->         <+> text "as" <+> trefAlias nice alias
-> tref nice (FunTref _ f@(FunCall _ _ _) a) = scalExpr nice f <+> trefAlias nice a
-> tref _nice (FunTref _ x _) =
->       error $ "internal error: node not supported in function tref: "
->             ++ show x
->
-> trefAlias :: Bool -> TableAlias -> Doc
-> trefAlias _ (NoAlias _) = empty
-> trefAlias _ (TableAlias _ t) = nmc t
-> -- hack this out for now. When the type checking is fixed, can try
-> -- to eliminate unneeded aliases?
-> trefAlias nice (FullAlias _ t s) =
->   nmc t <> (if nice
->              then empty
->              else parens (sepCsvMap nmc s))
-
-> direction :: Direction -> Doc
-> direction d = text $ case d of
->                           Asc -> "asc"
->                           Desc -> "desc"
->
-> whr :: Bool -> Maybe ScalarExpr -> Doc
-> whr nice (Just ex) = text "where" $+$ nest 2 (scalExpr nice ex)
-> whr _ Nothing = empty
->
-> selectList :: Bool -> SelectList -> Doc
-> selectList nice (SelectList _ ex) =
->   sepCsvMap selectItem ex
->   -- <+> ifNotEmpty (\i -> text "into" <+> hcatCsvMap scalExpr i) into
->   where
->     -- try to avoid printing alias if not necessary
->     selectItem (SelectItem _ ex1@(QIdentifier _ is) nm) | nice, last is == nm = scalExprSl nice ex1
->     selectItem (SelectItem _ ex1@(Identifier _ i) nm) | nice, i == nm = scalExprSl nice ex1
->     selectItem (SelectItem _ ex1 nm) = scalExprSl nice ex1 <+> text "as" <+> nmc nm
->     selectItem (SelExp _ e) = scalExprSl nice e
->
-> cascade :: Cascade -> Doc
-> cascade casc = text $ case casc of
->                                  Cascade -> "cascade"
->                                  Restrict -> "restrict"
-> -- ddl
->
-> constraint :: Bool -> Constraint -> Doc
-> constraint _nice (UniqueConstraint _ n c) =
->         mname n <+> text "unique"
->         <+> parens (sepCsvMap nmc c)
-> constraint _nice (PrimaryKeyConstraint _ n p) =
->         mname n <+>
->         text "primary key"
->         <+> parens (sepCsvMap nmc p)
-> constraint nice (CheckConstraint _ n c) =
->         mname n <+> text "check" <+> parens (scalExpr nice c)
-> constraint _nice (ReferenceConstraint _ n at tb rat ondel onupd) =
->         mname n <+>
->         text "foreign key" <+> parens (sepCsvMap nmc at)
->         <+> text "references" <+> name tb
->         <+> ifNotEmpty (parens . sepCsvMap nmc) rat
->         <+> text "on update" <+> cascade onupd
->         <+> text "on delete" <+> cascade ondel
->
-> mname :: String -> Doc
-> mname n = if n == ""
->           then empty
->           else text "constraint" <+> text n
->
-> returning :: Bool -> Maybe SelectList -> Doc
-> returning nice l = case l of
->                 Nothing -> empty
->                 Just ls -> nest 2 (text "returning" <+> selectList nice ls)
->
-> ifExists :: IfExists -> Doc
-> ifExists i = case i of
->                         Require -> empty
->                         IfExists -> text "if exists"
->
-> -- plpgsql
->
-> nestedStatements :: Bool -> (Annotation -> String) -> StatementList -> Doc
-> nestedStatements nice pa = nest 2 . vcat . map (statement nice True pa)
->
-> typeName :: TypeName -> Doc
-> typeName (SimpleTypeName _ s) = text s
-> typeName (PrecTypeName _ s i) = text s <> parens(integer i)
-> typeName (Prec2TypeName _ s i i1) = text s <> parens (sepCsv [integer i, integer i1])
-> typeName (ArrayTypeName _ t) = typeName t <> text "[]"
-> typeName (SetOfTypeName _ t) = text "setof" <+> typeName t
->
-> -- expressions
->
-> scalExpr :: Bool -> ScalarExpr -> Doc
-> scalExpr _ (AntiScalarExpr s) = text $ "$(" ++ s ++ ")"
-> scalExpr _ (Star _) = text "*"
-> scalExpr _ (QStar _ i) = nmc i <> text ".*"
-
-> scalExpr _ (Identifier _ i) = nmc i
->   {-if quotesNeeded
->      then text $ "\"" ++ i ++ "\""
->      else text i
->   where
->     --needs some work - quotes needed if contains invalid unquoted
->     --chars, or maybe if matches keyword or similar
->     quotesNeeded = case i of
->                      x:_ | not (isLetter x || x `elem` "_*") -> True
->                      _ | all okChar i -> False
->                        | otherwise -> True
->                    where
->                      okChar x =isAlphaNum x || x `elem` "*_."-}
-> scalExpr _nice (QIdentifier _a [i1, i]) = parens (nmc i1) <> text "." <> nmc i
-> scalExpr _nice (QIdentifier _a _) = error "only supports 2 part qualified identifers atm"
-> --scalExpr nice (QIdentifier a e i) = parens (scalExpr nice e) <> text "." <> scalExpr nice (Identifier a i)
-
-> --scalExpr (PIdentifier _ i) = parens $ scalExpr i
-> scalExpr _ (NumberLit _ n) = text n
-> scalExpr _ (StringLit _ s) = -- needs some thought about using $$?
->                           text "'" <> text replaceQuotes <> text "'"
->                           where
->                             replaceQuotes = replace "'" "''" s {-if tag == "'"
->                                               then replace "'" "''" s
->                                               else s-}
->
-> scalExpr nice (FunCall _ n es) =
->     --check for special operators
->    case getTName n of
->      Just "!and" | nice, [a,b] <- es -> doLeftAnds a b
->      Just "!arrayctor" -> text "array" <> brackets (csvExp nice es)
->      Just "!between" -> scalExpr nice (head es) <+> text "between"
->                    <+> parens (scalExpr nice (es !! 1))
->                   <+> text "and"
->                   <+> parens (scalExpr nice (es !! 2))
->      Just "!substring" -> text "substring"
->                      <> parens (scalExpr nice (head es)
->                                 <+> text "from" <+> scalExpr nice (es !! 1)
->                                 <+> text "for" <+> scalExpr nice (es !! 2))
->      Just "!arraysub" -> case es of
->                        (Identifier _ i : es1) -> nmc i
->                                                  <> brackets (csvExp nice es1)
->                        _ -> parens (scalExpr nice (head es))
->                             <> brackets (csvExp nice (tail es))
->      Just "!rowctor" -> text "row" <> parens (sepCsvMap (scalExpr nice) es)
->      Just "."   -- special case to avoid ws around '.'. Don't know if this is important
->            -- or just cosmetic
->          | [a,b] <- es -> parens (scalExpr nice a) <> text "." <> scalExpr nice b
->      Just n' | isOperatorName n' ->
->         case forceRight (getOperatorType defaultTemplate1Catalog n') of
->                           BinaryOp ->
->                               let e1d = scalExpr nice (head es)
->                                   opd = text $ filterKeyword n'
->                                   e2d = scalExpr nice (es !! 1)
->                               in parens (if n' `elem` ["!and", "!or"]
->                                          then vcat [e1d, opd <+> e2d]
->                                          else e1d <+> opd <+> e2d)
->                           PrefixOp -> parens (text (if n' == "u-"
->                                                     then "-"
->                                                     else filterKeyword n')
->                                                <+> parens (scalExpr nice (head es)))
->                           PostfixOp -> parens (scalExpr nice (head es)
->                                        <+> text (filterKeyword n'))
->      _ -> name n <> parens (csvExp nice es)
->    where
->      filterKeyword t = case t of
->                          "!and" -> "and"
->                          "!or" -> "or"
->                          "!not" -> "not"
->                          "!isnull" -> "is null"
->                          "!isnotnull" -> "is not null"
->                          "!like" -> "like"
->                          "!notlike" -> "not like"
->                          x -> x
->      -- try to write a series of ands in a vertical line with slightly less parens
->      doLeftAnds a b = let as = and' a
->                       in vcat ((scalExpr nice (head as)
->                                 : map (\x -> text "and" <+> scalExpr nice x) (tail as))
->                                ++ [text "and" <+> scalExpr nice b])
->      and' a = case a of
->                 FunCall _ f [x,y] | Just "!and" <- getTName f -> and' x ++ and' y
->                 _ -> [a]
->
-> scalExpr _ (BooleanLit _ b) = bool b
-> scalExpr nice (InPredicate _ att t lst) =
->   scalExpr nice att <+> (if not t then text "not" else empty) <+> text "in"
->   <+> parens (case lst of
->                        InList _ expr -> csvExp nice expr
->                        InQueryExpr _ sel -> queryExpr nice True True Nothing sel)
-> scalExpr nice (LiftOperator _ op flav args) =
->   scalExpr nice (head args) <+> text op
->   <+> text (case flav of
->               LiftAny -> "any"
->               LiftAll -> "all")
->   <+> parens (scalExpr nice $ head $ tail args)
-> scalExpr nice (ScalarSubQuery _ s) = parens (queryExpr nice True True Nothing s)
-> scalExpr _ (NullLit _) = text "null"
-> scalExpr nice (WindowFn _ fn part order frm) =
->   scalExpr nice fn <+> text "over"
->   <+> parens (if hp || ho
->               then (if hp
->                     then text "partition by" <+> csvExp nice part
->                     else empty)
->                     <+> orderBy nice order
->                     <+> frameStuff
->               else empty)
->   where
->     hp = not (null part)
->     ho = not (null order)
->     frameStuff = case frm of
->                 FrameUnboundedPreceding -> text "range unbounded preceding"
->                 FrameUnboundedFull -> text "range between unbounded preceding and unbounded following"
->                 FrameRowsUnboundedPreceding -> text "rows unbounded preceding"
->
-> scalExpr nice (AggregateFn _ d (FunCall _ fn es) o) =
->   name fn <> parens ((case d of
->                         Dupes -> text "all"
->                         Distinct -> text "distinct")
->                      <+> csvExp nice es
->                      <+> orderBy nice o)
-> scalExpr _ (AggregateFn _ _ _ _) = error "bad syntax for aggregate function"
-> scalExpr nice (Case _ whens els) =
->   text "case"
->   $+$ nest 2 (vcat (map whn whens)
->               $+$ maybePrint (\e -> text "else" <+> scalExpr nice e) els)
->   $+$ text "end"
->       where
->         whn (ex1, ex2) =
->             text "when" <+> sepCsvMap (scalExpr nice) ex1
->             <+> text "then" <+> scalExpr nice ex2
->
-> scalExpr nice (CaseSimple _ val whens els) =
->   text "case" <+> scalExpr nice val
->   $+$ nest 2 (vcat (map whn whens)
->               $+$ maybePrint (\e -> text "else" <+> scalExpr nice e) els)
->   $+$ text "end"
->       where
->         whn (ex1, ex2) =
->             text "when" <+> sepCsvMap (scalExpr nice) ex1
->             <+> text "then" <+> scalExpr nice ex2
->
-> scalExpr _ (PositionalArg _ a) = text "$" <> integer a
-> scalExpr _ (Placeholder _) = text "?"
-> scalExpr nice (Exists _ s) =
->   text "exists" <+> parens (queryExpr nice True True Nothing s)
-> scalExpr nice (Cast _ ex t) = text "cast" <> parens (scalExpr nice ex
->                                              <+> text "as"
->                                              <+> typeName t)
-> scalExpr nice (TypedStringLit a t s) =
->   typeName t <+> scalExpr nice (StringLit a s)
-> scalExpr nice (Interval a v f p) =
->   text "interval" <+> scalExpr nice (StringLit a v)
->   <+> intervalField <+> precision
->   where
->     intervalField =
->       text $ case f of
->                     IntervalYear -> "year"
->                     IntervalMonth -> "month"
->                     IntervalDay -> "day"
->                     IntervalHour -> "hour"
->                     IntervalMinute -> "minute"
->                     IntervalSecond -> "second"
->                     IntervalYearToMonth -> "year to month"
->                     IntervalDayToHour -> "day to hour"
->                     IntervalDayToMinute -> "day to minute"
->                     IntervalDayToSecond -> "day to second"
->                     IntervalHourToMinute -> "hour to minute"
->                     IntervalHourToSecond -> "hour to second"
->                     IntervalMinuteToSecond -> "minute to second"
->     precision = case p of
->                  Nothing -> empty
->                  Just i -> parens (int i)
-> scalExpr nice (Extract _ f e) =
->   text "extract"
->   <> parens (text field <+> text "from" <+> scalExpr nice e)
->   where
->     field =
->       case f of
->              ExtractCentury -> "century"
->              ExtractDay -> "day"
->              ExtractDecade -> "decade"
->              ExtractDow -> "dow"
->              ExtractDoy -> "doy"
->              ExtractEpoch -> "epoch"
->              ExtractHour -> "hour"
->              ExtractIsodow -> "isodow"
->              ExtractIsoyear -> "isoyear"
->              ExtractMicroseconds -> "microseconds"
->              ExtractMillennium -> "millennium"
->              ExtractMilliseconds -> "milliseconds"
->              ExtractMinute -> "minute"
->              ExtractMonth -> "month"
->              ExtractQuarter -> "quarter"
->              ExtractSecond -> "second"
->              ExtractTimezone -> "timezone"
->              ExtractTimezoneHour -> "timezone_hour"
->              ExtractTimezoneMinute -> "timezone_minute"
->              ExtractWeek -> "week"
->              ExtractYear -> "year"
-
-
-> scalExprSl :: Bool ->  ScalarExpr -> Doc
-> scalExprSl nice (FunCall _ f es) | Just "." <- getTName f
->                                 , [a@(Identifier _ _), b] <- es =
->   parens (scalExprSl nice a) <> text "." <> scalExprSl nice b
-> scalExprSl nice x = scalExpr nice x
-
->
-> set :: Bool -> SetClause -> Doc
-> set nice (SetClause _ a e) =
->    -- (FunCall _ "=" [Identifier _ a, e]) =
->   nmc a <+> text "=" <+> scalExpr nice e
-> {-set nice (FunCall _ "=" [a, b]) | (FunCall _ "!rowctor" is1) <- a
->                                      ,(FunCall _ "!rowctor" is2) <- b =
->   rsNoRow is1 <+> text "=" <+> rsNoRow is2
->   where
->     rsNoRow is = parens (sepCsvMap (scalExpr nice) is)
-> set _ a = error $ "bad expression in set in update: " ++ show a-}
-> set nice (MultiSetClause _ is (FunCall _ f es)) | Just "!rowctor" <- getTName f =
->   parens (sepCsvMap nmc is) <+> text "="
->   <+> parens (sepCsvMap (scalExpr nice) es)
-> set _ a = error $ "bad expression in set in update: " ++ show a
->
-> --utils
->
-> -- convert a list of expressions to horizontal csv
->
-> csvExp :: Bool -> [ScalarExpr] -> Doc
-> csvExp nice = hcatCsvMap (scalExpr nice)
->
-> maybePrint :: (t -> Doc) -> Maybe t -> Doc
-> maybePrint f c =
->     case c of
->       Nothing -> empty
->       Just a -> f a
->
-> csv :: [Doc] -> [Doc]
-> csv = punctuate comma
->
-> hcatCsv :: [Doc] -> Doc
-> hcatCsv = hcat . csv
-
-> sepCsv :: [Doc] -> Doc
-> sepCsv = sep . csv
->
-> ifNotEmpty :: ([a] -> Doc) -> [a] -> Doc
-> ifNotEmpty c l = if null l then empty else c l
->
-> hcatCsvMap :: (a -> Doc) -> [a] -> Doc
-> hcatCsvMap ex = hcatCsv . map ex
-
-> sepCsvMap :: (a -> Doc) -> [a] -> Doc
-> sepCsvMap ex = sepCsv . map ex
-
-> orderBy :: Bool -> [(ScalarExpr,Direction)] -> Doc
-> orderBy _ [] = empty
-> orderBy nice os =
->   text "order by"
->   $+$ nest 2 (sepCsvMap (\(oe,od) -> scalExpr nice oe
->                                      <+> direction od) os)
-
-> --vcatCsvMap :: (a -> Doc) -> [a] -> Doc
-> --vcatCsvMap ex = vcat . csv . map ex
-
->
-> bool :: Bool -> Doc
-> bool b = if b then text "true" else text "false"
->
-> newline :: Doc
-> newline = text "\n"
->
-> annot :: (Annotation -> String) -> Annotation -> Doc
-> annot ca a = let s = ca a
->               in if s == ""
->                    then empty
->                    else text "/*\n" <+> text s
->                         <+> text "*/\n"
-
-> label :: Maybe String -> Doc
-> label =
->   maybe empty (\l -> text "<<"
->                      <+> text l
->                      <+> text ">>" <> text "\n")
-
-util: to be removed when outputting names is fixed
+> import Database.HsSqlPpp.Internals.PrettyInternal
+> import Database.HsSqlPpp.Internals.Dialect
+> import Database.HsSqlPpp.Dialects.Ansi
 
-> getTName :: Name -> Maybe String
-> getTName (Name _ [n]) = Just $ ncStr n
-> getTName _ = Nothing
+> defaultPrettyFlags :: PrettyFlags
+> defaultPrettyFlags = PrettyFlags {ppDialect = ansiDialect}
 
diff --git a/src/Database/HsSqlPpp/Quote.lhs b/src/Database/HsSqlPpp/Quote.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Quote.lhs
+++ /dev/null
@@ -1,275 +0,0 @@
-
-> {- | A quasiquoter for SQL. Antiquoting is a bit inconsistent. The
-> splice variable names must be all lower case because of a limitation
-> in the parser.
->
-> Example:
->
-> >
-> > {-# LANGUAGE QuasiQuotes #-}
-> > import Database.HsSqlPpp.Ast
-> > import Database.HsSqlPpp.Quote
-> > import Database.HsSqlPpp.Annotation
-> >
-> > test :: Statement
-> > test = [$sqlStmt|
-> >
-> >   create table $(tablename) (
-> >    $(varname) $(typename)
-> >   );
-> >
-> >         |]
-> >   where
-> >     tablename = "my_table"
-> >     varname = "my_field"
-> >     typename = "text"
-> >
->
-> See <http://jakewheat.github.com/hssqlppp/QuasiQuoteTests.html>
-> for more simple examples
->      -}
-
-, and
-<http://jakewheat.github.com/hssqlppp/source/examples/Database/HsSqlPpp/Examples/Extensions/>
-for some example files which use quasiquotation to do ast
-transformations which implement syntax extensions to sql
-
->
-> {-# LANGUAGE ScopedTypeVariables #-}
->
-> module Database.HsSqlPpp.Quote
->     (sqlStmts,sqlStmt,pgsqlStmts,pgsqlStmt,sqlExpr) where
-
-> import Language.Haskell.TH.Quote
-> import Language.Haskell.TH
-> import Data.Generics
-> import Data.List
->
-> import Database.HsSqlPpp.Parsing.ParserInternal
-> import Database.HsSqlPpp.Annotation
-> import Database.HsSqlPpp.Ast hiding (Name)
-
-public api: the quasiquote functions
-
-> -- | quotes Statements
-> sqlStmts :: QuasiQuoter
-> sqlStmts = makeQQ parseStatementsWithPosition
->
-> -- | quotes a single Statement
-> sqlStmt :: QuasiQuoter
-> sqlStmt = makeQQ parseOneStatement
->
-> -- | quotes plpgsql Statements
-> pgsqlStmts :: QuasiQuoter
-> pgsqlStmts = makeQQ parsePlpgsqlWithPosition
->
-> -- | quotes a plpgsql Statement
-> pgsqlStmt :: QuasiQuoter
-> pgsqlStmt = makeQQ parseOnePlpgsql
-
-> -- | quotes a ScalarExpr
-> sqlExpr :: QuasiQuoter
-> sqlExpr = makeQQ parseScalarExprWithPosition
-
-boilerplate utils to hook everything together
-
-> type Parser e a = (String
->                    -> Int
->                    -> Int
->                    -> String
->                    -> Either e a)
->
-> makeQQ :: (Show e, Data a) =>
->           Parser e a -> QuasiQuoter
-> makeQQ p = QuasiQuoter {quoteExp = parseExprExp p
->                        ,quotePat = parseExprPat p
->                        ,quoteType = undefined
->                        ,quoteDec = undefined}
-
-> parseExprExp :: (Show e, Data a) =>
->                 Parser e a -> String -> Q Exp
-> parseExprExp p s = parseSql' p s
->                    >>=  dataToExpQ (const Nothing
->                                     `extQ` antiExpE
->                                     `extQ` antiStrE
->                                     `extQ` antiTriggerEventE
->                                     `extQ` antiStatementE)
->
-> parseExprPat :: (Show e, Data a) =>
->                 Parser e a ->  String -> Q Pat
-> parseExprPat p s = parseSql' p s
->                    >>=  dataToPatQ (const Nothing
->                                     `extQ` antiExprP
->                                     `extQ` antiStrP
->                                     `extQ` annotToWildCard
->                                     --`extQ` antiTriggerEventE
->                                     --`extQ` antiStatementE
->                                    )
->
-
-wrapper for all the different parsers which sets the source location
-and converts left to fail
-
-> parseSql' :: (Data a, Show e) => Parser e a -> String -> Q a
-> parseSql' p s = do
->     Loc fn _ _ (l,c) _ <- location
->     either (fail . show) return (p fn l c s)
-
-wrappers - the Parser module doesn't expose methods which parse
-exactly one statement
-
-> parseOnePlpgsql :: Parser String Statement
-> parseOnePlpgsql f l c s =
->     case parsePlpgsqlWithPosition f l c s of
->       Right [st] -> Right st
->       Right _ -> Left "got multiple statements"
->       Left e -> Left $ show e
->
-> parseOneStatement :: Parser String Statement
-> parseOneStatement f l c s =
->     case parseStatementsWithPosition f l c s of
->       Right [st] -> Right st
->       Right _ -> Left "got multiple statements"
->       Left e -> Left $ show e
-
-hack: replace the annotations in asts produced by parsing with
-wildcards, if you don't do this then pattern matches generally don't
-work since the source position annotations from the parser don't match
-up. The source position annotations are still available so that e.g. a
-function can pattern match against a statement then get the source
-position from the matched statements.
-
-> annotToWildCard :: Annotation -> Maybe PatQ
-> annotToWildCard _ = Just $ return WildP
-
-= individual antinode lookup functions
-
-> antiExpE :: ScalarExpr -> Maybe ExpQ
-> antiExpE v = fmap varE (antiExp v)
->
-> antiExprP :: ScalarExpr -> Maybe PatQ
-> antiExprP v = fmap varP $ antiExp v
->
-> antiExp :: ScalarExpr -> Maybe Name
-> antiExp (AntiScalarExpr v) = Just $ mkName v
-> antiExp _ = Nothing
-
-antistatements not working ...
-trying to replace a single antistatement node with multiple statement
-nodes and my generics skills aren't up to the task.
-
-> antiStatementE :: [Statement] -> Maybe ExpQ
-> antiStatementE (AntiStatement v : tl) =
->    Just (listE (vref : conArgs))
->    where
->      conArgs = gmapQ (dataToExpQ (const Nothing
->                        `extQ` antiExpE
->                        `extQ` antiStrE
->                        `extQ` antiTriggerEventE
->                        `extQ` antiStatementE)) tl
->      vref :: ExpQ
->      vref = varE $ mkName v
-> antiStatementE _ = Nothing
-
-> antiStrE :: String -> Maybe ExpQ
-> antiStrE v = fmap varE $ antiStr v
-
-> antiStrP :: String -> Maybe PatQ
-> antiStrP v = fmap varP $ antiStr v
-
-> antiStr :: String -> Maybe Name
-> antiStr v =
->   fmap mkName $ getSpliceName v
->   where
->     getSpliceName s
->       | isPrefixOf "$(" s && last s == ')' =
->           Just $ drop 2 $ init s
->       | isPrefixOf "$s(" s && last s == ')' =
->           Just $ drop 3 $ init s
->       | isPrefixOf "$i(" s && last s == ')' =
->           Just $ drop 3 $ init s
->       | otherwise = Nothing
-
->
-> antiTriggerEventE :: TriggerEvent -> Maybe ExpQ
-> antiTriggerEventE (AntiTriggerEvent v) = Just $ varE $ mkName v
-> antiTriggerEventE _ = Nothing
-
-~~~~
-
- > antiExpP :: Expression -> Maybe PatQ
- > antiExpP (AntiExpression v ) = Just $ varP $ mkName v
- > antiExpP _ = Nothing
-
-to add support for a new splice location, add the type name to the
-list at the top of MakeAntiNodes, adjust the parser to parse splices
-at that point, and add a new antiQ function in this file
-
-
-new idea - to support antiquotation as much as possible, have more
-than one splice syntax:
-
-[$sqlExpr| $(x) |] - want to do a splice like this, sometimes it
-should be
-
-where x= "str" gives
-Identifier [] "str" <- need $(x) to parse as an antiidentifier
-
-and sometimes
-
-where x = FunCall [] "fn" []
-gives
-FunCall [] "fn" [] <- need $(x) to parse as an antiexpression
-
-need context which you don't have to make this decision (and would
-probably be really hard even if the context was available)
-
-so - use two different splice syntaxes.
-
-to avoid doing string splices using [$sqlExpr| '$(sp)' |] which is
-ugly and wrong (?), add another splice for strings?
-
-...
-
-work on tests to try to get some sort of design - want to minimise the
-number of splice syntaxes at the same time not make it difficult to
-work out which syntax to use in which spot.
-
-
-
-what needs to be done to support _ in pattern quasiquotes? -> I think
-it's just adding a wildcard ctor to the appropriate ast types using
-makeantinodes, and adding in lexing and parsing support - actually
-using wildcards is now working with the annotation approach above
-
-~~~~
-
-Some ideas about moving forward
-
-after working on a number of extensions, it seems clear that the quasi
-quotation is a bit limited, specifically the number of splice points
-is too limiting and a lot of ast transforms end up using a lot of ast
-types directly rather than via quotes which is crap.
-
-some possible resolutions:
-
-live with it
-
-add lots more splice points, will need lots of different splice
-syntaxes e.g. to cope with splicing a trigger event list or a single
-trigger event. Will also need to have a load more quote functions to
-parse sql fragments for different contexts.
-
-try and use e.g. a haskell or lisp like syntax for sql, to reduce the
-number of ast types drastically - this will allow much more regular
-use of splice points, quotes, etc.
-
-variant on this idea is instead to move to a tutorial d like syntax,
-which is vastly more regular than sql syntax and should allow for a
-much smaller range of quoters and splice syntaxes also.
-
-maybe might as well switch to haskelldb? the haskell or lisp like
-version of sql syntax keeps us writing the databases in sql, whereas
-tutorial d. haskelldb mean sql really disappears into the
-plumbing. These approaches might solve some problems with custom
-syntax also.
diff --git a/src/Database/HsSqlPpp/Syntax.lhs b/src/Database/HsSqlPpp/Syntax.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Syntax.lhs
@@ -0,0 +1,119 @@
+
+> {- | This module contains the ast node data types. They are very
+>      permissive, in that they allow a lot of invalid SQL to be
+>      represented. The type checking process should catch all invalid
+>      trees, but doesn't quite manage at the moment. Sorry about all
+>      the seemingly pointless type synonyms below, they are an
+>      artefact of using UUAGC. You can see labels for the fields by
+>      looking at the ag source here:
+>      <https://github.com/JakeWheat/hssqlppp/blob/master/src/Database/HsSqlPpp/Internals/AstInternal.ag>
+>      -}
+>
+> module Database.HsSqlPpp.Syntax
+>     (
+>      -- * Name and TypeName
+>      Name(..)
+>     ,NameComponent(..)
+>     ,nameComponents
+>     ,ncStr
+>     ,TypeName(..)
+>      -- * Scalar expressions
+>     ,ScalarExpr(..)
+>     ,InList(..)
+>     ,LiftFlavour(..)
+>     ,Direction(..)
+>     ,NullsOrder(..)
+>     ,Distinct(..)
+>     ,CombineType(..)
+>     ,IntervalField(..)
+>     ,ExtractField(..)
+>     ,FrameClause(..)
+>     ,OdbcLiteralType(..)
+>     -- * Query expressions
+>     ,QueryExpr(..)
+>     ,makeSelect
+>     ,WithQuery(..)
+>     ,SelectList(..)
+>     ,SelectItem(..)
+>     ,TableRef(..)
+>     ,JoinExpr(..)
+>     ,JoinType(..)
+>     ,JoinHint(..)
+>     ,QueryHint(..)
+>     ,OnExpr
+>     ,Natural(..)
+>      -- * Statements
+>     ,Statement(..)
+>      -- ** dml components
+>     ,CopyToSource(..)
+>     ,CopyFromSource(..)
+>     ,CopyToOption(..)
+>     ,CopyFromOption(..)
+>     ,SetClause(..)
+>      -- ** ddl components
+>     ,AttributeDef(..)
+>     ,RowConstraint(..)
+>     ,Constraint(..)
+>     ,TablePartitionDef(..)
+>     ,TablePartitionDateTimeInterval(..)
+>     ,TypeAttributeDef(..)
+>     ,AlterDatabaseOperation(..)
+>     ,AlterSchemaOperation(..)
+>     ,AlterTableOperation(..)
+>     ,AlterTableAction(..)
+>     ,AlterSequenceOperation(..)
+>     ,AlterSequenceAction(..)
+>     ,AlterColumnAction(..)
+>     ,TriggerWhen(..)
+>     ,TriggerEvent(..)
+>     ,TriggerFire(..)
+>     ,DropType(..)
+>     ,Cascade(..)
+>     ,IfExists(..)
+>     ,RestartIdentity(..)
+>      -- *** function ddl components
+>     ,Replace(..)
+>     ,Volatility(..)
+>     ,Language(..)
+>     ,FnBody(..)
+>      -- ** PlPgsql components
+>     ,ParamDef(..)
+>     ,VarDef(..)
+>     ,RaiseType(..)
+>      -- * utility
+>     ,SetValue(..)
+>      -- * misc
+>     {-,WithQueryList
+>     ,MaybeSelectList
+>     ,TableRefList
+>     ,MaybeScalarExpr
+>     ,ScalarExprList
+>     ,ScalarExprListList
+>     ,SetClauseList
+>     ,AttributeDefList
+>     ,ConstraintList
+>     ,TypeAttributeDefList
+>     ,ParamDefList
+>     ,TypeNameList
+>     ,NameTypeNameListPair
+>     ,NameTypeNameListPairList
+>     ,ScalarExprListStatementListTriple
+>     ,ScalarExprListStatementListTripleList
+>     ,ScalarExprStatementListPair
+>     ,ScalarExprStatementListPairList
+>     ,VarDefList
+>     ,SelectItemList
+>     ,RowConstraintList
+>     ,CaseScalarExprListScalarExprPair
+>     ,CaseScalarExprListScalarExprPairList
+>     ,StatementList
+>     ,ScalarExprDirectionPair
+>     ,ScalarExprDirectionPairList
+>     ,AlterTableActionList
+>     ,MaybeNameComponentList
+>     ,NameComponentList
+>     ,MaybeBoolExpr-}
+>     ) where
+>
+> import Database.HsSqlPpp.Internals.AstInternal
+> --import Database.HsSqlPpp.Internals.Name
diff --git a/src/Database/HsSqlPpp/TypeCheck.lhs b/src/Database/HsSqlPpp/TypeCheck.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/TypeCheck.lhs
@@ -0,0 +1,35 @@
+
+This is the public module for the type checking functionality.
+
+> {- | Contains functions for typechecking sql asts.
+> -}
+> module Database.HsSqlPpp.TypeCheck
+>     (
+>      -- * typechecking/ annotation functions
+>      typeCheckStatements
+>     ,typeCheckQueryExpr
+>     ,typeCheckScalarExpr
+>     ,TypeCheckFlags(..)
+>     ,Dialect(..)
+>     ,ansiDialect
+>     ,defaultTypeCheckFlags
+>     ,emptyEnvironment
+>     ) where
+>
+> import Database.HsSqlPpp.Internals.AstInternal
+> import Database.HsSqlPpp.Internals.Dialect
+> import Database.HsSqlPpp.Dialects.Ansi
+> import Database.HsSqlPpp.Internals.TypeChecking.Environment (emptyEnvironment)
+> --import Database.HsSqlPpp.Internals.TypeChecking.Utils
+> --import Database.HsSqlPpp.Internals.AstAnnotation
+
+> -- | reasonable defaults for type checking, doesn't add anything
+> -- optional
+> defaultTypeCheckFlags :: TypeCheckFlags
+> defaultTypeCheckFlags =
+>     TypeCheckFlags
+>     {tcfAddQualifiers = False
+>     ,tcfAddFullTablerefAliases = False
+>     ,tcfAddSelectItemAliases = False
+>     ,tcfExpandStars = False
+>     ,tcfDialect = ansiDialect}
diff --git a/src/Database/HsSqlPpp/TypeChecker.lhs b/src/Database/HsSqlPpp/TypeChecker.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/TypeChecker.lhs
+++ /dev/null
@@ -1,45 +0,0 @@
-
-This is the public module for the type checking functionality.
-
-> {- | Contains the data types and functions for annotating
->  an ast and working with annotated trees, including the
->  representations of SQL data types.
->
-> Annotations:
->
-> * are attached to most of the ast node data types, but not quite all of them;
->
-> * types annotations are attached to most nodes during type checking;
->
-> * type errors are attached to the lowest down node that the type
->   error is detected at;
->
-> * nodes who fail the type check or whose type depends on a node with
->   a type error are given the type 'TypeCheckFailed';
->
-> * each statement has an additional 'StatementInfo' annotation attached to it;
->
-> * the parser fills in the source position annotation in every
->   annotatable ast node.
->
-> -}
-> module Database.HsSqlPpp.TypeChecker
->     (
->      -- * typechecking/ annotation functions
->      typeCheckStatements
->     ,typeCheckParameterizedStatement
->     ,typeCheckQueryExpr
->     ,typeCheckScalarExpr
->     ,fixUpIdentifiers
->     ,fixUpIdentifiersQE
->     ,fixUpIdentifiersSE
->     ,addExplicitCasts
->     ,canonicalizeTypeNames
->      -- * Annotated tree utils
->     ,getStatementAnnotations
->     ) where
->
-> import Database.HsSqlPpp.Internals.AstInternal
-> import Database.HsSqlPpp.Internals.TypeChecking.Utils
-> --import Database.HsSqlPpp.Internals.AstAnnotation
-> import Database.HsSqlPpp.Internals.AnnotationUtils
diff --git a/src/Database/HsSqlPpp/Types.lhs b/src/Database/HsSqlPpp/Types.lhs
--- a/src/Database/HsSqlPpp/Types.lhs
+++ b/src/Database/HsSqlPpp/Types.lhs
@@ -9,17 +9,13 @@
 >     (
 >      -- * SQL types
 >      Type (..)
+>     ,TypeExtra (..)
 >     ,PseudoType (..)
->      -- * type aliases
->      -- | aliases for all the sql types with multiple names
->      -- these give you the canonical names
->     ,typeSmallInt,typeBigInt,typeInt,typeNumeric,typeFloat4
+>     {-,typeSmallInt,typeBigInt,typeInt,typeNumeric,typeFloat4
 >     ,typeFloat8,typeVarChar,typeChar,typeBool,typeDate
->     ,typeInterval
->     ,canonicalizeTypeName
->     ,canonicalizeTypes
+>     ,typeTime,typeTimestamp,typeInterval-}
 >      -- * Type errors
 >     ,TypeError (..)
 >     ) where
 >
-> import Database.HsSqlPpp.Internals.TypeType
+> import Database.HsSqlPpp.Internals.TypesInternal
diff --git a/src/Database/HsSqlPpp/Utility.lhs b/src/Database/HsSqlPpp/Utility.lhs
new file mode 100644
--- /dev/null
+++ b/src/Database/HsSqlPpp/Utility.lhs
@@ -0,0 +1,80 @@
+
+> -- | This module contains a collection of utility functions
+
+> {-# LANGUAGE FlexibleContexts #-}
+> module Database.HsSqlPpp.Utility
+>     (-- * ast utils
+>      resetAnnotations
+>     ,queryType
+>     --,canonicalizeTypeName
+>     --,canonicalizeTypeNames
+>      -- * typechecked ast utils
+>     ,addExplicitCasts
+>     ,addImplicitCasts
+>     ,tcTreeInfo
+>     ,emacsShowErrors
+>     ) where
+
+> import Data.Generics.Uniplate.Data
+> import Data.Data
+> import Data.List
+> import Data.Maybe
+
+> import Database.HsSqlPpp.Internals.AstInternal
+> import Database.HsSqlPpp.Internals.TypesInternal
+> import Database.HsSqlPpp.Internals.ParseInternal
+> import Database.HsSqlPpp.Internals.Catalog.CatalogTypes
+> --import Database.HsSqlPpp.Catalog
+> import Database.HsSqlPpp.Parse
+> import Database.HsSqlPpp.TypeCheck
+> --import Text.Parsec.Prim
+> --import Control.Monad.Identity
+> import qualified Data.Text.Lazy as L
+
+> -- | replace all the annotations in a tree with 'emptyAnnotation'
+> resetAnnotations :: Data a => a -> a
+> resetAnnotations = transformBi (const emptyAnnotation)
+
+> -- | Gets the type of the sql source passed in. Expects the string to contain
+> -- a query expr
+> queryType :: Catalog -> L.Text -> Maybe Type
+> queryType cat src = do
+>   ast <- either (const Nothing) Just $ parseQueryExpr defaultParseFlags "" Nothing src
+>   fmap teType $ anType $ getAnnotation $ typeCheckQueryExpr defaultTypeCheckFlags cat ast
+
+> -- | Gets some information useful for checking a typechecked tree
+> -- returns the type of the top level node, a list of type errors from
+> -- the tree, a list of the queryexpr nodes, and a list of the scalar
+> -- exprs respectively, which have their type as nothing which indicates
+> -- that the typechecking didn't complete successfully
+> tcTreeInfo :: Data a =>
+>               a
+>            -> (Maybe TypeExtra,[([TypeError],Maybe SourcePosition)]
+>               ,[QueryExpr],[ScalarExpr])
+> tcTreeInfo ast =
+>   let noTypeSEs :: [ScalarExpr]
+>       noTypeSEs = [x | x <- universeBi ast
+>                      , isNothing (anType (getAnnotation x))]
+>       noTypeQEs :: [QueryExpr]
+>       noTypeQEs = [x | x <- universeBi ast
+>                      , isNothing (anType (getAnnotation x))]
+>       -- get the list of type errors with source positions
+>       -- from the typechecked ast
+>       tes :: [([TypeError],Maybe SourcePosition)]
+>       tes = [(e,sp) | a@(Annotation {}) <- universeBi ast
+>                     , let e = anErrs a
+>                     , let sp = anSrc a
+>                     , not (null e)]
+>       ty = anType $ getAnnotation ast
+>   in (ty,tes,noTypeQEs,noTypeSEs)
+
+> -- | show a type error list in emacs format
+> emacsShowErrors :: [([TypeError],Maybe SourcePosition)] -> String
+> emacsShowErrors tes =
+>   intercalate "\n" $ map se tes
+>   where
+>     se (es,sp) =
+>       (case sp of
+>          Nothing -> "unknown source"
+>          Just (fn,l,c) -> fn ++ ":" ++ show l ++ ":" ++ show c ++ ":")
+>       ++ " " ++ intercalate "\n" (map show es)
diff --git a/src/Database/HsSqlPpp/Utils/Utils.lhs b/src/Database/HsSqlPpp/Utils/Utils.lhs
deleted file mode 100644
--- a/src/Database/HsSqlPpp/Utils/Utils.lhs
+++ /dev/null
@@ -1,164 +0,0 @@
-
-This file contains some generic utility stuff
-
-> {-# LANGUAGE FlexibleContexts #-}
-> module Database.HsSqlPpp.Utils.Utils where
->
-> import Data.List
-> import Data.Either
-> import Data.Char
-> import Control.Arrow
-> import Control.Monad.Error
-> import Control.Applicative
-
-used to mix regular function composition and >>= in monads, so the
-order of application stays the same instead of going backwards when
-(.) is used
-
-> infixl 9 |>
-> (|>) :: (a -> b) -> (b -> c) -> a -> c
-> (|>) = flip (.)
->
-> errorWhen :: (Error a) => Bool -> a -> Either a ()
-> errorWhen cond = when cond . Left
->
-> returnWhen :: (Monad m) => Bool -> a -> m a -> m a
-> returnWhen c t t1 = if c then return t else t1
->
-> liftME :: a -> Maybe b -> Either a b
-> liftME d m = case m of
->                Nothing -> Left d
->                Just b -> Right b
->
-> both :: (a->b) -> (a,a) -> (b,b)
-> both fn = fn *** fn
->
-> (<:>) :: (Applicative f) =>
->          f a -> f [a] -> f [a]
-> (<:>) a b = (:) <$> a <*> b
->
-
-> eitherToMaybe :: Either a b -> Maybe b
-> eitherToMaybe (Left _) = Nothing
-> eitherToMaybe (Right b) = Just b
->
-> fromRight :: b -> Either a b -> b
-> fromRight b (Left _) = b
-> fromRight _ (Right r) = r
->
-> fromLeft :: a -> Either a b -> a
-> fromLeft _ (Left l) = l
-> fromLeft a (Right _) = a
->
-> mapEither :: (a->c) -> (b->d) -> Either a b -> Either c d
-> mapEither l _ (Left a) = Left $ l a
-> mapEither _ r (Right b) = Right $ r b
->
-> mapRight :: (b -> c) -> Either a b -> Either a c
-> mapRight = mapEither id
->
-> mapLeft :: (a -> c) -> Either a b -> Either c b
-> mapLeft l = mapEither l id
->
-> isRight :: Either a b -> Bool
-> isRight (Right _) = True
-> isRight (Left _) = False
->
-> leftToEmpty :: (r -> [a]) -> Either l r -> [a]
-> leftToEmpty = either (const [])
->
-> replace :: (Eq a) => [a] -> [a] -> [a] -> [a]
-> replace _ _ [] = []
-> replace old new xs@(y:ys) =
->   case stripPrefix old xs of
->     Nothing -> y : replace old new ys
->     Just ys' -> new ++ replace old new ys'
->
-> split :: Char -> String -> [String]
-> split _ ""                =  []
-> split c s                 =  let (l, s') = break (== c) s
->                            in  l : case s' of
->                                            [] -> []
->                                            (_:s'') -> split c s''
->
-> liftThrows :: (MonadError t m) => Either t a -> m a
-> liftThrows (Left err) = throwError err
-> liftThrows (Right val) = return val
->
-> -- run in errort monad, throw error as io error
->
-> wrapET :: (Show e, Monad m) => ErrorT e m a -> m a
-> wrapET c = runErrorT c >>= \x ->
->          case x of
->            Left er -> error $ show er
->            Right l -> return l
->
-> wrapETs :: (Monad m) => ErrorT String m a -> m a
-> wrapETs c = runErrorT c >>= \x ->
->          case x of
->            Left er -> error er
->            Right l -> return l
->
-> -- error utility - convert either to ErrorT String
->
-> tsl :: (MonadError String m, Show t) => Either t a -> m a
-> tsl x = case x of
->                Left s -> throwError $ show s
->                Right b -> return b
->
-> listEither :: [Either a b] -> Either [a] [b]
-> listEither es = let (l,r) = partitionEithers es
->                in if null l
->                   then Right r
->                   else Left l
->
-> forceRight :: Show e => Either e a -> a
-> forceRight (Left x) = error $ show x
-> forceRight (Right x) = x
->
->
-> npartition :: Eq b => (a -> b) -> [a] -> [(b,[a])]
-> npartition keyf l =
->   np [] l
->   where
->     np = foldl (\acc p -> insertWith (++) (keyf p) [p] acc)
->
-> insertWith :: Eq k => (a -> a -> a) -> k -> a -> [(k,a)] -> [(k,a)]
-> insertWith ac k v m =
->     case lookup k m of
->       Nothing -> m ++ [(k,v)]
->       Just v' -> let nv = ac v' v
->                  in map (\p@(k1,_) -> if k1 == k
->                                       then (k1,nv)
->                                       else p) m
-
-
-This should preserve order, so in the result, the keys (k in
-[(k,[a],[b])]) are ordered by their first appearance in as, then bs,
-and the values are ordered the matches in the same order as they
-appear in the two lists ([a] and [b] in [(k,[a],[b])])
-
-> joinLists :: Eq k => (a -> k) -> (b -> k)
->              -> [a] -> [b] -> [(k,[a],[b])]
-> joinLists ka kb as bs =
->     let -- arrange the two lists by key
->         kasps = npartition ka as
->         kbsps = npartition kb bs
->         -- get the list of keys
->         ks = nub $ map fst kasps ++ map fst kbsps
->         -- put together the two lists by key
->     in flip map ks $ \k ->
->         (k, getem k kasps, getem k kbsps)
->     where
->       getem :: Eq k => k -> [(k,[a])] -> [a]
->       getem k = concatMap snd . filter ((==k) . fst)
-
-> trim :: String -> String
-> trim = f . f
->    where f = reverse . dropWhile isSpace
-
-> concatLefts :: [Either [a] b] -> Either [a] ()
-> concatLefts s = let l = concat $ lefts s
->                 in if null l
->                    then Right ()
->                    else Left l
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/CombineQueryExprs.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/CombineQueryExprs.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/CombineQueryExprs.lhs
@@ -0,0 +1,65 @@
+
+
+> {-# LANGUAGE QuasiQuotes,OverloadedStrings,TemplateHaskell #-}
+>
+> module Database.HsSqlPpp.Tests.Parsing.CombineQueryExprs (combineQueryExprs) where
+>
+> import Database.HsSqlPpp.Utils.Here
+>
+> import Database.HsSqlPpp.Syntax
+
+> import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+
+> import qualified Data.Text as T
+
+> combineQueryExprs :: Item
+> combineQueryExprs =
+>    Group "combineSelects"
+>    [q "select a from tbl\n\
+>       \except\n\
+>       \select a from tbl1;"
+>     $ cq Except stbl stbl1
+>    ,q "select a from tbl where true\n\
+>         \except\n\
+>         \select a from tbl1 where true;"
+>       $ cq Except
+>             (stbl {selWhere = Just lTrue})
+>             (stbl1 {selWhere = Just lTrue})
+>    ,q "select a from tbl\n\
+>         \union\n\
+>         \select a from tbl1;"
+>       $ cq Union stbl stbl1
+>    ,q "select a from tbl\n\
+>         \union all\n\
+>         \select a from tbl1;"
+>       $ cq UnionAll stbl stbl1
+>    ,q "(select 1 union select 2) union select 3;"
+>       $ cq Union (cq Union (sel 1) (sel 2)) (sel 3)
+>    ,q "select 1 union (select 2 union select 3);"
+>       $ cq Union (sel 1) (cq Union (sel 2) (sel 3))
+>    ,q [here|
+>          with a as (select a from tbl),
+>               b as (select a from tbl1)
+>               select 1; |]
+>          $ with [("a",stbl)
+>                 ,("b",stbl1)] $ sel 1
+>    ,q [here|
+>          with a as (select a from tbl),
+>               b as (select a from tbl1)
+>               select 1
+>               union select 2; |]
+>          $ with [("a",stbl)
+>                 ,("b",stbl1)] $ cq Union (sel 1) (sel 2)
+>    ]
+>    where
+>      stbl = makeSelect
+>             {selSelectList = sl [si $ ei "a"]
+>             ,selTref = [tref "tbl"]}
+>      stbl1 = makeSelect
+>              {selSelectList = sl [si $ ei "a"]
+>              ,selTref = [tref "tbl1"]}
+>      sel :: Int -> QueryExpr
+>      sel n = makeSelect {selSelectList = sl [si $ num $ T.pack $ show n]}
+>      q = ParseQueryExpr defaultParseFlags
+>      cq = CombineQueryExpr ea
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/CreateTable.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/CreateTable.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/CreateTable.lhs
@@ -0,0 +1,321 @@
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.Parsing.CreateTable (createTable) where
+>
+> import Database.HsSqlPpp.Syntax
+
+> import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+
+> createTable:: Item
+> createTable =
+>   Group "create table" [
+>      Group "simple tables" [
+>       s "create table test (\n\
+>         \  fielda text,\n\
+>         \  fieldb int\n\
+>         \);"
+>       [CreateTable ea
+>        (name "test")
+>        [att "fielda" "text"
+>        ,att "fieldb" "int"
+>        ]
+>        []
+>        Nothing
+>        NoReplace]
+>      ,s "create table tbl (\n\
+>         \  fld boolean default false);"
+>       [CreateTable ea (name "tbl")
+>        [AttributeDef ea (Nmc "fld") (st "boolean")
+>                          (Just lFalse) []][] Nothing NoReplace]
+>
+>      ,s "create table tbl as select 1;"
+>       [CreateTableAs ea (name "tbl") NoReplace
+>        (makeSelect
+>         {selSelectList = sl [si $ num "1"]})]
+>
+>      ,s "create table tbl  (\n\
+>         \  fld int not null identity(1,1));"
+>       [CreateTable ea (name "tbl")
+>        [AttributeDef ea (Nmc "fld") (st "int")
+>                          Nothing [NotNullConstraint ea "", IdentityConstraint ea "" (Just(1,1))]][] Nothing
+>                          NoReplace]
+>
+>      ,s "create table tbl  (\n\
+>         \  fld int not null identity(-1,-1));"
+>       [CreateTable ea (name "tbl")
+>        [AttributeDef ea (Nmc "fld") (st "int")
+>                          Nothing [NotNullConstraint ea "", IdentityConstraint ea "" (Just(-1,-1))]][] Nothing
+>                          NoReplace]
+>
+>      ,s "create table tbl  (\n\
+>         \  fld int not null identity);"
+>       [CreateTable ea (name "tbl")
+>        [AttributeDef ea (Nmc "fld") (st "int")
+>                          Nothing [NotNullConstraint ea "", IdentityConstraint ea "" Nothing]][] Nothing
+>                          NoReplace]
+>
+>      ,s "alter table a rename to b;"
+>       [AlterTable ea (name "a") $ RenameTable ea (name "b")]
+>      ,s "alter table a rename column b to c;"
+>       [AlterTable ea (name "a") $ RenameColumn ea (Nmc "b") (Nmc "c")]
+>
+>      ,s "alter table a add column b int;"
+>       [AlterTable ea (name "a") $ AlterTableActions ea [AddColumn ea $ att "b" "int"]]
+>
+>      ,s "alter table a drop column b;"
+>       [AlterTable ea (name "a") $ AlterTableActions ea [DropColumn ea (Nmc "b")]]
+>
+>      ,s "alter table a alter column b set data type int;"
+>       [AlterTable ea (name "a") $ AlterTableActions ea [AlterColumn ea (Nmc "b") $ SetDataType ea (st "int")]]
+>
+>      ,s "alter table a alter column b set data type int;"
+>       [AlterTable ea (name "a") $ AlterTableActions ea [AlterColumn ea (Nmc "b") $ SetDataType ea (st "int")]]
+>
+>      ,s "alter table a alter column b set default 1;"
+>       [AlterTable ea (name "a") $ AlterTableActions ea [AlterColumn ea (Nmc "b") $ SetDefault ea (num "1")]]
+>      ,s "alter table a alter column b drop default;"
+>       [AlterTable ea (name "a") $ AlterTableActions ea [AlterColumn ea (Nmc "b") $ DropDefault ea]]
+>
+>      ,s "alter table a alter column b set not null;"
+>       [AlterTable ea (name "a") $ AlterTableActions ea [AlterColumn ea (Nmc "b") $ SetNotNull ea]]
+>      ,s "alter table a alter column b drop not null;"
+>       [AlterTable ea (name "a") $ AlterTableActions ea [AlterColumn ea (Nmc "b") $ DropNotNull ea]]
+>
+>      ,s "alter table a add column b int,drop column c;"
+>       [AlterTable ea (name "a") $ AlterTableActions ea [AddColumn ea $ att "b" "int"
+>                                                        ,DropColumn ea (Nmc "c")]]
+>
+>      ,s "alter table a drop column b;"
+>       [AlterTable ea (name "a") $ AlterTableActions ea [DropColumn ea (Nmc "b")]]
+>      ,s "alter table a add constraint unique(b);"
+>       [AlterTable ea (name "a") $ AlterTableActions ea [AddConstraint ea (UniqueConstraint ea "" [Nmc "b"])]]
+>      ]
+>     ,Group "constraints" [
+>       Group "nulls" [
+>       s "create table t1 (\n\
+>         \ a text null\n\
+>         \);"
+>         [CreateTable ea (name "t1") [AttributeDef ea (Nmc "a") (st "text")
+>                            Nothing [NullConstraint ea ""]]
+>          [] Nothing NoReplace]
+>      ,s "create table t1 (\n\
+>         \ a text not null\n\
+>         \);"
+>         [CreateTable ea (name "t1") [AttributeDef ea (Nmc "a") (st "text")
+>                                     Nothing [NotNullConstraint ea ""]]
+>          [] Nothing NoReplace]
+>      ]
+>
+>      ,Group "unique" [
+>       s "create table t1 (\n\
+>         \ x int,\n\
+>         \ y int,\n\
+>         \ unique (x,y)\n\
+>         \);"
+>         [CreateTable ea (name "t1") [att "x" "int"
+>                                    ,att "y" "int"]
+>          [UniqueConstraint ea "" [Nmc "x",Nmc "y"]] Nothing NoReplace]
+
+test arbitrary ordering
+
+>      ,s "create table t1 (\n\
+>         \ x int,\n\
+>         \ unique (x),\n\
+>         \ y int\n\
+>         \);"
+>         [CreateTable ea (name "t1") [att "x" "int"
+>                                    ,att "y" "int"]
+>          [UniqueConstraint ea "" [Nmc "x"]] Nothing NoReplace]
+
+
+test partitioning parser
+
+>      ,s "create table t1(\n\
+>         \ x int,\n\
+>         \ ts datetime\n\
+>         \ )\n\
+>         \ partition by range(ts)\n\
+>         \  (\n\
+>         \   every 5 months\n\
+>         \);"
+>         [CreateTable ea (name "t1") [att "x" "int"
+>                                     ,att "ts" "datetime"]
+>           []
+>          (Just (TablePartitionDef ea (Nmc "ts") 5 Month)) NoReplace]
+
+
+unique row
+
+>      ,s "create table t1 (\n\
+>         \ x int unique\n\
+>         \);"
+>         [CreateTable ea (name "t1")
+>          [AttributeDef ea (Nmc "x") (st "int") Nothing
+>           [RowUniqueConstraint ea ""]][] Nothing NoReplace]
+>
+>      ,s "create table t1 (\n\
+>         \ x int unique not null\n\
+>         \);"
+>         [CreateTable ea (name "t1") [AttributeDef ea (Nmc "x") (st "int") Nothing
+>                                     [RowUniqueConstraint ea ""
+>                                     ,NotNullConstraint ea ""]][] Nothing NoReplace]
+
+quick sanity check
+
+>      ,s "create table t1 (\n\
+>         \ x int not null unique\n\
+>         \);"
+>         [CreateTable ea (name "t1") [AttributeDef ea (Nmc "x") (st "int") Nothing
+>                                     [NotNullConstraint ea ""
+>                                     ,RowUniqueConstraint ea ""]][] Nothing NoReplace]
+>      ]
+>
+>      ,Group "primary key" [
+>       s "create table t1 (\n\
+>         \ x int primary key\n\
+>         \);"
+>         [CreateTable ea (name "t1") [AttributeDef ea (Nmc "x") (st "int") Nothing
+>                            [RowPrimaryKeyConstraint ea ""]][] Nothing NoReplace]
+>
+>      ,s "create table t1 (\n\
+>         \ x int,\n\
+>         \ y int,\n\
+>         \ primary key (x,y)\n\
+>         \);"
+>         [CreateTable ea (name "t1") [att "x" "int"
+>                           ,att "y" "int"]
+>          [PrimaryKeyConstraint ea "" [Nmc "x", Nmc "y"]] Nothing NoReplace]
+>      ]
+>
+>      ,Group "check" [
+>       s "create table t (\n\
+>         \f text check (f in('a', 'b'))\n\
+>         \);"
+>         [CreateTable ea (name "t")
+>          [AttributeDef ea (Nmc "f") (st "text") Nothing
+>           [RowCheckConstraint ea "" (InPredicate ea
+>                                   (ei "f") True
+>                                   (InList ea [stringQ "a", stringQ "b"]))]] [] Nothing NoReplace]
+>
+>      ,s "create table t1 (\n\
+>         \ x int,\n\
+>         \ y int,\n\
+>         \ check (x>y)\n\
+>         \);"
+>         [CreateTable ea (name "t1") [att "x" "int"
+>                                    ,att "y" "int"]
+>          [CheckConstraint ea "" (binop ">" (ei "x") (ei "y"))] Nothing NoReplace]
+>      ]
+>
+>      ,Group "misc" [
+>       s "create table t (\n\
+>         \f text not null unique check (f in('a', 'b'))\n\
+>         \);"
+>         [CreateTable ea (name "t")
+>          [AttributeDef ea (Nmc "f") (st "text") Nothing
+>           [NotNullConstraint ea ""
+>            ,RowUniqueConstraint ea ""
+>            ,RowCheckConstraint ea "" (InPredicate ea
+>                                    (ei "f") True
+>                                    (InList ea [stringQ "a"
+>                                               ,stringQ "b"]))]] [] Nothing NoReplace]
+>      ]
+
+>      ,Group "references" [
+>       s "create table t1 (\n\
+>         \ x int references t2\n\
+>         \);"
+>         [CreateTable ea (name "t1") [AttributeDef ea (Nmc "x") (st "int") Nothing
+>                            [RowReferenceConstraint ea "" (name "t2") Nothing
+>                             Restrict Restrict]][] Nothing NoReplace]
+>
+>      ,s "create table t1 (\n\
+>         \ x int references t2(y)\n\
+>         \);"
+>         [CreateTable ea (name "t1") [AttributeDef ea (Nmc "x") (st "int") Nothing
+>                            [RowReferenceConstraint ea "" (name "t2") (Just $ Nmc "y")
+>                             Restrict Restrict]][] Nothing NoReplace]
+>      ,s "create table t1 (\n\
+>         \ x int,\n\
+>         \ y int,\n\
+>         \ foreign key (x,y) references t2\n\
+>         \);"
+>         [CreateTable ea (name "t1") [att "x" "int"
+>                                    ,att "y" "int"]
+>          [ReferenceConstraint ea "" [Nmc "x", Nmc "y"] (name "t2") []
+>           Restrict Restrict] Nothing NoReplace]
+>
+>      ,s "create table t1 (\n\
+>         \ x int,\n\
+>         \ y int,\n\
+>         \ foreign key (x,y) references t2(z,w)\n\
+>         \);"
+>         [CreateTable ea (name "t1") [att "x" "int"
+>                           ,att "y" "int"]
+>          [ReferenceConstraint ea "" [Nmc "x", Nmc "y"] (name "t2") [Nmc "z", Nmc "w"]
+>           Restrict Restrict] Nothing NoReplace]
+>
+>      ,s "create table t1 (\n\
+>         \ x int references t2 on delete cascade\n\
+>         \);"
+>         [CreateTable ea (name "t1") [AttributeDef ea (Nmc "x") (st "int") Nothing
+>                            [RowReferenceConstraint ea "" (name "t2") Nothing
+>                             Cascade Restrict]][] Nothing NoReplace]
+>
+>      ,s "create table t1 (\n\
+>         \ x int references t2 on update cascade\n\
+>         \);"
+>         [CreateTable ea (name "t1") [AttributeDef ea (Nmc "x") (st "int") Nothing
+>                            [RowReferenceConstraint ea "" (name "t2") Nothing
+>                             Restrict Cascade]][] Nothing NoReplace]
+>
+>      ,s "create table t1 (\n\
+>         \ x int references t2 on delete cascade on update cascade\n\
+>         \);"
+>         [CreateTable ea (name "t1") [AttributeDef ea (Nmc "x") (st "int") Nothing
+>                                     [RowReferenceConstraint ea "" (name "t2") Nothing
+>                                      Cascade Cascade]][] Nothing NoReplace]
+>
+>      ,s "create table t1 (\n\
+>         \ x int,\n\
+>         \ y int,\n\
+>         \ foreign key (x,y) references t2 on update cascade on delete cascade\n\
+>         \);"
+>         [CreateTable ea (name "t1") [att "x" "int"
+>                                    ,att "y" "int"]
+>          [ReferenceConstraint ea "" [Nmc "x", Nmc "y"] (name "t2") []
+>           Cascade Cascade] Nothing NoReplace]
+>      ,s "create or replace table test (\n\
+>         \  fielda text,\n\
+>         \  fieldb int\n\
+>         \);"
+>       [CreateTable ea
+>        (name "test")
+>        [att "fielda" "text"
+>        ,att "fieldb" "int"
+>        ]
+>        []
+>        Nothing
+>        Replace]
+>
+>      ,s "create or replace table tbl as select 1;"
+>       [CreateTableAs ea (name "tbl") Replace
+>        (makeSelect
+>         {selSelectList = sl [si $ num "1"]})]
+>
+>      ,s "create or replace table t1 (\n\
+>         \ x int,\n\
+>         \ y int,\n\
+>         \ foreign key (x,y) references t2(z,w)\n\
+>         \);"
+>         [CreateTable ea (name "t1") [att "x" "int"
+>                           ,att "y" "int"]
+>          [ReferenceConstraint ea "" [Nmc "x", Nmc "y"] (name "t2") [Nmc "z", Nmc "w"]
+>           Restrict Restrict] Nothing Replace]
+>      ]
+>      ]
+>      ]
+
+>  where
+>    s = ParseStmts defaultParseFlags
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/Dml.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/Dml.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/Dml.lhs
@@ -0,0 +1,154 @@
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.Parsing.Dml (dml) where
+>
+> import Database.HsSqlPpp.Syntax
+
+> import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+
+TODO:
+
+from in update, using in delete (+ type check these)
+
+> dml:: Item
+> dml =
+>    Group "dml" [
+>      Group "insert" [
+>       s "insert into testtable\n\
+>         \(columna,columnb)\n\
+>         \values (1,2);\n"
+>        [Insert ea
+>         (name "testtable")
+>         [Nmc "columna", Nmc "columnb"]
+>         (Values ea [[num "1", num "2"]])
+>         Nothing]
+
+multi row insert, test the stand alone values statement first, maybe
+that should be in the select section?
+
+>      ,s "values (1,2), (3,4);"
+>      [QueryStatement ea $ Values ea [[num "1", num "2"]
+>                                     ,[num "3", num "4"]]]
+>
+>      ,s "insert into testtable\n\
+>         \(columna,columnb)\n\
+>         \values (1,2), (3,4);\n"
+>       [Insert ea
+>         (name "testtable")
+>         [Nmc "columna", Nmc "columnb"]
+>         (Values ea [[num "1", num "2"]
+>                    ,[num "3", num "4"]])
+>         Nothing]
+
+insert from select
+
+>      ,s "insert into a\n\
+>          \    select b from c;"
+>       [Insert ea (name "a") []
+>        (makeSelect
+>         {selSelectList = sl [si $ ei "b"]
+>         ,selTref = [tref "c"]})
+>        Nothing]
+>
+>      ,s "insert into testtable\n\
+>         \(columna,columnb)\n\
+>         \values (1,2) returning id;\n"
+>       [Insert ea
+>         (name "testtable")
+>         [Nmc "columna", Nmc "columnb"]
+>         (Values ea [[num "1", num "2"]])
+>         (Just $ sl [si $ ei "id"])]
+>      ]
+>
+>     ,Group "update" [
+>       s "update tb\n\
+>         \  set x = 1, y = 2;"
+>       [Update ea (name "tb") [set "x" $ num "1"
+>                             ,set "y" $ num "2"]
+>        [] Nothing Nothing]
+>      ,s "update tb\n\
+>         \  set x = 1, y = 2 where z = true;"
+>       [Update ea (name "tb") [set "x" $ num "1"
+>                             ,set "y" $ num "2"]
+>        []
+>        (Just $ binop "=" (ei "z") lTrue)
+>        Nothing]
+>      ,s "update tb\n\
+>         \  set x = 1, y = 2 returning id;"
+>       [Update ea (name "tb") [set "x" $ num "1"
+>                             ,set "y" $ num "2"]
+>        [] Nothing (Just $ sl [si $ ei "id"])]
+>      ,s "update tb\n\
+>         \  set (x,y) = (1,2);"
+>       [Update ea (name "tb")
+>        [MultiSetClause ea [Nmc "x",Nmc "y"]
+>         $ specop "rowctor" [num "1"
+>                             ,num "2"]]
+>        []
+>        Nothing Nothing]
+>      ]
+
+App ea "=" [App ea "rowctor" [Identifier ea "x",Identifier ea "y"],App ea "rowctor" [num "1",num "2"]])
+
+
+>
+>     ,Group "delete" [
+>       s "delete from tbl1 where x = true;"
+>       [Delete ea (name "tbl1") [] (Just $ binop "=" (ei "x") lTrue)
+>        Nothing]
+>      ,s "delete from tbl1 where x = true returning id;"
+>       [Delete ea (name "tbl1") [] (Just $ binop "=" (ei "x") lTrue)
+>        (Just $ sl [si $ ei "id"])]
+>      ]
+>
+>     ,Group "truncate" [
+>       s "truncate test;"
+>        [Truncate ea [name "test"] ContinueIdentity Restrict]
+>
+>      ,s "truncate table test, test2 restart identity cascade;"
+>        [Truncate ea [name "test",name "test2"] RestartIdentity Cascade]
+>      ]
+
+copy, bit crap at the moment
+
+>     ,Group "copy" [
+>       s "copy tbl(a,b) from stdin;\n\
+>         \bat\tt\n\
+>         \bear\tf\n\
+>         \\\.\n"
+>       [CopyFrom ea (name "tbl") [Nmc "a", Nmc "b"] Stdin []
+>        ,CopyData ea "\
+>         \bat\tt\n\
+>         \bear\tf\n"]
+>      ,s "copy tbl (a,b) from 'filename' with delimiter '|';"
+>       [CopyFrom ea (name "tbl") [Nmc "a", Nmc "b"]
+>       (CopyFilename "filename")
+>        [CopyFromDelimiter "|"]]
+>      ,s "copy tbl (a,b) from 'filename' with delimiter '|' parsers 'b=oracle';"
+>       [CopyFrom ea (name "tbl") [Nmc "a", Nmc "b"]
+>       (CopyFilename "filename")
+>        [CopyFromDelimiter "|",CopyFromParsers "b=oracle"]]
+>      ,s "copy tbl (a,b) from 'filename' with delimiter '|' error_log 'errors.log';"
+>       [CopyFrom ea (name "tbl") [Nmc "a", Nmc "b"]
+>       (CopyFilename "filename")
+>        [CopyFromDelimiter "|",CopyFromErrorLog "errors.log"]]
+>      ,s "copy tbl (a,b) from 'filename' with delimiter '|' error_log 'errors.log' error_verbosity 1;"
+>       [CopyFrom ea (name "tbl") [Nmc "a", Nmc "b"]
+>       (CopyFilename "filename")
+>        [CopyFromDelimiter "|", CopyFromErrorLog "errors.log", CopyFromErrorVerbosity 1]]
+>      ,s "copy tbl (a,b) from 'filename' with delimiter '|' error_log 'errors.log' error_verbosity 1 parsers 'b=oracle';"
+>       [CopyFrom ea (name "tbl") [Nmc "a", Nmc "b"]
+>       (CopyFilename "filename")
+>        [CopyFromDelimiter "|", CopyFromErrorLog "errors.log", CopyFromErrorVerbosity 1,CopyFromParsers "b=oracle"]]
+>      ,s "copy tbl to 'file';"
+>       [CopyTo ea (CopyTable (name "tbl") []) "file" []]
+>      ,s "copy tbl(a,b) to 'file';"
+>       [CopyTo ea (CopyTable (name "tbl") [Nmc "a", Nmc "b"]) "file" []]
+>      ,s "copy (select * from tbl) to 'file' with format binary;"
+>       [CopyTo ea (CopyQuery $ makeSelect {selSelectList = sl [si $ Star ea]
+>                                          ,selTref = [tref "tbl"]})
+>        "file" [CopyToFormat "binary"]]
+>      ]]
+>  where
+>    s = ParseStmts defaultParseFlags
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/FunctionsDdl.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/FunctionsDdl.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/FunctionsDdl.lhs
@@ -0,0 +1,150 @@
+
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.Parsing.FunctionsDdl (functionsDdl) where
+>
+> import Database.HsSqlPpp.Syntax
+> import Database.HsSqlPpp.Dialect
+
+> import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+
+> functionsDdl:: Item
+> functionsDdl =
+>    Group "functionsddl" [
+>      Group "basics" [
+>       s "create function t1(text) returns text as $$\n\
+>         \select a from t1 where b = $1;\n\
+>         \$$ language sql stable;"
+>       [CreateFunction ea (name "t1") [ParamDefTp ea $ st "text"]
+>        (st "text") NoReplace Sql
+>        (SqlFnBody ea
+>         [QueryStatement ea $
+>          makeSelect
+>          {selSelectList = sl [si $ ei "a"]
+>          ,selTref = [tref "t1"]
+>          ,selWhere = Just $ binop "=" (ei "b") (PositionalArg ea 1)}])
+>        Stable]
+>      ,s "create function fn() returns void as $$\n\
+>         \declare\n\
+>         \  a int;\n\
+>         \  b text;\n\
+>         \begin\n\
+>         \  null;\n\
+>         \end;\n\
+>         \$$ language plpgsql volatile;"
+>       [CreateFunction ea (name "fn") [] (st "void") NoReplace Plpgsql
+>        (PlpgsqlFnBody ea (Block ea Nothing [varDef "a" (st "int")
+>                                            ,varDef "b" (st "text")]
+>                           [NullStatement ea]))
+>        Volatile]
+>      ,s "create function fn() returns void as $$\n\
+>         \declare\n\
+>         \  a int;\n\
+>         \  b text;\n\
+>         \begin\n\
+>         \  null;\n\
+>         \end;\n\
+>         \$$ language plpgsql volatile;"
+>       [CreateFunction ea (name "fn") [] (st "void") NoReplace Plpgsql
+>        (PlpgsqlFnBody ea
+>         (Block ea Nothing [varDef "a" (st "int")
+>                           ,varDef "b" (st "text")]
+>         [NullStatement ea]))
+>        Volatile]
+>      ,s "create function fn(a text[]) returns int[] as $$\n\
+>         \declare\n\
+>         \  b xtype[] := '{}';\n\
+>         \begin\n\
+>         \  null;\n\
+>         \end;\n\
+>         \$$ language plpgsql immutable;"
+>       [CreateFunction ea (name "fn")
+>        [paramDef "a" $ at "text"]
+>        (at "int") NoReplace Plpgsql
+>        (PlpgsqlFnBody ea
+>         (Block ea Nothing
+>          [varDefv "b" (at "xtype") (stringQ "{}")]
+>          [NullStatement ea]))
+>        Immutable]
+>      ,s "create function fn() returns void as '\n\
+>         \declare\n\
+>         \  a int := 3;\n\
+>         \begin\n\
+>         \  null;\n\
+>         \end;\n\
+>         \' language plpgsql stable;"
+>       [CreateFunction ea (name "fn") [] (st "void") NoReplace Plpgsql
+>        (PlpgsqlFnBody ea
+>         (Block ea Nothing
+>          [varDefv "a" (st "int") (num "3")]
+>          [NullStatement ea]))
+>        Stable]
+>      ,s "create function fn(int) returns void as '\n\
+>         \declare\n\
+>         \  a alias for $1;\n\
+>         \begin\n\
+>         \  null;\n\
+>         \end;\n\
+>         \' language plpgsql stable;"
+>       [CreateFunction ea (name "fn")
+>        [ParamDefTp ea $ st "int"]
+>        (st "void") NoReplace Plpgsql
+>        (PlpgsqlFnBody ea
+>         (Block ea Nothing
+>          [ParamAlias ea (Nmc "a") 1]
+>          [NullStatement ea]))
+>        Stable]
+>      ,s "create function fn(b int) returns void as '\n\
+>         \declare\n\
+>         \  a alias for b;\n\
+>         \begin\n\
+>         \  null;\n\
+>         \end;\n\
+>         \' language plpgsql stable;"
+>       [CreateFunction ea (name "fn")
+>        [ParamDef ea (Nmc "b") $ st "int"]
+>        (st "void") NoReplace Plpgsql
+>        (PlpgsqlFnBody ea
+>         (Block ea Nothing
+>          [VarAlias ea (Nmc "a") (name "b")]
+>          [NullStatement ea]))
+>        Stable]
+>      ,s "create function fn() returns setof int as $$\n\
+>         \begin\n\
+>         \  null;\n\
+>         \end;\n\
+>         \$$ language plpgsql stable;"
+>       [CreateFunction ea (name "fn") []
+>        (SetOfTypeName ea $ st "int") NoReplace Plpgsql
+>        (PlpgsqlFnBody ea (Block ea Nothing [] [NullStatement ea]))
+>        Stable]
+>      ,s "create function fn() returns void as $$\n\
+>         \begin\n\
+>         \  null;\n\
+>         \end\n\
+>         \$$ language plpgsql stable;"
+>       [CreateFunction ea (name "fn") []
+>        (st "void") NoReplace Plpgsql
+>        (PlpgsqlFnBody ea (Block ea Nothing [] [NullStatement ea]))
+>        Stable]
+>      ,s "create or replace function fn() returns void as $$\n\
+>         \begin\n\
+>         \  null;\n\
+>         \end\n\
+>         \$$ language plpgsql stable;"
+>       [CreateFunction ea (name "fn") []
+>        (st "void") Replace Plpgsql
+>        (PlpgsqlFnBody ea (Block ea Nothing [] [NullStatement ea]))
+>        Stable]
+>      ,s "drop function test(text);"
+>       [DropFunction ea Require [(name "test",[st "text"])] Restrict]
+>      ,s "drop function test(int,int);"
+>       [DropFunction ea Require [(name "test",[st "int"
+>                                             ,st "int"])] Restrict]
+>      ,s "drop function if exists a(),test(text) cascade;"
+>       [DropFunction ea IfExists [(name "a",[])
+>                                 ,(name "test",[st "text"])] Cascade]
+>     ]]
+>  where
+>    s = ParseStmts defaultParseFlags {pfDialect = postgresDialect}
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/Joins.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/Joins.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/Joins.lhs
@@ -0,0 +1,108 @@
+
+
+> {-# LANGUAGE QuasiQuotes,OverloadedStrings #-}
+>
+> module Database.HsSqlPpp.Tests.Parsing.Joins (joins) where
+>
+> --import Database.HsSqlPpp.Utils.Here
+>
+> import Database.HsSqlPpp.Syntax
+
+> import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+
+> joins :: Item
+> joins =
+>   Group "joins"
+>   [q "select a from t1,t2"
+>    stbl {selTref = [tref "t1", tref "t2"]}
+>   ,q "select a from t1 natural inner join t2"
+>    stbl {selTref = [naturalInnerJoin (tref "t1") (tref "t2")]}
+>   ,q "select a from t1 inner join t2 using (a)"
+>    stbl {selTref = [usingInnerJoin (tref "t1") (tref "t2") ["a"]]}
+
+todo: these aren't quite right: any join which isn't natural requires
+a using or on clause. maybe the syntax should be fixed to represent
+this?
+
+>   ,q "select a from t1 left outer join t2"
+>    stbl {selTref = [tjoin (tref "t1") LeftOuter (tref "t2") Nothing]}
+>   ,q "select a from t1 right outer join t2"
+>    stbl {selTref = [tjoin (tref "t1") RightOuter (tref "t2") Nothing]}
+>   ,q "select a from t1 full outer join t2"
+>    stbl {selTref = [tjoin (tref "t1") FullOuter (tref "t2") Nothing]}
+>   ,q "select a from t1 cross join t2"
+>    stbl {selTref = [tjoin (tref "t1") Cross (tref "t2") Nothing]}
+>   ,q "select a from t1 join t2"
+>    stbl {selTref = [tjoin (tref "t1") Inner (tref "t2") Nothing]}
+>   ,q "select a from (b natural join c);"
+>    stbl {selTref = [tfp $ naturalInnerJoin (tref "b") (tref "c")]}
+
+>   ,q "select a from a cross join b cross join c;"
+>    stbl {selTref = [tjoin
+>                     (tjoin (tref "a") Cross (tref "b") Nothing)
+>                     Cross
+>                     (tref "c") Nothing]}
+>   ,q "select a from (a cross join b) cross join c;"
+>    stbl {selTref = [tjoin
+>                     (tfp $ tjoin (tref "a") Cross (tref "b") Nothing)
+>                     Cross
+>                     (tref "c") Nothing]}
+>   ,q "select a from ((a cross join b) cross join c);"
+>    stbl {selTref = [tfp $ tjoin
+>                     (tfp $ tjoin (tref "a") Cross (tref "b") Nothing)
+>                     Cross
+>                     (tref "c") Nothing]}
+
+>   ,q "select a from a cross join (b cross join c);"
+>    stbl {selTref = [tjoin
+>                     (tref "a") Cross
+>                     (tfp $ tjoin (tref "b") Cross (tref "c") Nothing)
+>                     Nothing]}
+
+>   ,q "select a from (a cross join (b cross join c));"
+>    stbl {selTref = [tfp $ tjoin
+>                     (tref "a") Cross
+>                     (tfp $ tjoin (tref "b") Cross (tref "c") Nothing)
+>                     Nothing]}
+
+>   ,q "select a from ((a cross join b) cross join c) cross join d;"
+>    stbl {selTref = [tjoin
+>                     (tfp $ tjoin
+>                      (tfp $ tjoin (tref "a") Cross (tref "b") Nothing)
+>                      Cross
+>                      (tref "c") Nothing)
+>                     Cross
+>                     (tref "d") Nothing]}
+
+>   ,q "select a from a cross join b cross join c cross join d;"
+>    stbl {selTref = [tjoin
+>                     (tjoin
+>                      (tjoin (tref "a") Cross (tref "b") Nothing)
+>                      Cross
+>                      (tref "c") Nothing)
+>                     Cross
+>                     (tref "d") Nothing]}
+>   {-,q "select a from (t cross join u) x"
+>    stbl {selTref = [TableAlias ea (Nmc "x") $ tfp
+>                     $ (join (tref "t") Cross (tref "u") Nothing)]}
+>   ,q "select a from (t as t(a, b) cross join u as t(c, d)) as t(a, b, c, d);"
+>    stbl {selTref = [TableAlias ea (Nmc "x") $ tfp
+>                     $ (join (tref "t") Cross (tref "u") Nothing)]}-}
+
+
+>   ,q "select a from b\n\
+>       \    inner join c\n\
+>       \      on true\n\
+>       \    inner join d\n\
+>       \      on 1=1;"
+>     stbl {selTref = [innerJoin
+>                      (innerJoin (tref "b") (tref "c") (Just lTrue))
+>                      (tref "d") (Just $ binop "=" (num "1") (num "1"))]}
+>   ]
+
+>    where
+>      stbl = makeSelect
+>             {selSelectList = sl [si $ ei "a"]
+>             ,selTref = [tref "tbl"]}
+>      q = ParseQueryExpr defaultParseFlags
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/LexerTests.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/LexerTests.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/LexerTests.lhs
@@ -0,0 +1,98 @@
+
+todo:
+quickcheck:
+generate random symbols
+print then parse, check equal
+generate random strings
+
+try to parse, if parses, print and check equal to original string
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.Parsing.LexerTests where
+
+> import Database.HsSqlPpp.Lex
+> --import Database.HsSqlPpp.Internals.Dialect
+> import Database.HsSqlPpp.Tests.TestTypes
+> import Database.HsSqlPpp.Dialect
+> --import Database.HsSqlPpp.Tests.Parsing.Utils
+
+> lexerTests :: Item
+> lexerTests = Group "lexing"
+>     [Lex postgresDialect "'string'" [SqlString "'" "'" "string"]
+>     ,Lex postgresDialect "E'string\\n'" [SqlString "E'" "'" "string\\n"] -- the \\n is to put a literal \ and n in the string
+>     ,Lex postgresDialect "E'bsquoteend\\''" [SqlString "E'" "'" "bsquoteend\\'"]
+>     ,Lex postgresDialect "E'bsquote\\'xx'" [SqlString "E'" "'" "bsquote\\'xx"]
+>     ,Lex postgresDialect "E'quoteend'''" [SqlString "E'" "'" "quoteend''"]
+>     ,Lex postgresDialect "E'quote''x'" [SqlString "E'" "'" "quote''x"]
+>     ,Lex postgresDialect "'normal '' quote'" [SqlString "'" "'" "normal '' quote"]
+>     ,Lex postgresDialect "'normalendquote '''" [SqlString "'" "'" "normalendquote ''"]
+>     ,Lex postgresDialect "$$dollar quoting$$" [SqlString "$$" "$$" "dollar quoting"]
+>     ,Lex postgresDialect "$x$dollar $$ quoting$x$" [SqlString "$x$" "$x$" "dollar $$ quoting"]
+
+identifiers
+
+>     ,Lex postgresDialect "test" [Identifier Nothing "test"]
+>     ,Lex postgresDialect "_test" [Identifier Nothing "_test"]
+>     ,Lex postgresDialect "\"test test\"" [Identifier (Just ("\"","\"")) "test test"]
+>     ,Lex postgresDialect "test123" [Identifier Nothing "test123"]
+>     ,Lex sqlServerDialect "[test \"]" [Identifier (Just ("[","]")) "test \""]
+>     ,Lex sqlServerDialect "@test" [PrefixedVariable '@' "test"]
+>     ,Lex sqlServerDialect "#test" [PrefixedVariable '#' "test"]
+>     ,Lex oracleDialect ":test" [PrefixedVariable ':' "test"]
+
+symbols
+
+>     ,Lex postgresDialect "+" [Symbol "+"]
+>     ,Lex postgresDialect "*" [Symbol "*"]
+
+numbers
+
+>     ,Lex postgresDialect "10" [SqlNumber "10"]
+>     ,Lex postgresDialect ".1" [SqlNumber ".1"]
+>     ,Lex postgresDialect "5e3" [SqlNumber "5e3"]
+>     ,Lex postgresDialect "5e+3" [SqlNumber "5e+3"]
+>     ,Lex postgresDialect "5e-3" [SqlNumber "5e-3"]
+>     ,Lex postgresDialect "10.2" [SqlNumber "10.2"]
+>     ,Lex postgresDialect "10.2e7" [SqlNumber "10.2e7"]
+
+whitespace
+
+>     ,Lex postgresDialect " " [Whitespace " "]
+>     ,Lex postgresDialect "  " [Whitespace "  "]
+>     ,Lex postgresDialect "\n" [Whitespace "\n"]
+>     ,Lex postgresDialect "\t" [Whitespace "\t"]
+
+check dots
+
+>     ,Lex postgresDialect "a.b" [Identifier Nothing "a"
+>                                  ,Symbol "."
+>                                  ,Identifier Nothing "b"]
+
+positional arg
+
+>     ,Lex postgresDialect "$1" [PositionalArg 1]
+
+line comment
+
+>     ,Lex postgresDialect "-- this is a comment\n" [LineComment "-- this is a comment\n"]
+>     -- check eof with no trailing newline
+>     ,Lex postgresDialect "-- this is a comment" [LineComment "-- this is a comment"]
+
+block comment
+
+>     ,Lex postgresDialect "/* block\ncomment */" [BlockComment "/* block\ncomment */"]
+>     ,Lex postgresDialect "/* nested /*block*/ comment */" [BlockComment "/* nested /*block*/ comment */"]
+
+splice
+
+>     ,Lex postgresDialect "$c(splice)" [Splice 'c' "splice"]
+
+>     ,Lex postgresDialect "1 .. 2"
+>        [SqlNumber "1", Whitespace " ", Symbol ".."
+>        ,Whitespace " ", SqlNumber "2"]
+
+>     ,Lex postgresDialect "1..2"
+>        [SqlNumber "1", Symbol "..", SqlNumber "2"]
+
+
+>     ]
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/Misc.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/Misc.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/Misc.lhs
@@ -0,0 +1,63 @@
+
+The automated tests, uses hunit to check a bunch of text expressions
+and sql statements parse to the correct tree, and then checks pretty
+printing and then reparsing gives the same tree. The code was mostly
+written almost in tdd style, which the order/ coverage of these tests
+reflects.
+
+There are no tests for invalid syntax at the moment.
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.Parsing.Misc (misc) where
+>
+> import Database.HsSqlPpp.Syntax
+
+> import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+
+> misc :: Item
+> misc =
+>   Group "miscParserTests"
+>   [Group "multiple statements"
+>    [s "select 1;\nselect 2;"
+>     [QueryStatement ea $ makeSelect {selSelectList = sl [si $ num "1"]}
+>     ,QueryStatement ea $ makeSelect {selSelectList = sl [si $ num "2"]}]
+>    ]
+>   ,Group "comments"
+>    [s "" []
+>    ,s "-- this is a test" []
+>    ,s "/* this is\n\
+>       \a test*/" []
+>    ,s "select 1;\n\
+>       \-- this is a test\n\
+>       \select -- this is a test\n\
+>       \2;"
+>     [QueryStatement ea $ makeSelect {selSelectList = sl [si $ num "1"]}
+>     ,QueryStatement ea $ makeSelect {selSelectList = sl [si $ num "2"]}]
+>    ,s "select 1;\n\
+>       \/* this is\n\
+>       \a test*/\n\
+>       \select /* this is a test*/2;"
+>     [QueryStatement ea $ makeSelect {selSelectList = sl [si $ num "1"]}
+>     ,QueryStatement ea $ makeSelect {selSelectList = sl [si $ num "2"]}]
+>    ]
+
+--------------------------------------------------------------------------------
+
+ddl statements
+
+
+>    ,Group "misc"
+>     [s "SET search_path TO my_schema, public;"
+>      [Set ea "search_path" [SetId ea "my_schema"
+>                            ,SetId ea "public"]]
+>     ,s "SET t1 = 3;"
+>      [Set ea "t1" [SetNum ea 3]]
+>     ,s "SET t1 = 'stuff';"
+>      [Set ea "t1" [SetStr ea "stuff"]]
+>     ,s "create language plpgsql;"
+>      [CreateLanguage ea "plpgsql"]
+>     ]
+>    ]
+>  where
+>    s = ParseStmts defaultParseFlags
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/MiscDdl.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/MiscDdl.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/MiscDdl.lhs
@@ -0,0 +1,114 @@
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.Parsing.MiscDdl (miscDdl) where
+>
+> import Database.HsSqlPpp.Syntax
+
+> import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+
+> miscDdl:: Item
+> miscDdl =
+>   Group "misc ddl" [
+>     Group "misc create/alter" [
+>       s "create database dbname;"
+>       [CreateDatabase ea (name "dbname")]
+>      ,s "alter database dbname rename to otherdb;"
+>       [AlterDatabase ea (name "dbname") (RenameDatabase ea (name "otherdb"))]
+>      ,s "create view v1 as\n\
+>         \select a,b from t;"
+>       [CreateView ea
+>        (name "v1") Nothing
+>        (makeSelect
+>         {selSelectList = sl [si $ ei "a"
+>                             ,si $ ei "b"]
+>         ,selTref = [tref "t"]})]
+>      ,s "alter view v1 as\n\
+>         \select a,b from t;"
+>       [AlterView ea
+>        (name "v1") Nothing
+>        (makeSelect
+>         {selSelectList = sl [si $ ei "a"
+>                             ,si $ ei "b"]
+>         ,selTref = [tref "t"]})]
+>      ,s "create view v1(c,d) as\n\
+>         \select a,b from t;"
+>       [CreateView ea
+>        (name "v1") (Just [Nmc "c",Nmc "d"])
+>        (makeSelect
+>         {selSelectList = sl [si $ ei "a"
+>                             ,si $ ei "b"]
+>         ,selTref = [tref "t"]})]
+>      ,s "alter view v1(c,d) as\n\
+>         \select a,b from t;"
+>       [AlterView ea
+>        (name "v1") (Just [Nmc "c",Nmc "d"])
+>        (makeSelect
+>         {selSelectList = sl [si $ ei "a"
+>                             ,si $ ei "b"]
+>         ,selTref = [tref "t"]})]
+>      ,s "create domain td as text check (value in ('t1', 't2'));"
+>       [CreateDomain ea (name "td") (st "text") ""
+>        (Just (InPredicate ea (ei "value") True
+>               (InList ea [stringQ "t1" ,stringQ "t2"])))]
+>      ,s "create type tp1 as (\n\
+>         \  f1 text,\n\
+>         \  f2 text\n\
+>         \);"
+>       [CreateType ea (name "tp1") [TypeAttDef ea (Nmc "f1") (st "text")
+>                                  ,TypeAttDef ea (Nmc "f2") (st "text")]]
+>
+>      ,s "create sequence s start with 5 increment by 4 no maxvalue no minvalue cache 1;"
+>         [CreateSequence ea (name "s") 4 Nothing Nothing 5 1]
+>
+>      ,s "alter sequence s owned by a.b;"
+>         [AlterSequence ea (name "s") $ AlterSequenceOwned ea $ qn "a" "b"]
+>      ,s "alter sequence s rename to s2;"
+>         [AlterSequence ea (name "s") $ AlterSequenceRename ea $ name "s2"]
+>      ,s "alter sequence s increment by 2 start with 3;"
+>         [AlterSequence ea (name "s") $ AlterSequenceActions ea
+>                                      $ [AlterSequenceIncrement ea 2,AlterSequenceStart ea 3]]
+>      ,s "alter sequence s no maxvalue minvalue 1;"
+>         [AlterSequence ea (name "s") $ AlterSequenceActions ea
+>                                      $ [AlterSequenceMax ea Nothing,AlterSequenceMin ea $ Just 1]]
+>      ,s "alter sequence s cache 2;"
+>         [AlterSequence ea (name "s") $ AlterSequenceActions ea [AlterSequenceCache ea 2]]
+>      ,s "alter sequence s restart;"
+>         [AlterSequence ea (name "s") $ AlterSequenceActions ea [AlterSequenceRestart ea Nothing]]
+>      ,s "alter sequence s restart with 1;"
+>         [AlterSequence ea (name "s") $ AlterSequenceActions ea [AlterSequenceRestart ea $ Just 1]]
+>
+>      ,s "create trigger tr\n\
+>          \after insert or delete on tb\n\
+>          \for each statement\n\
+>          \execute procedure fb();"
+>         [CreateTrigger ea (Nmc "tr") TriggerAfter [TInsert,TDelete]
+>          (name "tb") EachStatement (name "fb") []]
+>      ,s "drop trigger\n\
+>          \if exists tr\n\
+>          \on tb cascade;"
+>	      [DropTrigger ea IfExists (Nmc "tr") (name "tb") Cascade] 
+>      ,s "drop trigger tr\n\
+>          \on tb restrict;"
+>	      [DropTrigger ea Require (Nmc "tr") (name "tb") Restrict] 
+>      ]
+>
+>     ,Group "drops" [
+>       s "drop domain t;"
+>       [DropSomething ea Domain Require [name "t"] Restrict]
+>      ,s "drop domain if exists t,u cascade;"
+>       [DropSomething ea Domain IfExists [name "t", name "u"] Cascade]
+>      ,s "drop domain t restrict;"
+>       [DropSomething ea Domain Require [name "t"] Restrict]
+>
+>      ,s "drop type t;"
+>       [DropSomething ea Type Require [name "t"] Restrict]
+>      ,s "drop table t;"
+>       [DropSomething ea Table Require [name "t"] Restrict]
+>      ,s "drop view t;"
+>       [DropSomething ea View Require [name "t"] Restrict]
+>      ,s "drop database dbname;"
+>       [DropSomething ea Database Require [name "dbname"] Restrict]
+>      ]]
+>  where
+>    s = ParseStmts defaultParseFlags
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/MiscQueryExprs.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/MiscQueryExprs.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/MiscQueryExprs.lhs
@@ -0,0 +1,91 @@
+
+
+> {-# LANGUAGE QuasiQuotes,OverloadedStrings #-}
+>
+> module Database.HsSqlPpp.Tests.Parsing.MiscQueryExprs (miscQueryExprs) where
+>
+> --import Database.HsSqlPpp.Utils.Here
+>
+> import Database.HsSqlPpp.Syntax
+> import Database.HsSqlPpp.Dialect
+
+> import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+
+> miscQueryExprs:: Item
+> miscQueryExprs =
+>    Group "misc select statements"
+>    [s "select 1;"
+>     $ makeSelect {selSelectList = sl [si $ num "1"]}
+>    ,s "select a from t;" $ tblat
+>    ,s "select distinct a from t;" $ tblat {selDistinct = Distinct}
+>    ,s "select a from t where b=2;"
+>       $ tblat {selWhere = Just $ binop "=" (ei "b") (num "2")}
+>    ,s "select a from t where b=2 and c=3;"
+>       $ tblat {selWhere = Just $ binop "and"
+>                           (binop "=" (ei "b") (num "2"))
+>                           (binop "=" (ei "c") (num "3"))}
+>    ,s "SELECT T.A::INT FROM TBL AS T;"
+>     $ makeSelect
+>      {selSelectList = sl [si $ Cast ea (eqi "T" "A")
+>                                  (st "INT")]
+>      ,selTref = [trefa "TBL" "T"]}
+>    ,s "select a from t order by a;"
+>     $ tblat {selOrderBy = [(ei "a",Asc, NullsDefault)]}
+>    ,s "select a from t order by a asc;"
+>     $ tblat {selOrderBy = [(ei "a",Asc, NullsDefault)]}
+>    ,s "select a from t order by a desc;"
+>     $ tblat {selOrderBy = [(ei "a",Desc, NullsDefault)]}
+>    ,s "select a from t order by a,b;"
+>     $ tblat {selOrderBy = [(ei "a",Asc, NullsDefault)
+>                           ,(ei "b",Asc, NullsDefault)]}
+>    ,s "select a from t order by a asc,b;"
+>     $ tblat {selOrderBy = [(ei "a",Asc, NullsDefault)
+>                           ,(ei "b",Asc, NullsDefault)]}
+>    ,s "select a from t order by a desc,b;"
+>     $ tblat {selOrderBy = [(ei "a",Desc, NullsDefault)
+>                           ,(ei "b",Asc, NullsDefault)]}
+>    ,s "select a from t order by a desc,b desc;"
+>     $ tblat {selOrderBy = [(ei "a",Desc, NullsDefault)
+>                           ,(ei "b",Desc, NullsDefault)]}
+>    ,s "select a from t order by a nulls first;"
+>     $ tblat {selOrderBy = [(ei "a",Asc, NullsFirst)]}
+>    ,s "select a from t order by a nulls last;"
+>     $ tblat {selOrderBy = [(ei "a",Asc, NullsLast)]}
+>    ,s "select a from t order by a asc nulls first;"
+>     $ tblat {selOrderBy = [(ei "a",Asc, NullsFirst)]}
+>    ,s "select a from t order by a asc nulls last;"
+>     $ tblat {selOrderBy = [(ei "a",Asc, NullsLast)]}
+>    ,s "select a from t order by a desc nulls first;"
+>     $ tblat {selOrderBy = [(ei "a",Desc, NullsFirst)]}
+>    ,s "select a from t order by a desc nulls last;"
+>     $ tblat {selOrderBy = [(ei "a",Desc, NullsLast)]}
+>    ,s "select a from t limit 1;"
+>     $ tblat {selLimit = Just $ num "1"}
+>    ,s "select a from t offset 1;"
+>     $ tblat {selOffset = Just $ num "1"}
+>    ,s "select a from t order by a limit 1 offset 1;"
+>     $ tblat {selOrderBy = [(ei "a",Asc, NullsDefault)]
+>             ,selLimit = Just $ num "1"
+>             ,selOffset = Just $ num "1"}
+>    ,s "select (p).x, (p).y from pos;"
+>           $ makeSelect
+>                   {selSelectList = sl [si $ parenQual (ei "p") (ei "x")
+>                                       ,si $ parenQual (ei "p") (ei "y")]
+>                   ,selTref = [tref "pos"]}
+>    ,s "select ($1).x, ($1).y from pos;"
+>           $ makeSelect
+>                   {selSelectList = sl
+>                    [si $ member (Parens ea $ PositionalArg ea 1) (ei "x")
+>                    ,si $ member (Parens ea $ PositionalArg ea 1) (ei "y")]
+>                   ,selTref = [tref "pos"]}
+>   ,s "select right ('test string',5) from t;"
+>      $ makeSelect
+>            {selSelectList = sl [si $ App ea (name "right") [stringQ "test string",num "5"]]
+>            ,selTref = [tref "t"]}
+>    ]
+>  where
+>    s = ParseQueryExpr defaultParseFlags {pfDialect = postgresDialect}
+>    tblat = makeSelect
+>            {selSelectList = sl [si $ ei "a"]
+>            ,selTref = [tref "t"]}
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/OdbcParsing.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/OdbcParsing.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/OdbcParsing.lhs
@@ -0,0 +1,178 @@
+
+Odbc comes with some small 'extensions' to sql syntax. The basic idea
+is to wrap a few places in SQL where you write ansi standard sql, and
+delimit it with a {} pair, and then some simple parser in the odbc
+driver can convert this into the dialect specific sql for your
+non-ansi-sql supporting product circa 1989. In this way, you can
+achieve a little bit of SQL DBMS dialect independence.
+
+I think it is sensible to support the odbc syntax directly in your
+main SQL parser instead of in the driver, so here it is.
+
+Summary of ODBC syntax extensions:
+
+Here is microsoft's docs which are OK:
+
+https://msdn.microsoft.com/en-us/library/ms715364(v=vs.85).aspx
+
+1. date, time, and timestamp literals
+2. scalar function calls
+3. escapes for like strings
+4. outer joins
+5. calling a procedure
+
+= date, time and timestamp literals
+
+These abstract out the particular formats (because everyone has to put
+the years and months in different places, and use slashes or dashes or
+dots or whatever).
+
+{d 'yyyy-mm-dd'}
+{t 'HH:MM:ss[.f...]}
+{ts 'yyyy-mm-dd HH:MM:ss[.f...]'}
+
+The point of this is to have a fixed format for dates/times which the
+vendor specific driver vendor can convert into the format expected by
+the vendor's sql dbms.
+
+One thing that isn't clear to me is is whitespace allowed between {
+and d, or ' and } for instance, and is different whitespace other than
+a single space between the d and the ' for instance allowed?
+
+= scalar function calls
+
+{fn scalar-function-call}
+
+e.g.
+{fn curdate())}
+
+Note: these can nest, e.g.:
+
+INSERT INTO Orders (OrderID, CustID, OpenDate, SalesPerson, Status)
+   VALUES (?, ?, {fn CONVERT({fn CURDATE()}, SQL_DATE)}, ?, ?)
+
+The purpose of these is to take the ansi standard functions, and sql
+server/access functions, and the extract operator, which isn't quite a
+normal function, and then allow the driver to convert the function
+names and arguments into the database specific alternative (e.g. with
+a different function name, or the argument order changed).
+
+= escape for a like string
+
+this is the ansi standard:
+
+[ NOT ] LIKE <character pattern> [ ESCAPE <escape character> ]
+
+The odbc syntax to abstract this is:
+
+[ NOT ] LIKE <character pattern> {escape 'escape-character'}
+
+e.g.
+like '[[' {escape '['}
+->
+like '[[' escape [
+
+This isn't currently supported in hssqlppp.
+
+= outer join
+
+This is basically a weird wrapper which allows the driver to replace
+'ansi' outer join syntax with the old oracle outer join syntax if this
+is what the sql dbms supports. You write something like:
+
+select * from {oj t1 left outer join t1 on t1.a = t2.b}
+
+and then in theory, an older dbms which doesn't support this syntax
+can conver this to:
+
+select * from t1,t2 where t1.a(+) = t2.b
+
+I may have got the (+) in the wrong place. In hssqlppp, the {oj ... }
+is treated like trefparens:
+
+select * from {oj t1 left outer join t1 on t1.a = t2.b}
+is basically the same as
+select * from (t1 left outer join t1 on t1.a = t2.b)
+
+= calling a procedure
+
+{[?=]call procedure-name[([parameter][,[parameter]]...)]}
+
+this isn't currently supported in hssqlppp.
+
+There is additional stuff in the typechecking, see the odbc
+typechecking tests for more info. The type checker doesn't test the
+date/time literals inside the literal like other literals in hssqlppp,
+and these are treated as sugar, and oj does nothing, but there is a
+bit of work to deal with the functions.
+
+The odbc syntax is currently available in all dialects.
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.Parsing.OdbcParsing (odbcParsing) where
+>
+> import Database.HsSqlPpp.Syntax
+
+> import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+> import Database.HsSqlPpp.Dialect
+
+> odbcParsing:: Item
+> odbcParsing =
+>    Group "odbcParsing" [
+>        Group "datetime" [
+>            e "{d '2000-01-01'}" (OdbcLiteral ea OLDate "2000-01-01")
+>           ,e "{t '12:00:01.1'}" (OdbcLiteral ea OLTime "12:00:01.1")
+>           ,e "{ts '2000-01-01 12:00:01.1'}"
+>                (OdbcLiteral ea OLTimestamp "2000-01-01 12:00:01.1")
+>        ]
+>        ,Group "functions" [
+>              e "{fn CHARACTER_LENGTH(string_exp)}"
+>              $ OdbcFunc ea (App ea (name "CHARACTER_LENGTH")
+>                                    [ei "string_exp"])
+>             ,e "{fn EXTRACT(year from my_date)}"
+>              $ OdbcFunc ea (Extract ea ExtractYear $ ei "my_date")
+>             ,e "{fn now()}"
+>              $ OdbcFunc ea (App ea (name "now") [])
+>             ,e "{fn CONVERT('2000-01-01', SQL_DATE)}"
+>              $ OdbcFunc ea (App ea (name "CONVERT")
+>               [StringLit ea "2000-01-01"
+>               ,ei "SQL_DATE"])
+>             ,e "{fn CONVERT({fn CURDATE()}, SQL_DATE)}"
+>              $ OdbcFunc ea (App ea (name "CONVERT")
+>               [OdbcFunc ea (App ea (name "CURDATE") [])
+>               ,ei "SQL_DATE"])
+>             ]
+>        ,Group "outer join" [
+>              ParseQueryExpr defaultParseFlags
+>              "select * from {oj t1 left outer join t2 on true}"
+>              $ makeSelect
+>             {selSelectList = sl [si $ Star ea]
+>             ,selTref = [OdbcTableRef ea (JoinTref ea (tref "t1") Unnatural LeftOuter Nothing
+>                                          (tref "t2") (Just $ JoinOn ea (BooleanLit ea True)))]}]
+>        ,Group "check parsing bugs" [
+>              ParseQueryExpr defaultParseFlags
+>              "select {fn CONVERT(cint,SQL_BIGINT)} from t;"
+>              $ makeSelect
+>             {selSelectList = sl [si $ OdbcFunc ea (App ea (name "CONVERT")
+>                                                            [ei "cint"
+>                                                            ,ei "SQL_BIGINT"])]
+>             ,selTref = [tref "t"]}]
+>        ,Group "outer join" [
+>              tsql "select * from {oj t1 left outer join t2 on true}"
+>              [QueryStatement ea $ makeSelect
+>             {selSelectList = sl [si $ Star ea]
+>             ,selTref = [OdbcTableRef ea (JoinTref ea (tref "t1") Unnatural LeftOuter Nothing
+>                                          (tref "t2") (Just $ JoinOn ea (BooleanLit ea True)))]}]]
+>        ,Group "check parsing bugs" [
+>              tsql "select {fn CONVERT(cint,SQL_BIGINT)} from t;"
+>              [QueryStatement ea $ makeSelect
+>             {selSelectList = sl [si $ OdbcFunc ea (App ea (name "convert")
+>                                                            [ei "cint"
+>                                                            ,ei "SQL_BIGINT"])]
+>             ,selTref = [tref "t"]}]]
+
+>        ]
+>  where
+>    e = ParseScalarExpr defaultParseFlags
+>    tsql = ParseProcSql defaultParseFlags {pfDialect=sqlServerDialect}
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/Oracle.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/Oracle.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/Oracle.lhs
@@ -0,0 +1,45 @@
+
+Tests for oracle syntax variations
+
+> {-# LANGUAGE QuasiQuotes,OverloadedStrings #-}
+>
+> module Database.HsSqlPpp.Tests.Parsing.Oracle (oracle) where
+>
+> --import Database.HsSqlPpp.Utils.Here
+>
+> import Database.HsSqlPpp.Syntax
+
+> import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+> import Database.HsSqlPpp.Dialect
+
+> oracle :: Item
+> oracle =
+>   Group "parse oracle"
+>   [ora "select unique a from t;"
+>       [qs $ makeSelect
+>        {selSelectList = sl [si $ ei "a"]
+>        ,selDistinct = Distinct
+>        ,selTref = [tref "t"]}]
+>   ,ora "select count(unique a) from t;"
+>       [qs $ makeSelect
+>        {selSelectList =
+>            sl [si $ AggregateApp ea Distinct (app "count" [ei "a"]) []]
+>        ,selTref = [tref "t"]}]
+
+TODO: can't turn this into a regular outer join until type checking
+since we need to know where the fields come from, so add a new scalar
+expression syntax which represents a (+) suffix.
+
+>   {-,ora "select a,b from t,u where a=b(+);"
+>    [qs $ makeSelect
+>        {selSelectList = sl [sia (eqi "r" "dn") $ QNmc "rg"]
+>        ,selTref = [tref "tbl"]}]
+>   ,ora "select a,b from t,u where a(+)=b;"
+>    [qs $ makeSelect
+>        {selSelectList = sl [sia (eqi "r" "dn") $ QNmc "rg"]
+>        ,selTref = [tref "tbl"]}]-}
+>   ]
+>   where
+>     qs = QueryStatement ea
+>     ora = ParseStmts defaultParseFlags {pfDialect=oracleDialect}
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/ParserTests.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/ParserTests.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/ParserTests.lhs
@@ -0,0 +1,77 @@
+
+The automated tests, uses hunit to check a bunch of text expressions
+and sql statements parse to the correct tree, and then checks pretty
+printing and then reparsing gives the same tree. The code was mostly
+written almost in tdd style, which the order/ coverage of these tests
+reflects.
+
+There are no tests for invalid syntax at the moment.
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.Parsing.ParserTests
+>     (parserTestData
+>     ,Item(..)
+>     ) where
+>
+> --import Data.Generics
+> --import Control.Monad
+> --import Database.HsSqlPpp.Syntax
+> --import Database.HsSqlPpp.Annotation
+> --import Database.HsSqlPpp.Parse
+> --import Database.HsSqlPpp.Pretty
+> --import Database.HsSqlPpp.Utility
+>
+
+> --import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.Parsing.ScalarExprs
+> import Database.HsSqlPpp.Tests.Parsing.MiscQueryExprs
+> import Database.HsSqlPpp.Tests.Parsing.CombineQueryExprs
+> import Database.HsSqlPpp.Tests.Parsing.SelectLists
+> import Database.HsSqlPpp.Tests.Parsing.TableRefs
+> import Database.HsSqlPpp.Tests.Parsing.Joins
+> import Database.HsSqlPpp.Tests.Parsing.Schemas
+
+> import Database.HsSqlPpp.Tests.Parsing.Dml
+> import Database.HsSqlPpp.Tests.Parsing.Misc
+
+> import Database.HsSqlPpp.Tests.Parsing.CreateTable
+> import Database.HsSqlPpp.Tests.Parsing.MiscDdl
+> import Database.HsSqlPpp.Tests.Parsing.FunctionsDdl
+> import Database.HsSqlPpp.Tests.Parsing.Plpgsql
+
+> import Database.HsSqlPpp.Tests.Parsing.SqlServer
+> import Database.HsSqlPpp.Tests.Parsing.Oracle
+> import Database.HsSqlPpp.Tests.Parsing.LexerTests
+> import Database.HsSqlPpp.Tests.Parsing.OdbcParsing
+
+> --import Control.Applicative
+> import Database.HsSqlPpp.Tests.TestTypes
+
+
+> --import Database.HsSqlPpp.Tests.TestUtils
+> --import Data.Text.Lazy (Text)
+> --import qualified Data.Text as T
+> --import qualified Data.Text.Lazy as L
+
+> parserTestData :: Item
+> parserTestData =
+>   Group "parserTests" [
+>              lexerTests
+>             ,scalarExprs
+>             ,miscQueryExprs
+>             ,combineQueryExprs
+>             ,selectLists
+>             ,tableRefs
+>             ,joins
+>             ,dml
+>             ,Group "ddl" [createTable
+>                          ,miscDdl
+>                          ,functionsDdl]
+>             ,schemas
+>             ,pgplsql
+>             ,misc
+>             ,sqlServer
+>             ,oracle
+>             ,odbcParsing
+>             ]
+
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/Plpgsql.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/Plpgsql.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/Plpgsql.lhs
@@ -0,0 +1,161 @@
+
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.Parsing.Plpgsql (pgplsql) where
+>
+> import Database.HsSqlPpp.Syntax
+
+> import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+> import Database.HsSqlPpp.Dialect
+
+> pgplsql :: Item
+> pgplsql =
+>   Group "plpgsql" [
+>     Group "simple plpgsql statements" [
+>       f "success := true;"
+>       [Assignment ea (name "success") lTrue]
+>      ,f "success = true;"
+>       [Assignment ea (name "success") lTrue]
+>      ,f "return true;"
+>       [Return ea $ Just lTrue]
+>      ,f "return;"
+>       [Return ea Nothing]
+>      ,f "return next 1;"
+>       [ReturnNext ea $ num "1"]
+>      ,f "return query select a from b;"
+>       [ReturnQuery ea $ makeSelect {selSelectList = sl [si $ ei "a"]
+>                                    ,selTref = [tref "b"]}]
+>      ,f "raise notice 'stuff %', 1;"
+>       [Raise ea RNotice "stuff %" [num "1"]]
+>      ,f "perform test();"
+>       [Perform ea $ app "test" []]
+>      ,f "perform test(a,b);"
+>       [Perform ea $ app "test" [ei "a", ei "b"]]
+>      ,f "perform test(r.relvar_name || '_and_stuff');"
+>       [Perform ea $ app "test" [
+>                     binop "||" (eqi "r" "relvar_name")
+>                                (stringQ "_and_stuff")]]
+>      ,f "select into a,b c,d from e;"
+>       [Into ea False [name "a", name "b"]
+>        $ QueryStatement ea
+>        $ makeSelect {selSelectList = sl [si $ ei "c", si $ ei "d"]
+>                     ,selTref = [tref "e"]}]
+>      ,f "select c,d into a,b from e;"
+>       [Into ea False [name "a", name "b"]
+>        $ QueryStatement ea
+>        $ makeSelect {selSelectList = sl [si $ ei "c", si $ ei "d"]
+>                     ,selTref = [tref "e"]}]
+>      ,f "delete from pieces where x = 1 and y = 1 returning tag into r.tag;"
+>       [Into ea False [qn "r" "tag"]
+>        $ Delete ea (name "pieces") []
+>          (Just $ binop "and" (binop "=" (ei "x") (num "1"))
+>                               (binop "=" (ei "y") (num "1")))
+>          (Just $ sl [si $ ei "tag"])]
+>      ,f "update pieces\n\
+>         \set a=b returning tag into r.tag;"
+>       [Into ea False [qn "r" "tag"]
+>          $ Update ea (name "pieces")
+>                [SetClause ea (Nmc "a") $ ei "b"]
+>                []
+>                Nothing
+>                (Just $ sl $ [si $ ei "tag"])]
+>      ,f "insert into t(a) values (1) returning id into x;"
+>       [Into ea False [Name ea [Nmc "x"]]
+>        $ Insert ea
+>         (name "t")
+>         [Nmc "a"]
+>         (Values ea [[num "1"]])
+>         (Just $ sl [si $ ei "id"])]
+
+>      ,f "update t\n\
+>         \  set x = 1 returning id into z;"
+>       [Into ea False [Name ea [Nmc "z"]]
+>       $ Update ea (name "t") [SetClause ea (Nmc "x") $ num "1"]
+>         [] Nothing (Just $ sl [si $ ei "id"])]
+
+>      ,f "execute s;"
+>       [Execute ea (ei "s")]
+>      ,f "execute s into r;"
+>       [Into ea False [Name ea [Nmc "r"]] (Execute ea (ei "s"))]
+>     ,f "continue;" [ContinueStatement ea Nothing]
+>     ]
+>
+>     ,Group "other plpgsql statements" [
+>       f "for r in select a from tbl loop\n\
+>         \null;\n\
+>         \end loop;"
+>       [ForQueryStatement ea Nothing (Nmc "r")
+>        (makeSelect {selSelectList = sl [si $ ei "a"]
+>                    ,selTref = [tref "tbl"]})
+>        [NullStatement ea]]
+>      ,f "for r in select a from tbl where true loop\n\
+>         \null;\n\
+>         \end loop;"
+>       [ForQueryStatement ea Nothing (Nmc "r")
+>        (makeSelect {selSelectList = sl [si $ ei "a"]
+>                    ,selTref = [tref "tbl"]
+>                    ,selWhere = Just lTrue})
+>        [NullStatement ea]]
+>      ,f "for r in 1 .. 10 loop\n\
+>         \null;\n\
+>         \end loop;"
+>       [ForIntegerStatement ea Nothing (Nmc "r")
+>        (num "1") (num "10")
+>        [NullStatement ea]]
+>       -- catch a bug in lexing where 1..10 is parsed as
+>       -- num "1.", num ".10", instead of num 1, symbol "..", num 10
+>      ,f "for r in 1..10 loop\n\
+>         \null;\n\
+>         \end loop;"
+>       [ForIntegerStatement ea Nothing (Nmc "r")
+>        (num "1") (num "10")
+>        [NullStatement ea]]
+>
+>      ,f "if a=b then\n\
+>         \  update c set d = e;\n\
+>         \end if;"
+>       [If ea [(binop "=" (ei "a") (ei "b")
+>               ,[Update ea (name "c") [SetClause ea (Nmc "d")
+>                                      $ ei "e"] [] Nothing Nothing])]
+>        []]
+>      ,f "if true then\n\
+>         \  null;\n\
+>         \else\n\
+>         \  null;\n\
+>         \end if;"
+>       [If ea [(lTrue,[NullStatement ea])]
+>        [NullStatement ea]]
+>      ,f "if true then\n\
+>         \  null;\n\
+>         \elseif false then\n\
+>         \  return;\n\
+>         \end if;"
+>       [If ea [(lTrue, [NullStatement ea])
+>              ,(lFalse, [Return ea Nothing])]
+>        []]
+>      ,f "if true then\n\
+>         \  null;\n\
+>         \elseif false then\n\
+>         \  return;\n\
+>         \elsif false then\n\
+>         \  return;\n\
+>         \else\n\
+>         \  return;\n\
+>         \end if;"
+>       [If ea [(lTrue, [NullStatement ea])
+>              ,(lFalse, [Return ea Nothing])
+>              ,(lFalse, [Return ea Nothing])]
+>        [Return ea Nothing]]
+>      ,f "case a\n\
+>         \  when b then null;\n\
+>         \  when c,d then null;\n\
+>         \  else null;\n\
+>         \end case;"
+>      [CaseStatementSimple ea (ei "a")
+>       [([ei "b"], [NullStatement ea])
+>       ,([ei "c", ei "d"], [NullStatement ea])]
+>       [NullStatement ea]]
+>     ]]
+>  where
+>    f = ParseProcSql defaultParseFlags {pfDialect=postgresDialect}
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/ScalarExprs.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/ScalarExprs.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/ScalarExprs.lhs
@@ -0,0 +1,262 @@
+
+> {-# LANGUAGE QuasiQuotes,OverloadedStrings #-}
+>
+> module Database.HsSqlPpp.Tests.Parsing.ScalarExprs (scalarExprs) where
+>
+> import Database.HsSqlPpp.Utils.Here
+>
+> import Database.HsSqlPpp.Syntax
+> import Database.HsSqlPpp.Dialect
+
+> import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+
+> scalarExprs:: Item
+> scalarExprs =
+>    Group "parse expressions" [
+>     Group "numbers" [
+>       e "42" (num "42")
+>      ,e "3.5" (num "3.5")
+>      ,e "4." (num "4.")
+>      ,e ".001" (num ".001")
+>      ,e "5e2" (num "5e2")
+>      ,e "1.925e-3" (num "1.925e-3")
+
+>      ]
+>    ,Group "basic expressions" [
+>       e "1" (num "1")
+>      ,e "-1" (prefop "-" $ num "1")
+>      ,e "1.1" (num "1.1")
+>      ,e "-1.1" (prefop "-" $ num "1.1")
+>      ,e " 1 + 1 " (binop "+" (num "1")
+>                              (num "1"))
+>      ,e "1+1+1" (binop "+" (binop "+" (num "1")
+>                                       (num "1"))
+>                            (num "1"))
+>      ]
+>    ,Group "parens" [
+
+check some basic parens use wrt naked values and row constructors
+these tests reflect how pg seems to interpret the variants.
+
+>       e "(1)" (Parens ea (num "1"))
+>      ,e "row ()" (specop "rowctor" [])
+>      ,e "row (1)" (specop "rowctor" [num "1"])
+>      ,e "row (1,2)" (specop "rowctor" [num "1",num "2"])
+>      ,e "(1,2)" (specop "rowctor" [num "1",num "2"])
+>      ]
+>    ,Group "more basic expressions" [
+
+test some more really basic expressions
+
+>       e "'test'" (stringQ "test")
+>      ,e "''" (stringQ "")
+>      ,e "hello" (ei "hello")
+>      ,e "helloTest" (ei "helloTest")
+>      ,e "hello_test" (ei "hello_test")
+>      ,e "\"this is an identifier\""
+>             (Identifier ea (Name ea [QNmc "this is an identifier"]))
+>      ,e "hello1234" (ei "hello1234")
+>      ,e "true" lTrue
+>      ,e "false" lFalse
+>      ,e "null" lNull
+>      ]
+>    ,Group "array ctor and selector" [
+>       e "array[1,2]" (specop "arrayctor" [num "1", num "2"])
+>      ,e "a[1]" (specop "arraysub" [ei "a", num "1"])
+>      ]
+>    ,Group "simple operators" [
+>       e "1 + tst1" (binop "+" (num "1")
+>                               (ei "tst1"))
+>      ,e "tst1 + 1" (binop "+" (ei "tst1")
+>                               (num "1"))
+>      ,e "tst + tst1" (binop "+" (ei "tst")
+>                                 (ei "tst1"))
+>      ,e "'a' || 'b'" (binop "||" (stringQ "a")
+>                                  (stringQ "b"))
+>      ,e "tst | tst1" (binop "|" (ei "tst")
+>                                 (ei "tst1"))
+>      ,e "tst & tst1" (binop "&" (ei "tst")
+>                                 (ei "tst1"))
+>      ,e "tst # tst1" (binop "#" (ei "tst")
+>                                 (ei "tst1"))
+>      ,e "tst << tst1" (binop "<<" (ei "tst")
+>                                   (ei "tst1"))
+>      ,e "tst >> tst1" (binop ">>" (ei "tst")
+>                                   (ei "tst1"))
+>      ,e "~tst" (prefop "~" (ei "tst"))
+>      ,e "~tst + tst1" (prefop "~" $ binop "+" (ei "tst")
+>                                               (ei "tst1"))
+>      ,e "2 + 1 << 3" (binop "<<" (binop "+" (num "2") (num "1"))
+>                                  (num "3"))
+>      ,e "'stuff'::text"
+>       (Cast ea (stringQ "stuff") (st "text"))
+>      ,e "245::float(24)" (Cast ea (num "245") (PrecTypeName ea (name "float") 24))
+>      ,e "245.1::numeric(5,3)"
+>       (Cast ea (num "245.1") (Prec2TypeName ea (name "numeric") 5 3))
+>      ,e "245::double precision"
+>       (Cast ea (num "245") (st "double precision"))
+>      ,e "'test'::character varying(6)"
+>       (Cast ea (StringLit ea "test") (PrecTypeName ea (name "character varying") 6))
+>      ,e "date '1998-12-01'"
+>       (TypedStringLit ea (st "date") "1998-12-01")
+>      ,e "interval '63' day" (Interval ea "63" IntervalDay Nothing)
+>      ,e "interval '63' day (3)" (Interval ea "63" IntervalDay $ Just 3)
+>      ,e "interval '63' minute" (Interval ea "63" IntervalMinute Nothing)
+>      ,e "EXTRACT(year from a)" (Extract ea ExtractYear $ ei "a")
+>      ,e "a between 1 and 3"
+>         (specop "between" [ei "a", num "1", num "3"])
+>      ,e "a between 7 - 1 and 7 + 1"
+>         (specop "between" [ei "a"
+>                            ,binop "-" (num "7")
+>                                       (num "1")
+>                            ,binop "+" (num "7")
+>                                       (num "1")])
+>      ,e "cast(a as text)"
+>         (Cast ea (ei "a") (st "text"))
+>      ,e "@ a"
+>         (prefop "@" (ei "a"))
+>      ,e "substring(a from 0 for 3)"
+>         (specop "substring" [ei "a", num "0", num "3"])
+>      ,e "substring(a from 0 for (5 - 3))"
+>         (specop "substring" [ei "a"
+>                              ,num "0"
+>                              ,Parens ea (binop "-" (num "5") (num "3"))])
+>      ,e "substring(a,b,c)"
+>         (app "substring" [ei "a"
+>                          ,ei "b"
+>                          ,ei "c"])
+>      ,e "a like b"
+>         (binop "like" (ei "a") (ei "b"))
+>      ,e "a rlike b"
+>         (binop "rlike" (ei "a") (ei "b"))
+>      ,e "a not like b"
+>         (binop "notlike" (ei "a") (ei "b"))
+>      , e "a and b and c and d"
+>         (binop "and"
+>          (binop "and"
+>           (binop "and" (ei "a")
+>                         (ei "b"))
+>           (ei "c"))
+>          (ei "d"))
+>      ]
+>    ,Group "function calls" [
+>       e "fn()" (app "fn" [])
+>      ,e "fn(1)" (app "fn" [num "1"])
+>      ,e "fn('test')" (app "fn" [stringQ "test"])
+>      ,e "fn(1,'test')" (app "fn" [num "1", stringQ "test"])
+>      ,e "fn('test')" (app "fn" [stringQ "test"])
+>         --- qualified names, check that the . is binding
+>         -- more tightly than the ()
+>      ,e "g.f()" $ (App ea (Name ea [Nmc "g", Nmc "f"]) [])
+>      ,e "h.g.f()" (App ea (Name ea [Nmc "h", Nmc "g", Nmc "f"]) [])
+>      ]
+>    ,Group "simple whitespace sanity checks" [
+>       e "fn (1)" (app "fn" [num "1"])
+>      ,e "fn( 1)" (app "fn" [num "1"])
+>      ,e "fn(1 )" (app "fn" [num "1"])
+>      ,e "fn(1) " (app "fn" [num "1"])
+>      ]
+>    ,Group "null stuff" [
+>       e "not null" (prefop "not" lNull)
+>      ,e "a is null" (postop "isnull" (ei "a"))
+>      ,e "a is not null" (postop "isnotnull" (ei "a"))
+>      ,e "not not true" (prefop "not" $ prefop "not" lTrue)
+>      ]
+
+>    ,Group "case expressions" [
+>       e [here|
+>          case when a,b then 3
+>               when c then 4
+>               else 5
+>          end
+>          |]
+>         (Case ea [([ei "a", ei "b"], num "3")
+>                  ,([ei "c"], num "4")]
+>          (Just $ num "5"))
+>      ,e  "case 1 when 2 then 3 else 4 end"
+>         (CaseSimple ea (num "1")
+>          [([num "2"], num "3")]
+>          (Just $ num "4"))
+>      ]
+>    ,Group "positional args" [
+>       e "$1" (PositionalArg ea 1)
+>      ,e "?" (Placeholder ea)
+>      ,e "a = ?" (binop "=" (ei "a") (Placeholder ea))
+>      ]
+>    ,Group "exists" [
+>       e "exists (select 1 from a)"
+>       (Exists ea (makeSelect
+>                   {selSelectList = sl [si $ num "1"]
+>                   ,selTref = [tref "a"]}))
+
+selectFrom [SelExp ea (num "1")]
+                   (Tref ea (i "a") (NoAlias ea))))
+
+>      ]
+>    ,Group "in variants" [
+>       e "t in (1,2)"
+>       (InPredicate ea (ei "t") True (InList ea [num "1",num "2"]))
+>      ,e "t not in (1,2)"
+>       (InPredicate ea (ei "t") False (InList ea [num "1",num "2"]))
+>      ,e "(t,u) in (1,2)"
+>       (InPredicate ea (specop "rowctor" [ei "t",ei "u"]) True
+>        (InList ea [num "1",num "2"]))
+>      ,e "3 = any (array[1,2])"
+>       (LiftApp ea (name "=")
+>        LiftAny [num "3"
+>                ,specop "arrayctor" [num "1"
+>                                     ,num "2"]])
+>      ,e "3 = all (array[1,2,4])"
+>       (LiftApp ea (name "=")
+>        LiftAll [num "3"
+>                ,specop "arrayctor" [num "1"
+>                                     ,num "2"
+>                                     ,num "4"]])
+>      ]
+>    ,Group "comparison operators" [
+>       e "a < b"
+>       (binop "<" (ei "a") (ei "b"))
+>      ,e "a <> b"
+>       (binop "<>" (ei "a") (ei "b"))
+>      ,e "a != b"
+>       (binop "<>" (ei "a") (ei "b"))
+>      ]
+
+test some string parsing, want to check single quote behaviour,
+and dollar quoting, including nesting.
+
+>    ,Group "string parsing" [
+>       e "''" (stringQ "")
+>      ,e "''''" (stringQ "'")
+>      ,e "'test'''" (stringQ "test'")
+>      ,e "'''test'" (stringQ "'test")
+>      ,e "'te''st'" (stringQ "te'st")
+>      ,e "$$test$$" (str "test")
+>      ,e "$$te'st$$" (str "te'st")
+>      ,e "$st$test$st$" (str "test")
+>      ,e "$outer$te$$yup$$st$outer$" (str "te$$yup$$st")
+>      ,e "'spl$$it'" (stringQ "spl$$it")
+>      ]
+>    ,Group "bracketed things" [
+>       e "(p).x" $ parenQual (ei "p") (ei "x")
+>      ,e "(select f(((a).x, y)::z))"
+>         (ScalarSubQuery ea
+>          (makeSelect
+>           {selSelectList =
+>             sl [si $ app "f" [Cast ea
+>                               (specop "rowctor"
+>                                [parenQual (ei "a") (ei "x")
+>                                ,ei "y"])
+>                               (st "z")]]}))
+>      ]
+>    ,Group "tricky operator parsing" [
+>       e "2 <>-1"
+>         $ binop "<>" (num "2") (prefop "-" (num "1"))
+>      ,e "a <-> b"
+>         $ binop "<->" (ei "a") (ei "b")
+>    ]
+
+>      ]
+>  where
+>    e = ParseScalarExpr defaultParseFlags {pfDialect=postgresDialect}
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/Schemas.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/Schemas.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/Schemas.lhs
@@ -0,0 +1,91 @@
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.Parsing.Schemas (schemas) where
+
+> import qualified Data.Text as T
+
+> import Database.HsSqlPpp.Syntax
+
+> import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+
+> schemas :: Item
+> schemas =
+>   Group "schema" [
+>      Group "ddl - schemas" [
+>       s "create schema test;"
+>       [CreateSchema ea
+>        (Nmc "test")
+>        Nothing]
+>      ,s "create schema test authorization owner;"
+>       [CreateSchema ea
+>        (Nmc "test")
+>        (Just $ name "owner")
+>      ]
+>     ,Group "drop schema" [ 
+>       s "drop schema test;"
+>       [DropSomething ea Schema Require [name "test"] Restrict]
+>      ,s "drop schema if exists test restrict;"
+>       [DropSomething ea Schema IfExists [name "test"] Restrict]
+>      ,s "drop schema test cascade;"
+>       [DropSomething ea Schema Require [name "test"] Cascade]
+>      ]
+
+>     ,Group "alter schema" [ 
+>       s "alter schema test rename to test2;"
+>       [AlterSchema ea (Nmc "test") $ AlterSchemaName ea (Nmc "test2")]
+>       ,s "alter schema test owner to new_owner;"
+>       [AlterSchema ea (Nmc "test") $ AlterSchemaOwner ea (name "new_owner")]
+>      ]
+>     ]
+>     ,Group "ddl - schema-explicit tables" [
+>       s "create table s.test (\n\
+>        \  fielda text,\n\
+>        \  fieldb int\n\
+>        \);"
+>       [CreateTable ea
+>        (nameWithSchema "s" "test")
+>        [att "fielda" "text"
+>        ,att "fieldb" "int"
+>        ]
+>        []
+>        Nothing
+>        NoReplace]
+>      ,s "alter table s.a rename to b;"
+>       [AlterTable ea (nameWithSchema "s" "a") $ RenameTable ea (name "b")]
+>      ,s "drop table s.t;"
+>       [DropSomething ea Table Require [nameWithSchema "s" "t"] Restrict]
+>     ]
+>     ,Group "ddl - schema-explicit views" [
+>       s "create view s1.v1 as\n\
+>        \select a,b from s2.t;"
+>       [CreateView ea
+>       (nameWithSchema "s1" "v1") Nothing
+>       (makeSelect
+>        {selSelectList = sl [si $ ei "a"
+>                            ,si $ ei "b"]
+>        ,selTref = [trefWithSchema "s2" "t"]})]
+>      ,s "alter view s1.v1 as\n\
+>         \select a,b from s2.t;"
+>        [AlterView ea
+>        (nameWithSchema "s1" "v1") Nothing
+>        (makeSelect
+>         {selSelectList = sl [si $ ei "a"
+>                             ,si $ ei "b"]
+>         ,selTref = [trefWithSchema "s2" "t"]})]
+>      ,s "drop view s.v;"
+>       [DropSomething ea View Require [nameWithSchema "s" "v"] Restrict]
+>    ]
+>     ,Group "dml - schemas" [
+>       q "select a from s.t" stbl{selTref = [trefWithSchema "s" "t"]}
+>      ,q "select a from s1.t1 natural inner join t2"
+>       stbl {selTref = [naturalInnerJoin (trefWithSchema "s1" "t1") (tref "t2") ]}
+>    ]
+>   ]
+>  where
+>    s = ParseStmts defaultParseFlags
+>    stbl = makeSelect
+>           {selSelectList = sl [si $ ei "a"]
+>           ,selTref = []}
+>    q = ParseQueryExpr defaultParseFlags
+>    nameWithSchema sc n = Name ea $ [Nmc $ T.unpack sc, Nmc $ T.unpack n]
+>    trefWithSchema sc t = Tref ea (nameWithSchema sc t)
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/SelectLists.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/SelectLists.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/SelectLists.lhs
@@ -0,0 +1,117 @@
+> {-# LANGUAGE QuasiQuotes,OverloadedStrings #-}
+>
+> module Database.HsSqlPpp.Tests.Parsing.SelectLists (selectLists) where
+>
+> --import Database.HsSqlPpp.Utils.Here
+>
+> import Database.HsSqlPpp.Syntax
+
+> import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+
+> selectLists :: Item
+> selectLists =
+>    Group "selectLists"
+>    [q "select a from tbl" stbl
+>    ,q "select a,b from tbl"
+>       $ stbl {selSelectList = sl [si $ ei "a"
+>                                  ,si $ ei "b"]}
+>    ,q "select a as b from tbl"
+>       $ stbl {selSelectList = sl [sia (ei "a") $ Nmc "b"]}
+>    ,q "select * from tbl"
+>       $ stbl {selSelectList = sl [si $ Star ea]}
+>    ,q "select tbl.* from tbl"
+>       $ stbl {selSelectList = sl [si $ QStar ea (Nmc "tbl")]}
+>    ,q "select a + b as b from tbl;"
+>       $ stbl {selSelectList = sl [sia (binop "+" (ei "a") (ei "b")) $ Nmc "b"]}
+
+>    -- window stuff
+>    ,q "select row_number() over(order by a) as place from tbl;"
+>       $ stbl
+>         {selSelectList =
+>           sl [sia (WindowApp ea
+>                     (app "row_number" [])
+>                     []
+>                     [(ei "a", Asc, NullsDefault)] Nothing)
+>               $ Nmc "place"]}
+>    ,q "select row_number() over(order by a asc) as place from tbl;"
+>       $ stbl
+>         {selSelectList =
+>           sl [sia (WindowApp ea
+>                     (app "row_number" [])
+>                     []
+>                     [(ei "a", Asc, NullsDefault)] Nothing)
+>               $ Nmc "place"]}
+>    ,q "select row_number() over(order by a desc) as place from tbl;"
+>       $ stbl
+>         {selSelectList =
+>           sl [sia (WindowApp ea
+>                     (app "row_number" [])
+>                     []
+>                     [(ei "a", Desc, NullsDefault)] Nothing)
+>               $ Nmc "place"]}
+>    ,q "select row_number()\n\
+>         \over(partition by a,b order by c) as place\n\
+>         \from tbl;"
+>       $ stbl
+>         {selSelectList = sl [sia (WindowApp ea
+>                                   (app "row_number" [])
+>                                   [ei "a", ei "b"]
+>                                   [(ei "c", Asc, NullsDefault)]
+>                                   Nothing)
+>                              (Nmc "place")]}
+>    ,q "select row_number() over(), x from tbl;"
+>       $ stbl
+>         {selSelectList = sl [si $ WindowApp ea
+>                                   (app "row_number" [])
+>                                   [] [] Nothing
+>                             ,si $ ei "x"]}
+
+aggregates, group by, having
+
+>    ,q "select count(distinct b) from tbl;"
+>       $ stbl {selSelectList =
+>               sl [si $ AggregateApp ea Distinct (app "count" [ei "b"]) []]}
+>    ,q "select count(all b) from tbl;"
+>       $ stbl {selSelectList =
+>               sl [si $ AggregateApp ea All (app "count" [ei "b"]) []]}
+>    ,q "select string_agg(distinct relname,',' order by relname1) from tbl;"
+>       $ stbl {selSelectList =
+>               sl [si $ AggregateApp ea Distinct
+>                   (app "string_agg" [ei "relname",str ","])
+>                   [(ei "relname1", Asc, NullsDefault)]]}
+>    ,q "select a, count(b) from tbl group by a;"
+>       $ stbl {selSelectList =
+>               sl [si $ ei "a"
+>                  ,si $ app "count" [ei "b"]]
+>              ,selGroupBy = [ei "a"]}
+>    ,q "select a, count(b) as cnt from tbl group by a having cnt > 4;"
+>       $ stbl {selSelectList =
+>               sl [si $ ei "a"
+>                  ,sia (app "count" [ei "b"]) $ Nmc "cnt"]
+>              ,selGroupBy = [ei "a"]
+>              ,selHaving = Just $ binop  ">" (ei "cnt") (num "4")}
+>    ,q "select a from tbl option (partition group);"
+>       $ stbl {selOption = [QueryHintPartitionGroup]}
+>    ,q "select a from tbl option (partition group,columnar host group);"
+>       $ stbl {selOption = [QueryHintPartitionGroup,QueryHintColumnarHostGroup]}
+>    ,q "select a b from tbl;"
+>       $ stbl { selSelectList = sl [sia (ei "a") (Nmc "b")] }
+>    ,q "select a b, b c, c d from tbl;"
+>       $ stbl { selSelectList = sl [sia (ei "a") (Nmc "b"), sia (ei "b") (Nmc "c"), sia (ei "c") (Nmc "d")] }
+>    ,q "select a + b b from tbl;"
+>       $ stbl {selSelectList = sl [sia (binop "+" (ei "a") (ei "b")) $ Nmc "b"]}
+>    ,q "select row_number() over(order by a) place from tbl;"
+>       $ stbl
+>         {selSelectList =
+>           sl [sia (WindowApp ea
+>                     (app "row_number" [])
+>                     []
+>                     [(ei "a", Asc, NullsDefault)] Nothing)
+>               $ Nmc "place"]}
+>    ]
+>    where
+>      stbl = makeSelect
+>             {selSelectList = sl [si $ ei "a"]
+>             ,selTref = [tref "tbl"]}
+>      q = ParseQueryExpr defaultParseFlags
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/SqlServer.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/SqlServer.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/SqlServer.lhs
@@ -0,0 +1,195 @@
+
+
+> {-# LANGUAGE QuasiQuotes,OverloadedStrings #-}
+>
+> module Database.HsSqlPpp.Tests.Parsing.SqlServer (sqlServer) where
+>
+> --import Database.HsSqlPpp.Utils.Here
+>
+> import Database.HsSqlPpp.Syntax
+
+> import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+> import Database.HsSqlPpp.Dialect
+
+> sqlServer :: Item
+> sqlServer =
+>   Group "parse sql server"
+>   [s "select top 3 * from a order by c;"
+>       [qs $ makeSelect
+>               {selSelectList = sl [si $ Star ea]
+>               ,selTref = [tref "a"]
+>               ,selOrderBy = [(ei "c", Asc, NullsDefault)]
+>               ,selLimit = Just $ num "3"}]
+>   ,s "select top(3) * from a order by c;"
+>       [qs $ makeSelect
+>               {selSelectList = sl [si $ Star ea]
+>               ,selTref = [tref "a"]
+>               ,selOrderBy = [(ei "c", Asc, NullsDefault)]
+>               ,selLimit = Just $ num "3"}]
+>   ,s "select r.dn as 'rg' from tbl;"
+>    [qs $ makeSelect
+>        {selSelectList = sl [sia (eqi "r" "dn") $ QNmc "rg"]
+>        ,selTref = [tref "tbl"]}]
+>   ,s "select r.dn as 'check the pretty printing' from tbl;"
+>    [qs $ makeSelect
+>            {selSelectList = sl [sia (eqi "r" "dn") $ QNmc "check the pretty printing"]
+>            ,selTref = [tref "tbl"]}]
+
+syntax for identifiers is:
+[[[server.] [database].][schema].] database-object]
+so could have
+server.db.sc.obj
+->
+server...obj
+=> three dots max
+
+>   ,s "select a..b() from t;"
+>    [qs $ makeSelect
+>            {selSelectList = sl [SelExp ea (App ea (Name ea [Nmc "a",Nmc "", Nmc "b"])
+>                                            [])]
+>            ,selTref = [tref "t"]}]
+>   ,s "select a...b() from t;"
+>    [qs $ makeSelect
+>            {selSelectList = sl [SelExp ea (App ea (Name ea [Nmc "a",Nmc "", Nmc "", Nmc "b"])
+>                                            [])]
+>            ,selTref = [tref "t"]}]
+>   ,s "select * from a join x..b;"
+>    [qs $ makeSelect
+>            {selSelectList = sl [si $ Star ea]
+>            ,selTref = [innerJoin (tref "a")
+>                       (Tref ea (Name ea [Nmc "x",Nmc "",Nmc "b"])) Nothing]}]
+
+>   ,s "select * from a join x...b;"
+>    [qs $ makeSelect
+>            {selSelectList = sl [si $ Star ea]
+>            ,selTref = [innerJoin (tref "a")
+>                       (Tref ea (Name ea [Nmc "x",Nmc "",Nmc "",Nmc "b"])) Nothing]}]
+>   ,s "select a from t with(nolock);"
+>     -- with is just (sort of) recognised, and not parsed to abstract
+>     -- syntax
+>    [qs $ makeSelect
+>            {selSelectList = sl [si $ ei "a"]
+>            ,selTref = [tref "t"]}]
+>   ,s "select a from #tbl;"
+>    [qs $ makeSelect
+>            {selSelectList = sl [si $ ei "a"]
+>            ,selTref = [tref "#tbl"]}]
+
+>   ,s "CREATE TABLE [schema].[table_name](\n\
+>      \             [fieldname] [typename])"
+>    $ [CreateTable ea (Name ea [QNmc "schema",QNmc "table_name"])
+>       [AttributeDef ea (QNmc "fieldname")
+>        (SimpleTypeName ea (Name ea [QNmc "typename"])) Nothing []] [] Nothing NoReplace]
+
+>   ,s "select a from t  -- no semi colon\n\
+>      \select b from t"
+>    $ [qs $ makeSelect
+>            {selSelectList = sl [si $ ei "a"]
+>            ,selTref = [tref "t"]}
+>      ,qs $ makeSelect
+>            {selSelectList = sl [si $ ei "b"]
+>            ,selTref = [tref "t"]}]
+
+>   ,s "if 1=1\n\
+>      \   drop table #temp\n\
+>      \select b from t"
+>    $ [If ea [(binop "=" (num "1") (num "1")
+>              ,[DropSomething ea Table Require [name "#temp"] Restrict])] []
+>      ,qs $ makeSelect
+>            {selSelectList = sl [si $ ei "b"]
+>            ,selTref = [tref "t"]}]
+
+>   ,s "declare @nm int"
+>      $ [DeclareStatement ea [("@nm"
+>                              ,st "int"
+>                              ,Nothing)]]
+
+>   ,s "declare @nm int = 3, @nm2 datetime = '1/1/2000'"
+>      $ [DeclareStatement ea [("@nm"
+>                              ,st "int"
+>                              ,Just (num "3"))
+>                             ,("@nm2"
+>                              ,st "datetime"
+>                              ,Just $ str "1/1/2000")
+>                             ]]
+
+>   --,s "set @nm=3"
+>   --   $ [Assignment ea (name "@nm") (num "3")]
+>   ,s "select convert (INT,5) from t"
+>      $ [qs $ makeSelect
+>            {selSelectList = sl [si $ App ea (name "convert") [ei "INT",num "5"]]
+>            ,selTref = [tref "t"]}]
+
+todo: add more complex type name
+
+needs to be better: the style is lost, also a bit inconsistent
+
+>   ,s "select convert (time,something,108) from t"
+>      $ [qs $ makeSelect
+>            {selSelectList = sl [si $ Cast ea (ei "something") (st "time")]
+>            ,selTref = [tref "t"]}]
+
+>   ,s "CREATE NONCLUSTERED INDEX idx ON tbl (col) INCLUDE (Gap)"
+>      $ [CreateIndexTSQL ea (Nmc "idx") (name "tbl") [Nmc "col"]]
+
+>   ,s "CREATE NONCLUSTERED INDEX idx ON [dbo].[#tmp] (col) INCLUDE (Gap)"
+>      $ [CreateIndexTSQL ea (Nmc "idx")
+>                             (Name ea [QNmc "dbo"
+>                                      ,QNmc "#tmp"])
+>                            [Nmc "col"]]
+>   ,s "select y -@test from t"
+>      $ [qs $ makeSelect
+>            {selSelectList = sl [si $ binop "-" (ei "y") (ei "@test")]
+>            ,selTref = [tref "t"]}]
+>   ,s "select * from t natural inner hash join u"
+>      [qs $ makeSelect
+>        {selSelectList = sl [si $ Star ea]
+>        ,selTref = [JoinTref ea (tref "t") Natural Inner
+>                    (Just Hash) (tref "u") Nothing]}
+>      ]
+>   ,s "select * from t natural inner loop join u"
+>      [qs $ makeSelect
+>        {selSelectList = sl [si $ Star ea]
+>        ,selTref = [JoinTref ea (tref "t") Natural Inner
+>                    (Just Loop) (tref "u") Nothing]}
+>      ]
+>   ,s "select * from t natural inner merge join u"
+>      [qs $ makeSelect
+>        {selSelectList = sl [si $ Star ea]
+>        ,selTref = [JoinTref ea (tref "t") Natural Inner
+>                    (Just Merge) (tref "u") Nothing]}
+>      ]
+
+The following will fail if the words are not marked as keywords
+in ParserInternal.lhs
+
+>   ,s "select * from t loop join u"
+>      [qs $ makeSelect
+>        {selSelectList = sl [si $ Star ea]
+>        ,selTref = [JoinTref ea (tref "t") Unnatural Inner
+>                    (Just Loop) (tref "u") Nothing]}
+>      ]
+
+>   ,s "select * from t merge join u"
+>      [qs $ makeSelect
+>        {selSelectList = sl [si $ Star ea]
+>        ,selTref = [JoinTref ea (tref "t") Unnatural Inner
+>                    (Just Merge) (tref "u") Nothing]}
+>      ]
+
+>   ,s "select * from t hash join u"
+>      [qs $ makeSelect
+>        {selSelectList = sl [si $ Star ea]
+>        ,selTref = [JoinTref ea (tref "t") Unnatural Inner
+>                    (Just Hash) (tref "u") Nothing]}
+>      ]
+
+>   ]
+>   where
+>     s = ParseProcSql defaultParseFlags {pfDialect=sqlServerDialect}
+>     qs = QueryStatement ea
+
+create index ++
+parse select into to create table as (do this for postgresql non
+  plpgsql also)
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/TableRefs.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/TableRefs.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/TableRefs.lhs
@@ -0,0 +1,46 @@
+
+> {-# LANGUAGE QuasiQuotes,OverloadedStrings #-}
+>
+> module Database.HsSqlPpp.Tests.Parsing.TableRefs (tableRefs) where
+>
+> --import Database.HsSqlPpp.Utils.Here
+>
+> import Database.HsSqlPpp.Syntax
+
+> import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+
+> tableRefs :: Item
+> tableRefs =
+>    Group "tableRefs"
+>    [q "select a from tbl" stbl
+>    ,q "select a from sc.tbl"
+>     stbl {selTref = [qtref "sc" "tbl"]}
+>    ,q "select a from tbl a"
+>     stbl {selTref = [trefa "tbl" "a"]}
+>    ,q "select a from tbl as a"
+>     stbl {selTref = [trefa "tbl" "a"]}
+
+>    ,q "select a from tbl as a(b,c)"
+>     stbl {selTref = [treffa "tbl" "a" ["b","c"]]}
+
+>    ,q "select a from gen();"
+>     stbl {selTref = [FunTref ea (app "gen" [])]}
+>    ,q "select a from gen() t;"
+>     stbl {selTref = [ta $ FunTref ea (app "gen" [])]}
+>    ,q "select a from gen() as t;"
+>     stbl {selTref = [ta $ FunTref ea (app "gen" [])]}
+
+>    ,q "select a from (select a from tbl) as t;"
+>     stbl {selTref = [ta $ SubTref ea stbl]}
+
+>    ,q "select a from (select a from tbl) t;"
+>     stbl {selTref = [ta $ SubTref ea stbl]}
+
+>    ]
+>    where
+>      ta = TableAlias ea (Nmc "t")
+>      stbl = makeSelect
+>             {selSelectList = sl [si $ ei "a"]
+>             ,selTref = [tref "tbl"]}
+>      q = ParseQueryExpr defaultParseFlags
diff --git a/tests/Database/HsSqlPpp/Tests/Parsing/Utils.lhs b/tests/Database/HsSqlPpp/Tests/Parsing/Utils.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Parsing/Utils.lhs
@@ -0,0 +1,137 @@
+
+test item data type
+
+shortcuts for constructing test data and asts
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.Parsing.Utils where
+
+> import Database.HsSqlPpp.Syntax
+> --import Database.HsSqlPpp.Lex (Token)
+> import Database.HsSqlPpp.Annotation
+> import qualified Data.Text as T
+> import Data.Text (Text)
+> --import qualified Data.Text.Lazy as L
+> import Control.Arrow
+> --import Database.HsSqlPpp.Internals.Dialect
+> --import Database.HsSqlPpp.Tests.TestTypes
+
+> stringQ :: Text -> ScalarExpr
+> stringQ = StringLit ea . T.unpack
+>
+> eqi :: Text -> Text -> ScalarExpr
+> eqi c x = Identifier ea $ qn c x
+
+> ei :: Text -> ScalarExpr
+> ei j = Identifier ea $ name j
+>
+> qn :: Text -> Text -> Name
+> qn c n = Name ea [Nmc $ T.unpack c, Nmc $ T.unpack n]
+>
+> sl :: [SelectItem] -> SelectList
+> sl = SelectList ea
+>
+>
+> att :: Text -> Text -> AttributeDef
+> att n t = AttributeDef ea (Nmc $ T.unpack n) (SimpleTypeName ea $ name t) Nothing []
+
+> ea :: Annotation
+> ea = emptyAnnotation
+
+> name :: Text -> Name
+> name n = Name ea [Nmc $ T.unpack n]
+
+> member :: ScalarExpr -> ScalarExpr -> ScalarExpr
+> member a b = BinaryOp ea (name ".") a b
+
+> num :: Text -> ScalarExpr
+> num n = NumberLit ea $ T.unpack n
+
+> app :: Text -> [ScalarExpr] -> ScalarExpr
+> app n as = App ea (name n) as
+
+> specop :: Text -> [ScalarExpr] -> ScalarExpr
+> specop n as = SpecialOp ea (name n) as
+
+
+> prefop :: Text -> ScalarExpr -> ScalarExpr
+> prefop n a = PrefixOp ea (name n) a
+
+> postop :: Text -> ScalarExpr -> ScalarExpr
+> postop n a = PostfixOp ea (name n) a
+
+> binop :: Text -> ScalarExpr -> ScalarExpr -> ScalarExpr
+> binop n a0 a1 = BinaryOp ea (name n) a0 a1
+
+> lTrue,lFalse,lNull :: ScalarExpr
+> lTrue = BooleanLit ea True
+> lFalse = BooleanLit ea False
+> lNull = NullLit ea
+
+> st :: Text -> TypeName
+> st n = SimpleTypeName ea (Name ea [Nmc $ T.unpack n])
+
+> parenQual :: ScalarExpr -> ScalarExpr -> ScalarExpr
+> parenQual a b = BinaryOp ea (name ".") (Parens ea a) b
+
+> tref :: Text -> TableRef
+> tref s = Tref ea (name s)
+
+> trefa :: Text -> Text -> TableRef
+> trefa t a = TableAlias ea (Nmc $ T.unpack a) $ Tref ea (name t)
+
+> treffa :: Text -> Text -> [Text] -> TableRef
+> treffa t a cs = FullAlias ea (Nmc $ T.unpack a) (map (Nmc . T.unpack) cs)
+>                 $ Tref ea (name t)
+
+
+> qtref :: Text -> Text -> TableRef
+> qtref q i = Tref ea (qn q i)
+
+> si :: ScalarExpr -> SelectItem
+> si = SelExp ea
+
+> sia :: ScalarExpr -> NameComponent -> SelectItem
+> sia e a = SelectItem ea e a
+
+
+> str :: Text -> ScalarExpr
+> str = StringLit ea . T.unpack
+
+> set :: Text -> ScalarExpr -> SetClause
+> set n v = SetClause ea (Nmc $ T.unpack n) v
+
+> varDef :: Text -> TypeName -> VarDef
+> varDef nm t = VarDef ea (Nmc $ T.unpack nm) t Nothing
+
+> varDefv :: Text -> TypeName -> ScalarExpr -> VarDef
+> varDefv nm t v = VarDef ea (Nmc $ T.unpack nm) t (Just v)
+
+> paramDef :: Text -> TypeName -> ParamDef
+> paramDef nm t = ParamDef ea (Nmc $ T.unpack nm) t
+
+> at :: Text -> TypeName
+> at = ArrayTypeName ea . st
+
+> innerJoin :: TableRef -> TableRef -> Maybe ScalarExpr -> TableRef
+> innerJoin a b o = JoinTref ea a Unnatural Inner Nothing b
+>                            (fmap (JoinOn ea) o)
+
+> naturalInnerJoin :: TableRef -> TableRef -> TableRef
+> naturalInnerJoin a b  = JoinTref ea a Natural Inner Nothing b Nothing
+
+> usingInnerJoin :: TableRef -> TableRef -> [Text] -> TableRef
+> usingInnerJoin a b us = JoinTref ea a Unnatural Inner Nothing b
+>                            (Just $ JoinUsing ea $ map (Nmc . T.unpack) us)
+
+> tjoin :: TableRef -> JoinType -> TableRef -> Maybe ScalarExpr -> TableRef
+> tjoin a b c o = JoinTref ea a Unnatural b Nothing c (fmap (JoinOn ea) o)
+
+> with :: [(Text,QueryExpr)] -> QueryExpr -> QueryExpr
+> with ws e =
+>   WithQueryExpr ea
+>    (map (\(n,ne) -> WithQuery ea (Nmc n) Nothing ne) $ map (first T.unpack) ws)
+>    e
+
+> tfp :: TableRef -> TableRef
+> tfp = TableRefParens ea
diff --git a/tests/Database/HsSqlPpp/Tests/TestTypes.lhs b/tests/Database/HsSqlPpp/Tests/TestTypes.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TestTypes.lhs
@@ -0,0 +1,83 @@
+> module Database.HsSqlPpp.Tests.TestTypes (
+>     defaultParseFlags
+>    ,defaultTypeCheckFlags
+>    ,Dialect(..)
+>    ,ParseFlags(..)
+>    ,TypeCheckFlags(..)
+>    ,Item(..)
+>    --,defaultTemplate1Catalog
+>    --,ansiCatalog
+>    ,emptyEnvironment
+>    ,makeCatalog
+>    ,hackCanonicalizeEnvTypeNames
+>   ) where
+
+> import Database.HsSqlPpp.Syntax
+> import Database.HsSqlPpp.Lex (Token)
+> --import Database.HsSqlPpp.Annotation
+> --import qualified Data.Text as T
+> --import Data.Text (Text)
+> import qualified Data.Text.Lazy as L
+> --import Control.Arrow
+> --import Test.HUnit
+> --import Test.Framework.Providers.HUnit
+> --import Test.Framework
+> --import Data.List
+> import Data.Generics.Uniplate.Data
+> import Database.HsSqlPpp.Parse
+> import Database.HsSqlPpp.TypeCheck
+> --import Database.HsSqlPpp.Annotation
+> import Database.HsSqlPpp.Catalog
+> import Database.HsSqlPpp.Dialect
+> --import Database.HsSqlPpp.Ast hiding (App)
+> import Database.HsSqlPpp.Types
+> --import Database.HsSqlPpp.Pretty
+> -- import Database.HsSqlPpp.Utility
+> --import Database.HsSqlPpp.Internals.TypeChecking.Environment
+> --import Text.Show.Pretty
+> --import Debug.Trace
+> --import Database.HsSqlPpp.Tests.TestUtils
+> --import Control.Monad
+
+> --import Database.HsSqlPpp.Utils.GroomUtils
+> --import qualified Data.Text.Lazy as L
+> import Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.TypeConversion2
+> import Data.Data
+
+
+> data Item = Group String [Item]
+>           | ParseScalarExpr ParseFlags L.Text ScalarExpr
+>           | ParseStmts ParseFlags L.Text [Statement]
+>           | ParseProcSql ParseFlags L.Text [Statement]
+>           | ParseQueryExpr ParseFlags L.Text QueryExpr
+>           | Lex Dialect L.Text [Token]
+>           | TCScalExpr Catalog Environment TypeCheckFlags
+>                        L.Text (Either [TypeError] Type)
+>           | TCQueryExpr Catalog TypeCheckFlags
+>                         L.Text (Either [TypeError] Type)
+>           | TCStatements Catalog TypeCheckFlags
+>                          L.Text (Maybe [TypeError])
+>           | InsertQueryExpr [CatalogUpdate] L.Text (Either [TypeError] Type)
+>           | RewriteQueryExpr TypeCheckFlags [CatalogUpdate] L.Text L.Text
+
+>           | ImpCastsScalar TypeCheckFlags L.Text L.Text
+>             -- todo: combine this with tcscalexpr
+>           | ScalarExprExtra Dialect Catalog Environment L.Text (Either [TypeError] TypeExtra)
+>           | MatchApp Dialect Catalog [NameComponent]
+>                      [(TypeExtra, Maybe LitArg)]
+>                      (Either [TypeError] ([TypeExtra],TypeExtra))
+>           | Custom String (IO ())
+
+> makeCatalog :: Dialect -> [CatalogUpdate] -> Catalog
+> makeCatalog d cus =
+>     either (error . show) id
+>     $ updateCatalog (hackCanonicalizeEnvTypeNames d cus) $ diDefaultCatalog d
+
+This takes a type name and canonicalizes it, first by trying to see if
+it is the ansi type name and the dialect uses a different name for
+that type, and then checks to see if this is a built in alias of a
+type for that dialect and gets the canonical name instead.
+
+> hackCanonicalizeEnvTypeNames :: Data a => Dialect -> a -> a
+> hackCanonicalizeEnvTypeNames d = transformBi $ \a -> case a of
+>     s -> maybe (canonicalizeTypeName d s) id $ ansiTypeNameToDialect d s
diff --git a/tests/Database/HsSqlPpp/Tests/TestUtils.lhs b/tests/Database/HsSqlPpp/Tests/TestUtils.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TestUtils.lhs
@@ -0,0 +1,426 @@
+
+> module Database.HsSqlPpp.Tests.TestUtils
+>     (assertTrace,itemToTft) where
+>
+> import qualified Test.Tasty as T
+> import qualified Test.Tasty.HUnit as H
+> --import Data.List
+> import Data.Generics.Uniplate.Data
+> import Data.Data
+
+> import Debug.Trace
+> import Control.Monad
+
+> --import Database.HsSqlPpp.Utils.Here
+> import Database.HsSqlPpp.Parse
+> import Database.HsSqlPpp.Syntax
+> import Database.HsSqlPpp.Pretty
+> import Database.HsSqlPpp.TypeCheck
+> import Database.HsSqlPpp.Annotation
+> import Database.HsSqlPpp.Catalog
+> import Database.HsSqlPpp.Utils.GroomUtils
+> import Database.HsSqlPpp.Utility
+> --import Database.HsSqlPpp.SqlTypes
+> --import Database.HsSqlPpp.Utils.PPExpr
+> --import Data.Text.Lazy (Text)
+> import qualified Data.Text.Lazy as L
+> --import qualified Data.Text as T
+> import Database.HsSqlPpp.Lex (lexTokens,prettyToken,Token)
+> --import Text.Parsec.Text (runParser)
+> --import Control.Applicative
+> --import Data.Generics.Uniplate.Data
+> import Database.HsSqlPpp.Tests.TestTypes
+> import Database.HsSqlPpp.Internals.TypeChecking.TypeConversion.TypeConversion2
+
+> --import Test.HUnit
+> --import Test.Framework.Providers.HUnit
+> --import Test.Framework
+> --import Data.List
+> --import Data.Generics.Uniplate.Data
+> --import Database.HsSqlPpp.Parser
+> --import Database.HsSqlPpp.TypeChecker
+> --import Database.HsSqlPpp.Annotation
+> --import Database.HsSqlPpp.Catalog
+> --import Database.HsSqlPpp.Ast hiding (App)
+> import Database.HsSqlPpp.Types
+> --import Database.HsSqlPpp.Pretty
+> --import Database.HsSqlPpp.Utility
+> --import Database.HsSqlPpp.Internals.TypeChecking.Environment
+> --import Text.Show.Pretty
+> --import Debug.Trace
+> --import Database.HsSqlPpp.Tests.TestUtils
+> --import Control.Monad
+
+> --import Database.HsSqlPpp.Utils.GroomUtils
+
+> --import qualified Data.Text.Lazy as L
+> import Database.HsSqlPpp.Dialect
+
+> assertTrace :: (Show a,Eq a) => String -> String -> a -> a -> IO ()
+> assertTrace nem s a1 a2 = do
+>     when (a1 /= a2) $ trace nem $ return ()
+>     H.assertEqual s a1 a2
+
+> itemToTft :: Item -> T.TestTree
+> itemToTft (ParseScalarExpr f a b) = testParseScalarExpr f a b
+> itemToTft (ParseQueryExpr f a b) = testParseQueryExpr f a b
+> --itemToTft (ParseProcSql f a b) = testParseProcSql f a b
+> itemToTft (ParseStmts f a b) = testParseStatements f a b
+> itemToTft (ParseProcSql f a b) = testParseProcSql f a b
+> {-itemToTft (TSQL a b) =
+>   testParsePlpgsqlStatements (if True
+>                        then SQLServer
+>                        else PostgreSQL) a b-}
+> {-itemToTft (OracleX a b) =
+>   testParsePlpgsqlStatements Oracle a b -}
+> --itemToTft (MSStmt a b) = testParseStatements a b
+> itemToTft (Group s is) = T.testGroup s $ map itemToTft is
+> itemToTft (Lex d a b) = testLex d a b
+
+> itemToTft (TCScalExpr c e f s r) = testTCScalarExpr c e f s r
+> itemToTft (TCQueryExpr cat f s r) = testQueryExprType cat f s r
+> itemToTft (TCStatements cat f s r) = testStatementsTypecheck cat f s r
+> itemToTft (InsertQueryExpr cus s r) = testInsertQueryExprType sqlServerDialect {-PostgreSQL-} cus s r
+> --itemToTft (TSQLQueryExpr cus s r) = undefined --testQueryExprType SQLServer cus s r
+> --itemToTft (OracleQueryExpr cus s r) = undefined --testQueryExprType Oracle cus s r
+> itemToTft (RewriteQueryExpr f cus s s') = testRewrite f cus s s'
+
+> itemToTft (ImpCastsScalar f s s') = testImpCastsScalar f s s'
+> itemToTft (ScalarExprExtra d cat env s r) = testScalarExprTypeExtra d cat env s r
+> itemToTft (MatchApp d cat f as r) = testMatchApp d cat f as r
+> itemToTft (Custom nm f) = H.testCase nm f
+
+> testParseScalarExpr :: ParseFlags -> L.Text -> ScalarExpr -> T.TestTree
+> testParseScalarExpr f src ast =
+>   parseUtil src ast (parseScalarExpr f "" Nothing)
+>                     (parseScalarExpr f "" Nothing)
+>                     (prettyScalarExpr
+>                      defaultPrettyFlags {ppDialect = pfDialect f} )
+> testParseQueryExpr :: ParseFlags -> L.Text -> QueryExpr -> T.TestTree
+> testParseQueryExpr f src ast =
+>   parseUtil src ast (parseQueryExpr f "" Nothing)
+>                     (parseQueryExpr f "" Nothing)
+>                     (prettyQueryExpr defaultPrettyFlags {ppDialect = pfDialect f})
+
+>
+> testParseStatements :: ParseFlags -> L.Text -> [Statement] -> T.TestTree
+> testParseStatements flg src ast =
+>   let parse = parseStatements flg "" Nothing
+>       pp = prettyStatements defaultPrettyFlags {ppDialect=pfDialect flg}
+>   in parseUtil src ast parse parse pp
+
+> testParseProcSql :: ParseFlags -> L.Text -> [Statement] -> T.TestTree
+> testParseProcSql flg src ast =
+>   let parse = parseProcSQL flg "" Nothing
+>       pp = prettyStatements defaultPrettyFlags {ppDialect=pfDialect flg}
+>   in parseUtil src ast parse parse pp
+
+>
+>
+> parseUtil :: (Show t, Eq b, Show b, Data b) =>
+>              L.Text
+>           -> b
+>           -> (L.Text -> Either t b)
+>           -> (L.Text -> Either t b)
+>           -> (b -> L.Text)
+>           -> T.TestTree
+> parseUtil src ast parser reparser printer = H.testCase ("parse " ++ L.unpack src) $
+>   case parser src of
+>     Left er -> H.assertFailure $ show er
+>     Right ast' -> do
+>       when (ast /= resetAnnotations ast') $ do
+>         putStrLn $ groomNoAnns ast
+>         putStrLn $ groomNoAnns $ resetAnnotations ast'
+>       H.assertEqual ("parse " ++ L.unpack src) ast $ resetAnnotations ast'
+>       case reparser (printer ast) of
+>         Left er -> H.assertFailure $ "reparse\n" ++ (L.unpack $ printer ast) ++ "\n" ++ show er ++ "\n" -- ++ pp ++ "\n"
+>         Right ast'' -> H.assertEqual ("reparse: " ++ L.unpack (printer ast)) ast $ resetAnnotations ast''
+
+> testLex :: Dialect -> L.Text -> [Token] -> T.TestTree
+> testLex d t r = H.testCase ("lex "++ L.unpack t) $ do
+>     let x = lexTokens d "" Nothing t
+>         y = either (error . show) id x
+>     H.assertEqual "lex" r (map snd y)
+>     let t' = L.concat $ map (L.pack . prettyToken d) r
+>     H.assertEqual "lex . pretty" t t'
+
+> testTCScalarExpr :: Catalog -> Environment -> TypeCheckFlags
+>                    -> L.Text -> Either [TypeError] Type -> T.TestTree
+> testTCScalarExpr cat env f src et =
+>   H.testCase ("typecheck " ++ L.unpack src) $ do
+>   let ast = case parseScalarExpr defaultParseFlags {pfDialect = tcfDialect f} "" Nothing src of
+>               Left e -> error $ show e
+>               Right l -> l
+>       aast = typeCheckScalarExpr f cat
+>              (canonicalizeEnvTypes (tcfDialect f) env)
+>              $ canonicalizeTypes (tcfDialect f) ast
+>       (ty,errs,noTypeQEs,noTypeSEs) = tcTreeInfo aast
+>       er = concatMap fst errs
+>       got = case () of
+>               _ | null er -> maybe (Left []) (Right . teType) ty
+>                 | otherwise -> Left er
+>       allTyped = case et of
+>                    Left _ -> True -- don't check if everything is typed
+>                                   -- if expecting a type error
+>                    Right _ -> null noTypeSEs && null noTypeQEs
+>   unless allTyped $
+>        trace ("MISSING TYPES: " ++ groomTypes aast)
+>        $ H.assertBool "" allTyped
+>   unless (et == got) $ trace (groomTypes aast) $ return ()
+>   H.assertEqual "" et got
+
+> testScalarExprTypeExtra:: Dialect -> Catalog -> Environment -> L.Text
+>                           -> Either [TypeError] TypeExtra
+>                           -> T.TestTree
+> testScalarExprTypeExtra d cat env src ete = H.testCase ("typecheck " ++ L.unpack src) $ do
+>   let ast = case parseScalarExpr defaultParseFlags {pfDialect = d} "" Nothing src of
+>               Left e -> error $ show e
+>               Right l -> l
+>       aast = typeCheckScalarExpr defaultTypeCheckFlags {tcfDialect = d} cat
+>              (canonicalizeEnvTypes d env)
+>              $ canonicalizeTypes d ast
+>       (ty,errs,noTypeQEs,noTypeSEs) = tcTreeInfo aast
+>       er = concatMap fst errs
+>       got = case () of
+>               _ | null er -> maybe (Left []) Right ty
+>                 | otherwise -> Left er
+>       allTyped = case ete of
+>           Left _ -> True  -- don't check if everything is typed
+>                           -- if expecting a type error
+>           Right _ -> null noTypeSEs && null noTypeQEs
+>   unless allTyped $
+>        trace ("MISSING TYPES: " ++ groomTypes aast)
+>        $ H.assertBool "" allTyped
+>   unless (ete == got) $ trace (groomTypes aast) $ return ()
+>   H.assertEqual "" ete got
+
+> testImpCastsScalar :: TypeCheckFlags -> L.Text -> L.Text -> T.TestTree
+> testImpCastsScalar f src wsrc = H.testCase ("typecheck " ++ L.unpack src) $
+>   let ast = case parseScalarExpr defaultParseFlags {pfDialect = tcfDialect f} "" Nothing src of
+>               Left e -> error $ show e
+>               Right l -> l
+>       aast = typeCheckScalarExpr f (diDefaultCatalog postgresDialect) emptyEnvironment
+>              $ canonicalizeTypes (tcfDialect f) ast
+>       aast' = addExplicitCasts aast
+>       wast = case parseScalarExpr defaultParseFlags {pfDialect = tcfDialect f} "" Nothing wsrc of
+>                Left e -> error $ show e
+>                Right l -> l
+>   in (if (resetAnnotations aast') /= (resetAnnotations wast)
+>       then trace ("\n***************** got: \n"
+>                   ++ L.unpack (prettyScalarExpr defaultPrettyFlags aast')
+>                   ++ "\nwanted:\n" ++ L.unpack (prettyScalarExpr defaultPrettyFlags wast)
+>                   ++ "\n*****************\n"
+>                   ++ "\n***************** got: \n"
+>                   ++ groomNoAnns aast'
+>                   ++ "\nwanted:\n" ++ groomNoAnns wast
+>                   ++ "\n*****************\n"
+>                   )
+>       else id) $ H.assertEqual "" (resetAnnotations aast') (resetAnnotations wast)
+
+
+> testQueryExprType :: Catalog -> TypeCheckFlags
+>                   -> L.Text -> Either [TypeError] Type -> T.TestTree
+> testQueryExprType cat f src et =
+>   H.testCase ("typecheck " ++ L.unpack src) $ do
+>   let ast = case parseQueryExpr
+>                  defaultParseFlags {pfDialect = tcfDialect f}
+>                  "" Nothing src of
+>               Left e -> error $ show e
+>               Right l -> l
+>       {-Right cat = updateCatalog cus $ case dl of
+>           PostgreSQL -> defaultTemplate1Catalog
+>           SQLServer -> defaultTSQLCatalog
+>           Oracle -> defaultTSQLCatalog-}
+>       {-flg = case dl of
+>           PostgreSQL -> defaultTypeCheckFlags
+>           SQLServer -> defaultTypeCheckFlags {tcfDialect = SQLServer}
+>           Oracle -> defaultTypeCheckFlags {tcfDialect = Oracle}-}
+>       aast = typeCheckQueryExpr f cat
+>              $ canonicalizeTypes (tcfDialect f) ast
+>       (ty,errs,noTypeQEs,noTypeSEs) = tcTreeInfo aast
+>       er = concatMap fst errs
+>       got :: Either [TypeError] Type
+>       got = case () of
+>               _ | null er -> maybe (Left []) (Right . teType) ty
+>                 | otherwise -> Left er
+>       allTyped = case et of
+>                    Left _ -> True -- don't check if everything is typed
+>                                   -- if expecting a type error
+>                    Right _ -> null noTypeSEs && null noTypeQEs
+>   unless allTyped $
+>        trace ("MISSING TYPES: " ++ groomTypes aast)
+>        $ H.assertBool "" allTyped
+>   unless (et == got) $ trace (groomTypes aast) $ return ()
+>   H.assertEqual "" et got
+>   --queryExprRewrites cus src et
+
+> testStatementsTypecheck :: Catalog -> TypeCheckFlags -> L.Text -> Maybe [TypeError] -> T.TestTree
+> testStatementsTypecheck cat f src et =
+>   H.testCase ("typecheck " ++ L.unpack src) $ do
+>   let ast = case parseStatements defaultParseFlags {pfDialect = tcfDialect f} "" Nothing src of
+>               Left e -> error $ show e
+>               Right l -> l
+>       {-Right cat = updateCatalog cus $ case dl of
+>           PostgreSQL -> defaultTemplate1Catalog
+>           SQLServer -> defaultTSQLCatalog
+>           Oracle -> defaultTSQLCatalog
+>       flg = case dl of
+>           PostgreSQL -> defaultTypeCheckFlags
+>           SQLServer -> defaultTypeCheckFlags {tcfDialect = SQLServer}
+>           Oracle -> defaultTypeCheckFlags {tcfDialect = Oracle}-}
+>       (_,aast) = typeCheckStatements f cat
+>                  $ canonicalizeTypes (tcfDialect f) ast
+>       (_,errs,noTypeQEs,noTypeSEs) = tcTreeInfo aast
+>       er = concatMap fst errs
+>       got :: Maybe [TypeError]
+>       got = case () of
+>               _ | null er -> Nothing
+>                 | otherwise -> Just er
+>       allTyped = case et of
+>                    Just _ -> True -- don't check if everything is typed
+>                                   -- if expecting a type error
+>                    Nothing -> null noTypeSEs && null noTypeQEs
+>   unless allTyped $
+>        trace ("MISSING TYPES: " ++ groomTypes aast)
+>        $ H.assertBool "" allTyped
+>   unless (et == got) $ trace (groomTypes aast) $ return ()
+>   H.assertEqual "" et got
+>   --queryExprRewrites cus src et
+
+
+> testInsertQueryExprType :: Dialect -> [CatalogUpdate] -> L.Text -> Either [TypeError] Type -> T.TestTree
+> testInsertQueryExprType dl cus src et = H.testCase ("typecheck " ++ L.unpack src) $ do
+>   let cat = makeCatalog dl cus
+>       flg = defaultTypeCheckFlags {tcfDialect = dl}
+>       asts = either (error . show) id $ parseStatements defaultParseFlags "" Nothing src
+>       Insert _ _ _ q _ = extractInsert $ snd $ typeCheckStatements flg cat
+>                          $ canonicalizeTypes (tcfDialect flg) asts
+>       q' = addImplicitCasts cat q
+>       q'' = typeCheckQueryExpr flg cat q'
+>       (ty,errs,noTypeQEs,noTypeSEs) = tcTreeInfo q''
+>       er = concatMap fst errs
+>       got :: Either [TypeError] Type
+>       got = case () of
+>               _ | null er -> maybe (Left []) (Right . teType) ty
+>                 | otherwise -> Left er
+>       allTyped = case et of
+>                    Left _ -> True -- don't check if everything is typed
+>                                   -- if expecting a type error
+>                    Right _ -> null noTypeSEs && null noTypeQEs
+>   unless allTyped $
+>        trace ("MISSING TYPES: " ++ groomTypes q'')
+>        $ H.assertBool "" allTyped
+>   unless (et == got) $ trace (groomTypes q'') $ return ()
+>   H.assertEqual "" et got
+>   where
+>     extractInsert [i@Insert{}] = i
+>     extractInsert x = error $ "expected a single insert statement, got " ++ groomTypes x
+
+rewrite the queryexpr with all the options true
+
+pretty print, then check that the resultant sql parses the same, and
+type checks properly and produces the same type
+
+> _queryExprRewrites :: [CatalogUpdate] -> L.Text -> Either [TypeError] Type -> IO () --Test.Framework.Test
+> _queryExprRewrites cus src et = {-testCase ("rewrite expanded " ++ src) $-} do
+>   let ast = case parseQueryExpr defaultParseFlags "" Nothing src of
+>               Left e -> error $ "parse: " ++ L.unpack src ++ "\n" ++ show e
+>               Right l -> l
+>   let cat = makeCatalog postgresDialect cus
+>       aast = typeCheckQueryExpr
+>                defaultTypeCheckFlags {tcfAddQualifiers = True
+>                                         ,tcfAddSelectItemAliases = True
+>                                         ,tcfExpandStars = True
+>                                         ,tcfAddFullTablerefAliases = True}
+>                cat $ canonicalizeTypes
+>                      (tcfDialect defaultTypeCheckFlags) ast
+>       ty = anType $ getAnnotation aast
+>       -- print with rewritten tree
+>       pp = prettyQueryExpr defaultPrettyFlags aast
+>       astrw = case parseQueryExpr defaultParseFlags "" Nothing pp of
+>                 Left e -> error $ "parse: " ++ L.unpack pp ++ "\n" ++ show e
+>                 Right l -> l
+>       aastrw = typeCheckQueryExpr
+>                  defaultTypeCheckFlags
+>                  cat $ canonicalizeTypes
+>                        (tcfDialect defaultTypeCheckFlags) astrw
+>       tyrw = anType $ getAnnotation aast
+>   H.assertEqual "rewrite pp . parse" (resetAnnotations aast) (resetAnnotations aastrw)
+>   H.assertEqual "rewrite ty" ty tyrw
+>   let (_,errs,noTypeQEs,noTypeSEs) = tcTreeInfo aast
+>       er = concatMap fst errs
+>       allTyped = case et of
+>                    Left _ -> True -- don't check if everything is typed
+>                                   -- if expecting a type error
+>                    Right _ -> null noTypeSEs && null noTypeQEs
+>   unless (null er) $
+>        trace ("errors in tree: " ++ groomTypes aastrw)
+>        $ H.assertBool "" (null er)
+>   unless allTyped $
+>        trace ("MISSING TYPES: " ++ groomTypes aastrw)
+>        $ H.assertBool "" allTyped
+
+
+
+
+> testRewrite :: TypeCheckFlags -> [CatalogUpdate] -> L.Text -> L.Text
+>             -> T.TestTree
+> testRewrite f cus src src' = H.testCase ("rewrite " ++ L.unpack src) $ do
+>   let ast = case parseQueryExpr defaultParseFlags {pfDialect = tcfDialect f}
+>                  "" Nothing src of
+>               Left e -> error $ show e
+>               Right l -> l
+>       cat = makeCatalog (tcfDialect f) cus
+>       aast = typeCheckQueryExpr f cat ast
+>       astrw = resetAnnotations aast
+>       ast' = case parseQueryExpr defaultParseFlags "" Nothing src' of
+>               Left e -> error $ show e
+>               Right l -> resetAnnotations l
+>   (if astrw /= ast'
+>       then trace ("\n***************** expected\n" ++
+>                   L.unpack (prettyQueryExpr defaultPrettyFlags ast')
+>                   ++ "\n" ++ L.unpack (prettyQueryExpr defaultPrettyFlags astrw)
+>                   ++ "\n\n" ++ groomTypes ast'
+>                   ++ "\n\n" ++ groomTypes astrw
+>                   ++ "\n***************** got\n")
+>       else id) $ H.assertEqual "" ast' astrw
+>   -- check second rewrite is idempotent
+>   {-let astrw2 = resetAnnotations $ typeCheckQueryExpr f cat astrw
+>   (if astrw /= astrw2
+>       then trace ("\nSECOND REWRITE\n***************** expected\n" ++
+>                   prettyQueryExpr defaultPrettyFlags astrw
+>                   ++ "\n" ++ prettyQueryExpr defaultPrettyFlags astrw2
+>                   ++ "\n\n" ++ groomTypes astrw
+>                   ++ "\n\n" ++ groomTypes astrw2
+>                   ++ "\n***************** got\n")
+>       else id) $ assertEqual "second rewrite" astrw astrw2-}
+
+
+> testMatchApp :: Dialect -> Catalog -> [NameComponent]
+>              -> [(TypeExtra, Maybe LitArg)]
+>              -> (Either [TypeError] ([TypeExtra],TypeExtra))
+>              -> T.TestTree
+> testMatchApp d cat f as r = H.testCase (show f ++ show as) $
+>     H.assertEqual "" r $ matchApp d cat f as
+
+
+> canonicalizeTypes :: Data a => Dialect -> a -> a
+> canonicalizeTypes d = transformBi $ \x -> case x of
+>     ScalarType t -> ScalarType $ canonicalizeTypeName d t
+>     _ -> x
+
+> canonicalizeEnvTypes :: Data a => Dialect -> a -> a
+> canonicalizeEnvTypes d = transformBi $ \x -> case x of
+>     TypeExtra (ScalarType t) p s n ->
+>       TypeExtra (ScalarType $ canonicalizeTypeName d t) p s n
+>     _ -> x
+
+~~~~
+TODO
+new idea for testing:
+parsesql -> ast1
+parse, pretty print, parse -> ast2
+load into pg, pg_dump, parse -> ast3
+parse, pretty print, load into pg, pg_dump, parse -> ast4
+check all these asts are the same
+~~~~
diff --git a/tests/Database/HsSqlPpp/Tests/Tests.lhs b/tests/Database/HsSqlPpp/Tests/Tests.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/Tests.lhs
@@ -0,0 +1,15 @@
+
+> module Database.HsSqlPpp.Tests.Tests (allTests) where
+>
+> import Test.Tasty
+>
+> import Database.HsSqlPpp.Tests.Parsing.ParserTests
+
+> import Database.HsSqlPpp.Tests.TypeChecking.TypeCheckTests
+
+> import Database.HsSqlPpp.Tests.TestUtils
+
+> allTests :: [TestTree]
+> allTests = map itemToTft
+>            [parserTestData
+>            ,typeCheckTestData]
diff --git a/tests/Database/HsSqlPpp/Tests/TpchData.lhs b/tests/Database/HsSqlPpp/Tests/TpchData.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TpchData.lhs
@@ -0,0 +1,975 @@
+
+> {-# LANGUAGE QuasiQuotes,OverloadedStrings #-}
+
+> module Database.HsSqlPpp.Tests.TpchData
+>     (tpchQueries
+>     ,tpchCatalog) where
+>
+
+> import Database.HsSqlPpp.Utils.Here
+> import Database.HsSqlPpp.Catalog
+> --import Database.HsSqlPpp.Types
+
+> tpchQueries :: [(String,String)]
+> tpchQueries =
+>   [("Q1",[here|
+\begin{code}
+select
+        l_returnflag,
+        l_linestatus,
+        sum(l_quantity) as sum_qty,
+        sum(l_extendedprice) as sum_base_price,
+        sum(l_extendedprice * (1 - l_discount)) as sum_disc_price,
+        sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge,
+        avg(l_quantity) as avg_qty,
+        avg(l_extendedprice) as avg_price,
+        avg(l_discount) as avg_disc,
+        count(*) as count_order
+from
+        lineitem
+where
+        l_shipdate <= date '1998-12-01' - interval '63' day (3)
+group by
+        l_returnflag,
+        l_linestatus
+order by
+        l_returnflag,
+        l_linestatus;
+--set rowcount -1
+--go
+\end{code}
+>                                     |])
+>   ,("Q2",[here|
+\begin{code}
+
+select
+        s_acctbal,
+        s_name,
+        n_name,
+        p_partkey,
+        p_mfgr,
+        s_address,
+        s_phone,
+        s_comment
+from
+        part,
+        supplier,
+        partsupp,
+        nation,
+        region
+where
+        p_partkey = ps_partkey
+        and s_suppkey = ps_suppkey
+        and p_size = 15
+        and p_type like '%BRASS'
+        and s_nationkey = n_nationkey
+        and n_regionkey = r_regionkey
+        and r_name = 'EUROPE'
+        and ps_supplycost = (
+                select
+                        min(ps_supplycost)
+                from
+                        partsupp,
+                        supplier,
+                        nation,
+                        region
+                where
+                        p_partkey = ps_partkey
+                        and s_suppkey = ps_suppkey
+                        and s_nationkey = n_nationkey
+                        and n_regionkey = r_regionkey
+                        and r_name = 'EUROPE'
+        )
+order by
+        s_acctbal desc,
+        n_name,
+        s_name,
+        p_partkey;
+--set rowcount 100
+--go
+\end{code}
+>                                     |])
+>   ,("Q3",[here|
+\begin{code}
+select
+        l_orderkey,
+        sum(l_extendedprice * (1 - l_discount)) as revenue,
+        o_orderdate,
+        o_shippriority
+from
+        customer,
+        orders,
+        lineitem
+where
+        c_mktsegment = 'MACHINERY'
+        and c_custkey = o_custkey
+        and l_orderkey = o_orderkey
+        and o_orderdate < date '1995-03-21'
+        and l_shipdate > date '1995-03-21'
+group by
+        l_orderkey,
+        o_orderdate,
+        o_shippriority
+order by
+        revenue desc,
+        o_orderdate;
+--set rowcount 10
+--go
+\end{code}
+>                                     |])
+>   ,("Q4",[here|
+\begin{code}
+select
+        o_orderpriority,
+        count(*) as order_count
+from
+        orders
+where
+        o_orderdate >= date '1996-03-01'
+        and o_orderdate < date '1996-03-01' + interval '3' month
+        and exists (
+                select
+                        *
+                from
+                        lineitem
+                where
+                        l_orderkey = o_orderkey
+                        and l_commitdate < l_receiptdate
+        )
+group by
+        o_orderpriority
+order by
+        o_orderpriority;
+--set rowcount -1
+--go
+\end{code}
+>                                     |])
+>   ,("Q5",[here|
+\begin{code}
+select
+        n_name,
+        sum(l_extendedprice * (1 - l_discount)) as revenue
+from
+        customer,
+        orders,
+        lineitem,
+        supplier,
+        nation,
+        region
+where
+        c_custkey = o_custkey
+        and l_orderkey = o_orderkey
+        and l_suppkey = s_suppkey
+        and c_nationkey = s_nationkey
+        and s_nationkey = n_nationkey
+        and n_regionkey = r_regionkey
+        and r_name = 'EUROPE'
+        and o_orderdate >= date '1997-01-01'
+        and o_orderdate < date '1997-01-01' + interval '1' year
+group by
+        n_name
+order by
+        revenue desc;
+--set rowcount -1
+--go
+\end{code}
+>                                     |])
+>   ,("Q6",[here|
+\begin{code}
+select
+        sum(l_extendedprice * l_discount) as revenue
+from
+        lineitem
+where
+        l_shipdate >= date '1997-01-01'
+        and l_shipdate < date '1997-01-01' + interval '1' year
+        and l_discount between 0.07 - 0.01 and 0.07 + 0.01
+        and l_quantity < 24;
+--set rowcount -1
+--go
+\end{code}
+>                                     |])
+>   ,("Q7",[here|
+\begin{code}
+select
+        supp_nation,
+        cust_nation,
+        l_year,
+        sum(volume) as revenue
+from
+        (
+                select
+                        n1.n_name as supp_nation,
+                        n2.n_name as cust_nation,
+                        extract(year from l_shipdate) as l_year,
+                        l_extendedprice * (1 - l_discount) as volume
+                from
+                        supplier,
+                        lineitem,
+                        orders,
+                        customer,
+                        nation n1,
+                        nation n2
+                where
+                        s_suppkey = l_suppkey
+                        and o_orderkey = l_orderkey
+                        and c_custkey = o_custkey
+                        and s_nationkey = n1.n_nationkey
+                        and c_nationkey = n2.n_nationkey
+                        and (
+                                (n1.n_name = 'PERU' and n2.n_name = 'IRAQ')
+                                or (n1.n_name = 'IRAQ' and n2.n_name = 'PERU')
+                        )
+                        and l_shipdate between date '1995-01-01' and date '1996-12-31'
+        ) as shipping
+group by
+        supp_nation,
+        cust_nation,
+        l_year
+order by
+        supp_nation,
+        cust_nation,
+        l_year;
+--set rowcount -1
+--go
+\end{code}
+>                                     |])
+>   ,("Q8",[here|
+\begin{code}
+select
+        o_year,
+        sum(case
+                when nation = 'IRAQ' then volume
+                else 0
+        end) / sum(volume) as mkt_share
+from
+        (
+                select
+                        extract(year from o_orderdate) as o_year,
+                        l_extendedprice * (1 - l_discount) as volume,
+                        n2.n_name as nation
+                from
+                        part,
+                        supplier,
+                        lineitem,
+                        orders,
+                        customer,
+                        nation n1,
+                        nation n2,
+                        region
+                where
+                        p_partkey = l_partkey
+                        and s_suppkey = l_suppkey
+                        and l_orderkey = o_orderkey
+                        and o_custkey = c_custkey
+                        and c_nationkey = n1.n_nationkey
+                        and n1.n_regionkey = r_regionkey
+                        and r_name = 'MIDDLE EAST'
+                        and s_nationkey = n2.n_nationkey
+                        and o_orderdate between date '1995-01-01' and date '1996-12-31'
+                        and p_type = 'STANDARD ANODIZED BRASS'
+        ) as all_nations
+group by
+        o_year
+order by
+        o_year;
+--set rowcount -1
+--go
+
+\end{code}
+>                                     |])
+>   ,("Q9",[here|
+\begin{code}
+
+
+select
+        nation,
+        o_year,
+        sum(amount) as sum_profit
+from
+        (
+                select
+                        n_name as nation,
+                        extract(year from o_orderdate) as o_year,
+                        l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
+                from
+                        part,
+                        supplier,
+                        lineitem,
+                        partsupp,
+                        orders,
+                        nation
+                where
+                        s_suppkey = l_suppkey
+                        and ps_suppkey = l_suppkey
+                        and ps_partkey = l_partkey
+                        and p_partkey = l_partkey
+                        and o_orderkey = l_orderkey
+                        and s_nationkey = n_nationkey
+                        and p_name like '%antique%'
+        ) as profit
+group by
+        nation,
+        o_year
+order by
+        nation,
+        o_year desc;
+--set rowcount -1
+--go
+
+\end{code}
+>                                     |])
+>   ,("Q10",[here|
+\begin{code}
+
+
+select
+        c_custkey,
+        c_name,
+        sum(l_extendedprice * (1 - l_discount)) as revenue,
+        c_acctbal,
+        n_name,
+        c_address,
+        c_phone,
+        c_comment
+from
+        customer,
+        orders,
+        lineitem,
+        nation
+where
+        c_custkey = o_custkey
+        and l_orderkey = o_orderkey
+        and o_orderdate >= date '1993-12-01'
+        and o_orderdate < date '1993-12-01' + interval '3' month
+        and l_returnflag = 'R'
+        and c_nationkey = n_nationkey
+group by
+        c_custkey,
+        c_name,
+        c_acctbal,
+        c_phone,
+        n_name,
+        c_address,
+        c_comment
+order by
+        revenue desc;
+--set rowcount 20
+--go
+
+\end{code}
+>                                     |])
+>   ,("Q11",[here|
+\begin{code}
+
+
+select
+        ps_partkey,
+        sum(ps_supplycost * ps_availqty) as value
+from
+        partsupp,
+        supplier,
+        nation
+where
+        ps_suppkey = s_suppkey
+        and s_nationkey = n_nationkey
+        and n_name = 'CHINA'
+group by
+        ps_partkey having
+                sum(ps_supplycost * ps_availqty) > (
+                        select
+                                sum(ps_supplycost * ps_availqty) * 0.0001000000
+                        from
+                                partsupp,
+                                supplier,
+                                nation
+                        where
+                                ps_suppkey = s_suppkey
+                                and s_nationkey = n_nationkey
+                                and n_name = 'CHINA'
+                )
+order by
+        value desc;
+--set rowcount -1
+--go
+
+\end{code}
+>                                     |])
+>   ,("Q12",[here|
+\begin{code}
+
+
+select
+        l_shipmode,
+        sum(case
+                when o_orderpriority = '1-URGENT'
+                        or o_orderpriority = '2-HIGH'
+                        then 1
+                else 0
+        end) as high_line_count,
+        sum(case
+                when o_orderpriority <> '1-URGENT'
+                        and o_orderpriority <> '2-HIGH'
+                        then 1
+                else 0
+        end) as low_line_count
+from
+        orders,
+        lineitem
+where
+        o_orderkey = l_orderkey
+        and l_shipmode in ('AIR', 'RAIL')
+        and l_commitdate < l_receiptdate
+        and l_shipdate < l_commitdate
+        and l_receiptdate >= date '1994-01-01'
+        and l_receiptdate < date '1994-01-01' + interval '1' year
+group by
+        l_shipmode
+order by
+        l_shipmode;
+--set rowcount -1
+--go
+
+\end{code}
+>                                     |])
+>   ,("Q13",[here|
+\begin{code}
+
+
+select
+        c_count,
+        count(*) as custdist
+from
+        (
+                select
+                        c_custkey,
+                        count(o_orderkey)
+                from
+                        customer left outer join orders on
+                                c_custkey = o_custkey
+                                and o_comment not like '%pending%requests%'
+                group by
+                        c_custkey
+        ) as c_orders (c_custkey, c_count)
+group by
+        c_count
+order by
+        custdist desc,
+        c_count desc;
+--set rowcount -1
+--go
+
+\end{code}
+>                                     |])
+>   ,("Q14",[here|
+\begin{code}
+
+select
+        100.00 * sum(case
+                when p_type like 'PROMO%'
+                        then l_extendedprice * (1 - l_discount)
+                else 0
+        end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue
+from
+        lineitem,
+        part
+where
+        l_partkey = p_partkey
+        and l_shipdate >= date '1994-12-01'
+        and l_shipdate < date '1994-12-01' + interval '1' month;
+--set rowcount -1
+--go
+
+\end{code}
+>                                     |])
+>   ,("Q15",[here|
+\begin{code}
+
+/*create view revenue0 (supplier_no, total_revenue) as
+        select
+                l_suppkey,
+                sum(l_extendedprice * (1 - l_discount))
+        from
+                lineitem
+        where
+                l_shipdate >= date '1995-06-01'
+                and l_shipdate < date '1995-06-01' + interval '3' month
+        group by
+                l_suppkey;*/
+
+with
+revenue0 as
+        (select
+                l_suppkey as supplier_no,
+                sum(l_extendedprice * (1 - l_discount)) as total_revenue
+        from
+                lineitem
+        where
+                l_shipdate >= date '1995-06-01'
+                and l_shipdate < date '1995-06-01' + interval '3' month
+        group by
+                l_suppkey)
+select
+        s_suppkey,
+        s_name,
+        s_address,
+        s_phone,
+        total_revenue
+from
+        supplier,
+        revenue0
+where
+        s_suppkey = supplier_no
+        and total_revenue = (
+                select
+                        max(total_revenue)
+                from
+                        revenue0
+        )
+order by
+        s_suppkey;
+
+--drop view revenue0;
+--set rowcount -1
+--go
+
+\end{code}
+>                                     |])
+>   ,("Q16",[here|
+\begin{code}
+
+
+select
+        p_brand,
+        p_type,
+        p_size,
+        count(distinct ps_suppkey) as supplier_cnt
+from
+        partsupp,
+        part
+where
+        p_partkey = ps_partkey
+        and p_brand <> 'Brand#15'
+        and p_type not like 'MEDIUM BURNISHED%'
+        and p_size in (39, 26, 18, 45, 19, 1, 3, 9)
+        and ps_suppkey not in (
+                select
+                        s_suppkey
+                from
+                        supplier
+                where
+                        s_comment like '%Customer%Complaints%'
+        )
+group by
+        p_brand,
+        p_type,
+        p_size
+order by
+        supplier_cnt desc,
+        p_brand,
+        p_type,
+        p_size;
+--set rowcount -1
+--go
+
+\end{code}
+>                                     |])
+>   ,("Q17",[here|
+\begin{code}
+
+
+select
+        sum(l_extendedprice) / 7.0 as avg_yearly
+from
+        lineitem,
+        part
+where
+        p_partkey = l_partkey
+        and p_brand = 'Brand#52'
+        and p_container = 'JUMBO CAN'
+        and l_quantity < (
+                select
+                        0.2 * avg(l_quantity)
+                from
+                        lineitem
+                where
+                        l_partkey = p_partkey
+        );
+--set rowcount -1
+--go
+
+\end{code}
+>                                     |])
+>   ,("Q18",[here|
+\begin{code}
+
+
+select
+        c_name,
+        c_custkey,
+        o_orderkey,
+        o_orderdate,
+        o_totalprice,
+        sum(l_quantity)
+from
+        customer,
+        orders,
+        lineitem
+where
+        o_orderkey in (
+                select
+                        l_orderkey
+                from
+                        lineitem
+                group by
+                        l_orderkey having
+                                sum(l_quantity) > 313
+        )
+        and c_custkey = o_custkey
+        and o_orderkey = l_orderkey
+group by
+        c_name,
+        c_custkey,
+        o_orderkey,
+        o_orderdate,
+        o_totalprice
+order by
+        o_totalprice desc,
+        o_orderdate;
+--set rowcount 100
+--go
+
+\end{code}
+>                                     |])
+>   ,("Q19",[here|
+\begin{code}
+
+
+select
+        sum(l_extendedprice* (1 - l_discount)) as revenue
+from
+        lineitem,
+        part
+where
+        (
+                p_partkey = l_partkey
+                and p_brand = 'Brand#43'
+                and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG')
+                and l_quantity >= 3 and l_quantity <= 3 + 10
+                and p_size between 1 and 5
+                and l_shipmode in ('AIR', 'AIR REG')
+                and l_shipinstruct = 'DELIVER IN PERSON'
+        )
+        or
+        (
+                p_partkey = l_partkey
+                and p_brand = 'Brand#25'
+                and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK')
+                and l_quantity >= 10 and l_quantity <= 10 + 10
+                and p_size between 1 and 10
+                and l_shipmode in ('AIR', 'AIR REG')
+                and l_shipinstruct = 'DELIVER IN PERSON'
+        )
+        or
+        (
+                p_partkey = l_partkey
+                and p_brand = 'Brand#24'
+                and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG')
+                and l_quantity >= 22 and l_quantity <= 22 + 10
+                and p_size between 1 and 15
+                and l_shipmode in ('AIR', 'AIR REG')
+                and l_shipinstruct = 'DELIVER IN PERSON'
+        );
+--set rowcount -1
+--go
+
+\end{code}
+>                                     |])
+>   ,("Q20",[here|
+\begin{code}
+
+
+select
+        s_name,
+        s_address
+from
+        supplier,
+        nation
+where
+        s_suppkey in (
+                select
+                        ps_suppkey
+                from
+                        partsupp
+                where
+                        ps_partkey in (
+                                select
+                                        p_partkey
+                                from
+                                        part
+                                where
+                                        p_name like 'lime%'
+                        )
+                        and ps_availqty > (
+                                select
+                                        0.5 * sum(l_quantity)
+                                from
+                                        lineitem
+                                where
+                                        l_partkey = ps_partkey
+                                        and l_suppkey = ps_suppkey
+                                        and l_shipdate >= date '1994-01-01'
+                                        and l_shipdate < date '1994-01-01' + interval '1' year
+                        )
+        )
+        and s_nationkey = n_nationkey
+        and n_name = 'VIETNAM'
+order by
+        s_name;
+--set rowcount -1
+--go
+
+\end{code}
+>                                     |])
+>   ,("Q21",[here|
+\begin{code}
+
+
+select
+        s_name,
+        count(*) as numwait
+from
+        supplier,
+        lineitem l1,
+        orders,
+        nation
+where
+        s_suppkey = l1.l_suppkey
+        and o_orderkey = l1.l_orderkey
+        and o_orderstatus = 'F'
+        and l1.l_receiptdate > l1.l_commitdate
+        and exists (
+                select
+                        *
+                from
+                        lineitem l2
+                where
+                        l2.l_orderkey = l1.l_orderkey
+                        and l2.l_suppkey <> l1.l_suppkey
+        )
+        and not exists (
+                select
+                        *
+                from
+                        lineitem l3
+                where
+                        l3.l_orderkey = l1.l_orderkey
+                        and l3.l_suppkey <> l1.l_suppkey
+                        and l3.l_receiptdate > l3.l_commitdate
+        )
+        and s_nationkey = n_nationkey
+        and n_name = 'INDIA'
+group by
+        s_name
+order by
+        numwait desc,
+        s_name;
+--set rowcount 100
+--go
+
+\end{code}
+>                                     |])
+>   ,("Q22",[here|
+\begin{code}
+
+
+select
+        cntrycode,
+        count(*) as numcust,
+        sum(c_acctbal) as totacctbal
+from
+        (
+                select
+                        substring(c_phone from 1 for 2) as cntrycode,
+                        c_acctbal
+                from
+                        customer
+                where
+                        substring(c_phone from 1 for 2) in
+                                ('41', '28', '39', '21', '24', '29', '44')
+                        and c_acctbal > (
+                                select
+                                        avg(c_acctbal)
+                                from
+                                        customer
+                                where
+                                        c_acctbal > 0.00
+                                        and substring(c_phone from 1 for 2) in
+                                                ('41', '28', '39', '21', '24', '29', '44')
+                        )
+                        and not exists (
+                                select
+                                        *
+                                from
+                                        orders
+                                where
+                                        o_custkey = c_custkey
+                        )
+        ) as custsale
+group by
+        cntrycode
+order by
+        cntrycode;
+--set rowcount -1
+--go
+
+\end{code}
+>                                     |])
+>   ]
+
+
+> tpchCatalog :: [CatalogUpdate]
+> tpchCatalog =
+
+CREATE TABLE NATION  ( N_NATIONKEY  INTEGER NOT NULL,
+                            N_NAME       CHAR(25) NOT NULL,
+                            N_REGIONKEY  INTEGER NOT NULL,
+                            N_COMMENT    VARCHAR(152));
+
+>   [CatCreateTable ("public","nation") [("n_nationkey", mkCatNameExtra "integer")
+>                            ,("n_name", mkCatNameExtra "char")
+>                            ,("n_regionkey", mkCatNameExtra "integer")
+>                            ,("n_comment", mkCatNameExtra "varchar")]
+
+CREATE TABLE REGION  ( R_REGIONKEY  INTEGER NOT NULL,
+                            R_NAME       CHAR(25) NOT NULL,
+                            R_COMMENT    VARCHAR(152));
+
+>   ,CatCreateTable ("public","region") [("r_regionkey", mkCatNameExtra "integer")
+>                           ,("r_name", mkCatNameExtra "char")
+>                           ,("r_comment", mkCatNameExtra "varchar")]
+
+CREATE TABLE PART  ( P_PARTKEY     INTEGER NOT NULL,
+                          P_NAME        VARCHAR(55) NOT NULL,
+                          P_MFGR        CHAR(25) NOT NULL,
+                          P_BRAND       CHAR(10) NOT NULL,
+                          P_TYPE        VARCHAR(25) NOT NULL,
+                          P_SIZE        INTEGER NOT NULL,
+                          P_CONTAINER   CHAR(10) NOT NULL,
+                          P_RETAILPRICE DECIMAL(15,2) NOT NULL,
+                          P_COMMENT     VARCHAR(23) NOT NULL );
+
+>   ,CatCreateTable ("public","part") [("p_partkey", mkCatNameExtra "integer")
+>                          ,("p_name", mkCatNameExtra "varchar")
+>                          ,("p_mfgr", mkCatNameExtra "char")
+>                          ,("p_brand", mkCatNameExtra "char")
+>                          ,("p_type", mkCatNameExtra "varchar")
+>                          ,("p_size", mkCatNameExtra "integer")
+>                          ,("p_container", mkCatNameExtra "char")
+>                          ,("p_retailprice", mkCatNameExtra "numeric")
+>                          ,("p_comment", mkCatNameExtra "varchar")]
+
+CREATE TABLE SUPPLIER ( S_SUPPKEY     INTEGER NOT NULL,
+                             S_NAME        CHAR(25) NOT NULL,
+                             S_ADDRESS     VARCHAR(40) NOT NULL,
+                             S_NATIONKEY   INTEGER NOT NULL,
+                             S_PHONE       CHAR(15) NOT NULL,
+                             S_ACCTBAL     DECIMAL(15,2) NOT NULL,
+                             S_COMMENT     VARCHAR(101) NOT NULL);
+
+>   ,CatCreateTable ("public","supplier") [("s_suppkey", mkCatNameExtra "integer")
+>                              ,("s_name", mkCatNameExtra "char")
+>                              ,("s_address", mkCatNameExtra "varchar")
+>                              ,("s_nationkey", mkCatNameExtra "integer")
+>                              ,("s_phone", mkCatNameExtra "char")
+>                              ,("s_acctbal", mkCatNameExtra "numeric")
+>                              ,("s_comment", mkCatNameExtra "varchar")]
+
+
+CREATE TABLE PARTSUPP ( PS_PARTKEY     INTEGER NOT NULL,
+                             PS_SUPPKEY     INTEGER NOT NULL,
+                             PS_AVAILQTY    INTEGER NOT NULL,
+                             PS_SUPPLYCOST  DECIMAL(15,2)  NOT NULL,
+                             PS_COMMENT     VARCHAR(199) NOT NULL );
+
+>   ,CatCreateTable ("public","partsupp") [("ps_partkey", mkCatNameExtra "integer")
+>                              ,("ps_suppkey", mkCatNameExtra "integer")
+>                              ,("ps_availqty", mkCatNameExtra "integer")
+>                              ,("ps_supplycost", mkCatNameExtra "numeric")
+>                              ,("ps_comment", mkCatNameExtra "varchar")]
+
+CREATE TABLE CUSTOMER ( C_CUSTKEY     INTEGER NOT NULL,
+                             C_NAME        VARCHAR(25) NOT NULL,
+                             C_ADDRESS     VARCHAR(40) NOT NULL,
+                             C_NATIONKEY   INTEGER NOT NULL,
+                             C_PHONE       CHAR(15) NOT NULL,
+                             C_ACCTBAL     DECIMAL(15,2)   NOT NULL,
+                             C_MKTSEGMENT  CHAR(10) NOT NULL,
+                             C_COMMENT     VARCHAR(117) NOT NULL);
+
+>   ,CatCreateTable ("public","customer") [("c_custkey", mkCatNameExtra "integer")
+>                              ,("c_name", mkCatNameExtra "char")
+>                              ,("c_address", mkCatNameExtra "varchar")
+>                              ,("c_nationkey", mkCatNameExtra "integer")
+>                              ,("c_phone", mkCatNameExtra "char")
+>                              ,("c_acctbal", mkCatNameExtra "numeric")
+>                              ,("c_mktsegment", mkCatNameExtra "char")
+>                              ,("c_comment", mkCatNameExtra "varchar")]
+
+
+CREATE TABLE ORDERS  ( O_ORDERKEY       INTEGER NOT NULL,
+                           O_CUSTKEY        INTEGER NOT NULL,
+                           O_ORDERSTATUS    CHAR(1) NOT NULL,
+                           O_TOTALPRICE     DECIMAL(15,2) NOT NULL,
+                           O_ORDERDATE      DATE NOT NULL,
+                           O_ORDERPRIORITY  CHAR(15) NOT NULL,  
+                           O_CLERK          CHAR(15) NOT NULL, 
+                           O_SHIPPRIORITY   INTEGER NOT NULL,
+                           O_COMMENT        VARCHAR(79) NOT NULL);
+
+>   ,CatCreateTable ("public","orders") [("o_orderkey", mkCatNameExtra "integer")
+>                            ,("o_custkey", mkCatNameExtra "integer")
+>                            ,("o_orderstatus", mkCatNameExtra "char")
+>                            ,("o_totalprice", mkCatNameExtra "numeric")
+>                            ,("o_orderdate", mkCatNameExtra "date")
+>                            ,("o_orderpriority", mkCatNameExtra "char")
+>                            ,("o_clerk", mkCatNameExtra "char")
+>                            ,("o_shippriority", mkCatNameExtra "integer")
+>                            ,("o_comment", mkCatNameExtra "varchar")]
+
+
+CREATE TABLE LINEITEM ( L_ORDERKEY    INTEGER NOT NULL,
+                             L_PARTKEY     INTEGER NOT NULL,
+                             L_SUPPKEY     INTEGER NOT NULL,
+                             L_LINENUMBER  INTEGER NOT NULL,
+                             L_QUANTITY    DECIMAL(15,2) NOT NULL,
+                             L_EXTENDEDPRICE  DECIMAL(15,2) NOT NULL,
+                             L_DISCOUNT    DECIMAL(15,2) NOT NULL,
+                             L_TAX         DECIMAL(15,2) NOT NULL,
+                             L_RETURNFLAG  CHAR(1) NOT NULL,
+                             L_LINESTATUS  CHAR(1) NOT NULL,
+                             L_SHIPDATE    DATE NOT NULL,
+                             L_COMMITDATE  DATE NOT NULL,
+                             L_RECEIPTDATE DATE NOT NULL,
+                             L_SHIPINSTRUCT CHAR(25) NOT NULL,
+                             L_SHIPMODE     CHAR(10) NOT NULL,
+                             L_COMMENT      VARCHAR(44) NOT NULL);
+
+>   ,CatCreateTable ("public","lineitem") [("l_orderkey", mkCatNameExtra "integer")
+>                              ,("l_partkey", mkCatNameExtra "integer")
+>                              ,("l_suppkey", mkCatNameExtra "integer")
+>                              ,("l_linenumber", mkCatNameExtra "integer")
+>                              ,("l_quantity", mkCatNameExtra "numeric")
+>                              ,("l_extendedprice", mkCatNameExtra "numeric")
+>                              ,("l_discount", mkCatNameExtra "numeric")
+>                              ,("l_tax", mkCatNameExtra "numeric")
+>                              ,("l_returnflag", mkCatNameExtra "char")
+>                              ,("l_linestatus", mkCatNameExtra "char")
+>                              ,("l_shipdate", mkCatNameExtra "date")
+>                              ,("l_commitdate", mkCatNameExtra "date")
+>                              ,("l_receiptdate", mkCatNameExtra "date")
+>                              ,("l_shipinstruct", mkCatNameExtra "char")
+>                              ,("l_shipmode", mkCatNameExtra "char")
+>                              ,("l_comment", mkCatNameExtra "varchar")]
+
+>   ]
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/Aggregates.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/Aggregates.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/Aggregates.lhs
@@ -0,0 +1,51 @@
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.Aggregates
+>     (aggregates) where
+
+> import Database.HsSqlPpp.Tests.TestTypes
+> import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Catalog
+> import Database.HsSqlPpp.Dialect
+> --import Database.HsSqlPpp.Internals.TypesInternal
+> --import Database.HsSqlPpp.TypeChecker
+> import Database.HsSqlPpp.Tests.TypeChecking.Utils
+> --import Database.HsSqlPpp.Internals.TypesInternal hiding (mkTypeExtra,mkTypeExtraNN)
+
+dodgy hack to support cube:
+special case the cube
+
+only support case where the group by consists of a single cube or
+ordinary groups
+no nested groups in the cube
+type check
+group by cube(a,b,...)
+as if it was written
+group by a,b,...
+
+TODO: deal with types, null, rollup,cube, grouping sets, nested groups
+and flexible combinations
+
+> aggregates :: Item
+> aggregates =
+>   Group "aggregates"
+>   [tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                                  ,("b", mkCatNameExtra "int4")
+>                                  ,("c", mkCatNameExtra "int4")]]
+>    "select a,b,count(c) as c from t group by a,b"
+>    $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                            ,("b", mkTypeExtra typeInt)
+>                            ,("c", mkTypeExtraNN typeBigInt)]
+>   ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                                  ,("b", mkCatNameExtra "int4")
+>                                  ,("c", mkCatNameExtra "int4")]]
+>    "select a,b,count(c) as c from t group by cube(a,b)"
+>    $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                            ,("b", mkTypeExtra typeInt)
+>                            ,("c", mkTypeExtraNN typeBigInt)]
+>   ]
+>   where
+>     tcQueryExpr cus =
+>         let cat = makeCatalog postgresDialect cus
+>         in TCQueryExpr cat defaultTypeCheckFlags {tcfDialect=postgresDialect}
+>     typeInt = ScalarType "int4"
+>     typeBigInt = ScalarType "int8"
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/AnsiScalarExprs.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/AnsiScalarExprs.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/AnsiScalarExprs.lhs
@@ -0,0 +1,365 @@
+
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.AnsiScalarExprs
+>     (ansiScalarExprs) where
+
+> import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Internals.TypesInternal
+> import Database.HsSqlPpp.Tests.TestTypes
+> import Database.HsSqlPpp.Catalog
+> import Database.HsSqlPpp.Dialect
+> --import Database.HsSqlPpp.Internals.TypeChecking.Environment
+> --import Database.HsSqlPpp.Tests.TypeChecking.Utils
+> import qualified Data.Text.Lazy as T
+
+> ansiScalarExprs :: Item
+> ansiScalarExprs =
+>   Group "ansiScalarExprs"
+>   [Group "sanity"
+>    [
+>      -- todo: these should be unknown
+>     se "1" $ Right $ ScalarType "int" -- Right UnknownType
+>    ,se "1.1" $ Right $ ScalarType "numeric" -- Right UnknownType
+>    ,se "'test'" $ Right UnknownType
+>    ,se "null" $ Right UnknownType
+>    ,se "true" $ Right $ ScalarType "boolean"
+>    ,se "false" $ Right $ ScalarType "boolean"
+
+>    ,se "null" $ Right UnknownType
+
+
+typedstringlit
+
+>    ,se "int '3'" $ Right $ ScalarType "int"
+
+interval
+
+>    ,se "interval '3' day" $ Right $ ScalarType "interval"
+
+identifier
+
+>    ,see [("a", mkTypeExtra $ ScalarType "int")]
+>         "a" $ Right $ ScalarType "int"
+
+star: not here
+qstar: not here
+
+positional arg: not supported in this dialect
+placeholder,hostparameter
+
+>    ,se "?" $ Right UnknownType
+
+>    -- not sure how this should work
+>    -- todo: not currently supported in the parser
+>    --,se ":test" $ Right UnknownType
+
+
+cast
+
+
+>   ,see [("a", mkTypeExtra $ ScalarType "float")]
+>        "cast(a as real)" $ Right $ ScalarType "real"
+
+implicit cast: not here
+
+case x 2
+
+>   ,see [("a", mkTypeExtra $ ScalarType "int")
+>        ,("b", mkTypeExtra $ ScalarType "int")
+>        ,("c", mkTypeExtra $ ScalarType "int")]
+>    "case a when 1 then b else c end" $ Right $ ScalarType "int"
+
+>   ,see [("a", mkTypeExtra $ ScalarType "int")
+>        ,("b", mkTypeExtra $ ScalarType "int")
+>        ,("c", mkTypeExtra $ ScalarType "int")]
+>    "case when a=1 then b else c end" $ Right $ ScalarType "int"
+
+
+parens
+
+>    ,see [("a", mkTypeExtra $ ScalarType "int")]
+>         "(a)" $ Right $ ScalarType "int"
+
+
+in predicate: just the list version here
+  query version tested elsewhere
+
+
+>    ,see [("a", mkTypeExtra $ ScalarType "int")]
+>     "a in (1,2,3)" $ Right $ ScalarType "boolean"
+
+>    ]
+
+subqueries: test these elsewhere
+quantified comparison: test these elsewhere
+match: test this elsewhere
+
+TODO: arrays
+how should these work, want something better than the idiosyncratic
+postgres way of supporting arrays
+array select
+array ctor
+
+TODO: collate, needs some typechecking on collations, which needs more
+catalog stuff
+
+todo: multiset ops
+
+>
+>
+
+todo: 6.9 grouping
+
+todo: 6.10 window function stuff
+
+todo: 6.11 nested window?
+
+6.12 case
+
+todo: these should be 'polymorphic' and work with non built in types
+also
+
+>    ,Group "case abbreviation simple" $
+>     [see [("a", mkTypeExtra $ ScalarType t)
+>          ,("b", mkTypeExtra $ ScalarType t)]
+>      "nullif(a,b)"
+>      $ Right $ ScalarType t
+>     | t <- allTypes]
+>     ++
+>     [see [("a", mkTypeExtra $ ScalarType t)
+>          ,("b", mkTypeExtra $ ScalarType t)
+>          ,("c", mkTypeExtra $ ScalarType t)]
+>      (T.pack $ "coalesce(" ++ args ++ ")") $ Right $ ScalarType t
+>      | args <- ["a","a,b","a,b,c"]
+>      , t <- allTypes ]
+
+
+todo: normal cases
+
+6.13 cast
+
+
+>    ,Group "cast simple" $
+>     [see [("a", mkTypeExtra $ ScalarType "int")
+>          ,("b", mkTypeExtra $ ScalarType "varchar")]
+>      "cast(b as int)"
+>      $ Right $ ScalarType "int"
+>     ,see [("a", mkTypeExtra $ ScalarType "int")
+>          ,("b", mkTypeExtra $ ScalarType "varchar")]
+>      "cast(a as varchar)"
+>      $ Right $ ScalarType "varchar"
+>     ,see [("a", mkTypeExtra $ ScalarType "int")
+>          ,("b", mkTypeExtra $ ScalarType "varchar")]
+>      "cast(a as character)"
+>      $ Right $ ScalarType "char"
+>     ]
+
+todo: 6.14 next value for
+
+todo: 6.15 field reference
+
+todo: 6.24 array element reference
+
+todo: 6.25 multiset element reference
+
+6.27 numeric value expression
+
+>    ,Group "numeric value expression simple"
+>     [see [("a", mkTypeExtra $ ScalarType t)
+>          ,("b", mkTypeExtra $ ScalarType t)]
+>      e $ Right $ ScalarType t
+>      | e <- ["+a","-a","a+b","a-b","a*b","a/b"]
+>      , t <- numericTypes ]
+
+6.28 numeric value function
+
+todo: position
+
+>    ,Group "numeric value function simple" $
+>    [see [("a", mkTypeExtra $ ScalarType t)]
+>      e $ Right $ ScalarType "int"
+>      | e <- ["char_length(a)", "character_length(a)"
+>             ,"octet_length(a)"]
+>      , t <- textTypes ]
+
+todo: char_length with using
+
+>    ++
+>    [see [("a", mkTypeExtra $ ScalarType t)]
+>      (T.pack $ "extract(" ++ f ++ " from a)")
+>       $ Right $ ScalarType "int"
+>      | f <- ["TIMEZONE_HOUR","TIMEZONE_MINUTE"
+>             ,"SECOND"
+>             ,"YEAR"
+>             ,"MONTH"
+>             ,"DAY"
+>             ,"HOUR"
+>             ,"MINUTE"]
+>      , t <- datetimeTypes ]
+
+todo: cardinality
+todo: array_max_cardinality
+
+
+>     ++
+>     [see [("a", mkTypeExtra $ ScalarType t)]
+>      e $ Right $ ScalarType t
+>      | e <- ["abs(a)"]
+>      , t <- numericTypes ]
+
+question: what types are supported by mod??
+the standard says 'exact numeric with scale 0'
+postgres does for all integer + numeric
+
+>     ++
+>     [see [("a", mkTypeExtra $ ScalarType t)
+>          ,("b", mkTypeExtra $ ScalarType t)]
+>      e $ Right $ ScalarType t
+>      | e <- ["mod(a,b)"]
+>      , t <- ["numeric", "smallint", "int", "bigint"] ]
+
+supports ln,exp,pow,sqrt for single and double precision
+
+standard says implementation defined approximate precision, which
+could mean float or real, or just one, or something else I think
+
+>     ++
+>     [see [("a", mkTypeExtra $ ScalarType t)]
+>      (T.pack (fn ++ "(a)")) $ Right $ ScalarType t
+>      | t <- ["float","real"]
+>      , fn <- ["ln","exp","pow","sqrt"] ]
+
+floor and ceiling, same as ln et al, but with numeric also
+
+>     ++
+>     [see [("a", mkTypeExtra $ ScalarType t)]
+>      (T.pack (fn ++ "(a)")) $ Right $ ScalarType t
+>      | t <- ["float","real", "numeric"]
+>      , fn <- ["floor","ceil","ceiling"] ]
+
+todo: width bucket not working - needs a special case in the precision
+stuff
+
+>     {- ++
+>     [see [("a", mkTypeExtra $ ScalarType t)
+>          ,("b", mkTypeExtra $ ScalarType t)
+>          ,("c", mkTypeExtra $ ScalarType t)
+>          ,("d", mkTypeExtra $ ScalarType "numeric")
+>          ]
+>      "width_bucket(a,b,c,d)" $ Right $ ScalarType "numeric"
+>      | t <- allTypes ] -}
+
+
+
+6.29 string value expression
+
+>    ,Group "string value expression simple" $
+>     [see [("a", (mkTypeExtra (ScalarType t)) {tePrecision = Just 5})
+>          ,("b", (mkTypeExtra (ScalarType t)) {tePrecision = Just 5})]
+>      "a || b" $ Right $ ScalarType t
+>      | t <- textTypes ++ binaryTypes ]
+
+todo: collate
+
+6.30 string value function
+
+>    ,Group "string value expression simple" (
+>    [see [("a", mkTypeExtra $ ScalarType t)
+>         ,("b", mkTypeExtra $ ScalarType "int")
+>         ,("c", mkTypeExtra $ ScalarType "int")]
+>      fn $ Right $ ScalarType t
+>      | fn <- ["substring(a from b for c)"
+>               -- todo: support other substring variations
+>              {-,"substring(a from b)"-}]
+>      , t <- textTypes ] ++
+>    [see [("a", mkTypeExtra $ ScalarType t)]
+>      (T.pack (fn ++ "(a)")) $ Right $ ScalarType t
+>      | fn <- ["upper","lower"]
+>      , t <- textTypes ])
+
+todo: convert
+todo: translate
+
+todo: trim
+
+todo: overlay
+
+todo: normalize
+
+binary: substring, trim, overlay
+
+6.31 <datetime value expression>
+
+>    ,Group "numeric value expression simple"
+>     [see [("a", mkTypeExtra $ ScalarType dt)
+>          ,("b", mkTypeExtra $ ScalarType "interval")]
+>      e $ Right $ ScalarType dt
+>      | e <- ["b+a","a+b","a-b"]
+>      , dt <- datetimeTypes ]
+
+todo: timezone stuff
+
+todo: 6.32 <datetime value function>
+
+6.33 <interval value expression>
+
+>    ,Group "numeric value expression simple"
+>     [see [("a", mkTypeExtra $ ScalarType "interval")
+>          ,("b", mkTypeExtra $ ScalarType "interval")
+>          ,("c", mkTypeExtra $ ScalarType "interval")
+>          ]
+>      e $ Right $ ScalarType "interval"
+>      | e <- ["a+b","a-b", "+a","-a"]]
+
+todo:
+  | <left paren> <datetime value expression> <minus sign> <datetime term> <right paren>
+      <interval qualifier>
+
+
+-----
+specialops
+
+special functions
+
+functions
+
+aggs
+
+windows
+
+typealias checking
+
+implicit casting:
+case
+greatest,least
+ops, fns, etc.
+in list
+how to test these well enough?
+
+anomalies
+  bad casts
+  interval?
+  type match fails in implicit castings
+
+
+
+
+
+>   ]
+>   where
+>     se = TCScalExpr (diDefaultCatalog ansiDialect) emptyEnvironment
+>                     defaultTypeCheckFlags {tcfDialect=ansiDialect}
+>     see env = TCScalExpr (diDefaultCatalog ansiDialect) (selListEnv env)
+>               defaultTypeCheckFlags {tcfDialect=ansiDialect}
+>     selListEnv env = either (const brokeEnvironment) id
+>                      $ envSelectListEnvironment env
+>     numericTypes = ["numeric", "decimal", "smallint", "int", "bigint", "float", "real"]
+>     textTypes = ["char","varchar","clob","nchar","nvarchar","nclob"]
+>     binaryTypes = ["binary","varbinary","blob"]
+>     datetimeTypes = ["date","time","timestamp","interval"]
+>     allTypes = numericTypes
+>                ++ textTypes
+>                ++ binaryTypes
+>                ++ ["boolean"]
+>                ++ datetimeTypes
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/CaseExpressions.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/CaseExpressions.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/CaseExpressions.lhs
@@ -0,0 +1,62 @@
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.CaseExpressions
+>     (caseExpressions) where
+>
+> import Database.HsSqlPpp.Tests.TestTypes
+> import Database.HsSqlPpp.Internals.TypesInternal hiding (mkTypeExtra,mkTypeExtraNN)
+
+
+> --import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Dialect
+>
+>
+> caseExpressions :: Item
+> caseExpressions =
+>   Group "case expressions" [
+>       e "case\n\
+>         \ when true then 1\n\
+>         \end" $ Right typeInt
+>      ,e "case\n\
+>         \ when 1=2 then 'stuff'\n\
+>         \ when 2=3 then 'blah'\n\
+>         \ else 'test'\n\
+>         \end" $ Right UnknownType
+>      ,e "case\n\
+>         \ when 1=2 then 'stuff'\n\
+>         \ when 2=3 then 'blah'\n\
+>         \ else 'test'::text\n\
+>         \end" $ Right $ ScalarType "text"
+>      ,e "case\n\
+>         \ when 1=2 then 'stuff'\n\
+>         \ when true=3 then 'blah'\n\
+>         \ else 'test'\n\
+>         \end" $ Left [NoMatchingOperator "=" [typeBool,typeInt]]
+>      ,e "case\n\
+>         \ when 1=2 then true\n\
+>         \ when 2=3 then false\n\
+>         \ else 1\n\
+>         \end" $ Left [IncompatibleTypeSet [typeBool
+>                                         ,typeBool
+>                                         ,typeInt]]
+>      ,e "case\n\
+>         \ when 1=2 then false\n\
+>         \ when 2=3 then 1\n\
+>         \ else true\n\
+>         \end" $ Left [IncompatibleTypeSet [typeBool
+>                                           ,typeInt
+>                                           ,typeBool]]
+>      ,e "case 1 when 2 then 3 else 4 end" $ Right typeInt
+>      ,e "case 1 when true then 3 else 4 end"
+>             $ Left [IncompatibleTypeSet [ScalarType "int4"
+>                                          ,ScalarType "bool"]]
+>      ,e "case 1 when 2 then true else false end" $ Right typeBool
+>      ,e "case 1 when 2 then 3 else false end"
+>             $ Left [IncompatibleTypeSet [ScalarType "int4"
+>                                          ,ScalarType "bool"]]
+>      ]
+>  where
+>    e = TCScalExpr (diDefaultCatalog postgresDialect) emptyEnvironment
+>            defaultTypeCheckFlags {tcfDialect = postgresDialect}
+>    typeInt = ScalarType "int4"
+>    typeBool = ScalarType "bool"
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/Catalog.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/Catalog.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/Catalog.lhs
@@ -0,0 +1,137 @@
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.Catalog
+>     (catalog) where
+
+> import Database.HsSqlPpp.Internals.Catalog.CatalogNew
+> import Database.HsSqlPpp.Tests.TestTypes
+> --import Database.HsSqlPpp.Internals.TypeChecking.Environment
+> --import Database.HsSqlPpp.Tests.TypeChecking.Utils
+> --import qualified Data.Text.Lazy as T
+> import qualified Test.Tasty.HUnit as H
+> --import qualified Data.Map as M
+> import qualified Data.Set as S
+> import Control.Monad
+
+> catalog :: Item
+> catalog =
+>     Group "catalog"
+>     [
+
+create role
+query to see it there
+
+>      Custom "create role" $ do
+>          let Right c = updateCatalog (CreateRole "me") emptyCatalog
+>          let rs = cRoles c
+>          H.assertEqual "" (S.fromList ["me"]) rs
+>          let Right c1 = updateCatalog (CreateRole "me2") c
+>          let rs1 = cRoles c1
+>          H.assertEqual "" (S.fromList ["me","me2"]) rs1
+
+drop role
+query to see it gone
+
+>     ,Custom "drop role" $ do
+>          let Right c = foldM (flip updateCatalog)
+>                              emptyCatalog
+>                              [CreateRole "me"
+>                              ,CreateRole "me2"]
+>              Right c1 = updateCatalog (DropRole "me" Restrict) c
+>          let rs = cRoles c1
+>          H.assertEqual "" (S.fromList ["me2"]) rs
+>          let Right c2 = updateCatalog (DropRole "me2" Restrict) c
+>          let rs1 = cRoles c2
+>          H.assertEqual "" (S.fromList ["me"]) rs1
+
+
+rename role
+query to see old role gone and new role there
+
+>     ,Custom "rename role" $ do
+>          let Right c = foldM (flip updateCatalog)
+>                              emptyCatalog
+>                              [CreateRole "me"
+>                              ,CreateRole "me2"]
+>              Right c1 = updateCatalog (RenameRole "me" "anotherme") c
+>          let rs = cRoles c1
+>          H.assertEqual "" (S.fromList ["anotherme","me2"]) rs
+
+
+
+todo: check for stuff linked to role
+
+
+
+create role already exists
+
+>     ,Custom "create role already exists" $ do
+>          let Right c = updateCatalog (CreateRole "me") emptyCatalog
+>          H.assertEqual "" (Left $ RoleAlreadyExists "me") $ updateCatalog (CreateRole "me") c
+
+drop role doesn't exist
+
+>     ,Custom "drop role doesn't exist" $ do
+>          let Right c = updateCatalog (CreateRole "me") emptyCatalog
+>          H.assertEqual "" (Left $ RoleNotRecognised "me1")
+>               $ updateCatalog (DropRole "me1" Restrict) c
+
+rename role new already exists
+
+rename role old doesn't exist
+
+rename role old doesn't exist and new exists
+
+
+collation and character sets
+
+create character set
+check it is there
+check the default collation exists and is binary
+
+create character set
+create a collation
+check collation is there
+
+create character set
+create a collation
+set it as default
+delete the binary collation
+check collation is there and is default and binary isn't there
+
+create two collations and check
+
+create two collations and drop one
+
+drop a character set with cascade
+     with restrict
+
+rename character set
+
+rename collation - default
+rename collation - non-default
+
+renames with schema change only
+
+set character set owner
+set collation owner
+
+anomalies for above...
+
+schemas
+sequences
+typeids
+type categories
+external types
+casts
+functions, operators
+windows, aggregates?
+tables
+  a table with a implicitly declared sequence must create a separate
+  sequence in a desugaring process
+views
+domain types
+composite type
+enums
+
+>   ]
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/DDL.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/DDL.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/DDL.lhs
@@ -0,0 +1,40 @@
+
+This file does basic typechecking for DDL. It only covers some ddl at
+the moment.
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.DDL
+>     (ddl) where
+
+> --import Database.HsSqlPpp.Internals.TypesInternal
+> import Database.HsSqlPpp.Tests.TestTypes
+> --import Database.HsSqlPpp.Types
+> --import Database.HsSqlPpp.Catalog
+> --import Database.HsSqlPpp.TypeChecker
+> --import Database.HsSqlPpp.Types
+
+> --import Database.HsSqlPpp.Tests.TypeChecking.Utils
+
+> ddl :: Item
+> ddl =
+>   Group "ddl" []
+
+
+create schema
+alter schema
+drop schema
+
+
+
+create table
+alter table
+drop table
+
+create sequence
+alter sequence
+drop sequence
+
+create view
+drop view
+alter view
+
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/ImplicitCasts.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/ImplicitCasts.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/ImplicitCasts.lhs
@@ -0,0 +1,27 @@
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.ImplicitCasts
+>     (impCasts) where
+
+> import Database.HsSqlPpp.Tests.TestTypes
+> --import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Dialect
+> --import Database.HsSqlPpp.TypeCheck
+> import Data.Text.Lazy ()
+
+
+> impCasts :: Item
+> impCasts =
+>   Group "impCasts"
+>   [e p "'1' + 2" "'1' :: int4 + 2"
+>   ,e p "1.5 :: numeric between 1.1 and 2"
+>        "1.5 :: numeric between 1.1 and 2 :: numeric"
+>   ,e p "'aa'::text = 'bb'"
+>        "'aa'::text = 'bb'::text"
+>   ,e s "cast(1 as int4) + cast('2' as varchar)"
+>        "cast(1 as int4) + cast(cast('2' as varchar) as int4)"
+>   ]
+>   where
+>     e = ImpCastsScalar
+>     p = defaultTypeCheckFlags {tcfDialect=postgresDialect}
+>     s = defaultTypeCheckFlags {tcfDialect=sqlServerDialect}
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/InsertQueryExprs.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/InsertQueryExprs.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/InsertQueryExprs.lhs
@@ -0,0 +1,84 @@
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.InsertQueryExprs
+>     (insertQueryExprs) where
+
+> import Database.HsSqlPpp.Tests.TypeChecking.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+> import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Catalog
+> --import Database.HsSqlPpp.TypeChecker
+> --import Database.HsSqlPpp.Internals.TypesInternal hiding (mkTypeExtra,mkTypeExtraNN)
+
+
+> insertQueryExprs :: Item
+> insertQueryExprs =
+>   Group "insertQueryExpr"
+>       [
+>        -- int to bigint
+>        InsertQueryExpr
+>         [CatCreateTable ("public","t1") [("a", mkCatNameExtra "int4")]
+>         ,CatCreateTable ("public","t2") [("b", mkCatNameExtra "int8")]]
+>         "insert into t2(b) select a from t1;"
+>         $ Right $ CompositeType [("a", mkTypeExtra typeBigInt)]
+>        -- null to not null 
+>       ,InsertQueryExpr
+>         [CatCreateTable ("public","t1") [("a", mkCatNameExtra "int4")]
+>         ,CatCreateTable ("public","t2") [("b", mkCatNameExtraNN "int4")]]
+>         "insert into t2(b) select a from t1;"
+>         $ Right $ CompositeType [("a", mkTypeExtraNN typeInt)]
+>        -- not null to null
+>       ,InsertQueryExpr
+>         [CatCreateTable ("public","t1") [("a", mkCatNameExtraNN "int4")]
+>         ,CatCreateTable ("public","t2") [("b", mkCatNameExtra "int4")]]
+>         "insert into t2(b) select a from t1;"
+>         $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+>        -- implicit column list
+>       ,InsertQueryExpr
+>         [CatCreateTable ("public","t1") [("a", mkCatNameExtraNN "int4")]
+>         ,CatCreateTable ("public","t2") [("b", mkCatNameExtra "int4")]]
+>         "insert into t2 select a from t1;"
+>         $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+
+insert + star - fails, commented out for now
+
+        -- star expansion
+        -- one column - todo: why '?column?'?
+       ,InsertQueryExpr
+         [CatCreateTable ("public","t1") [("a", mkCatNameExtraNN "int4")]
+         ,CatCreateTable ("public","t2") [("b", mkCatNameExtraNN "int8")]]
+         "insert into t2 select * from t1;"
+         $ Right $ CompositeType [("a", mkTypeExtraNN typeBigInt)]
+        -- two columns (not sure what that correct type is)
+       ,InsertQueryExpr
+         [CatCreateTable ("public","t1") [("a", mkCatNameExtraNN "int4"),("b", mkCatNameExtraNN "int4")]
+         ,CatCreateTable ("public","t2") [("c", mkCatNameExtraNN "int8"),("d", mkCatNameExtraNN "int8")]]
+         "insert into t2 select * from t1;"
+         $ Right $ CompositeType [("a", mkTypeExtraNN typeBigInt),("b", mkTypeExtraNN typeBigInt)]
+
+>        -- where (uses outerDownEnv)
+>       ,InsertQueryExpr
+>         [CatCreateTable ("public","t1") [("a", mkCatNameExtraNN "int4")]
+>         ,CatCreateTable ("public","t2") [("b", mkCatNameExtraNN "int4")]]
+>         "insert into t2 select a from t1 where a>0;"
+>         $ Right $ CompositeType [("a", mkTypeExtraNN typeInt)]
+
+>        -- int to bigint - values
+>       ,InsertQueryExpr
+>         [CatCreateTable ("public","t2") [("b", mkCatNameExtra "int8")]]
+>         "insert into t2(b) values (1);"
+>         $ Right $ CompositeType [("values%0", mkTypeExtra typeBigInt)]
+>        -- not null to null - values
+>       ,InsertQueryExpr
+>         [CatCreateTable ("public","t2") [("b", mkCatNameExtra "int4")]]
+>         "insert into t2(b) values (1);"
+>         $ Right $ CompositeType [("values%0", mkTypeExtra typeInt)]
+>       ,InsertQueryExpr
+>         [CatCreateTable ("public","tt") [("b", mkCatNameExtraNN "int4")]
+>         ,CatCreateTable ("public","t") [("d", mkCatNameExtraNN "date")]]
+>         "insert into tt select datepart(day,d) from t;"
+>        $ Right $ CompositeType [("datepart",mkTypeExtraNN typeInt)]
+>       ]
+>   where
+>     typeInt = ScalarType "int4"
+>     typeBigInt = ScalarType "int8"
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/Issues.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/Issues.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/Issues.lhs
@@ -0,0 +1,63 @@
+
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.Issues
+>     (issues) where
+>
+> import Database.HsSqlPpp.Tests.TestTypes
+> --import Database.HsSqlPpp.TypeCheck
+> import Database.HsSqlPpp.Catalog
+> import Database.HsSqlPpp.Dialect
+
+> --import Database.HsSqlPpp.Types
+
+todo: make sure type checking twice doesn't change the tree at all the
+second time - including rewrite versions
+issue with select t.x from tbl t, typecheck is mangling to
+select tbl.x from tbl t.
+
+
+>
+>
+> issues :: Item
+> issues =
+>   Group "issues"
+>   [
+>   -- check that quoted select list aliases don't lose their quotes
+>    let s = "select t.a as \"Quoted\" from t as t(a,b);"
+>    in RewriteQueryExpr defaultTypeCheckFlags {tcfDialect = postgresDialect}
+>         {tcfAddQualifiers = True
+>         ,tcfAddSelectItemAliases = True
+>         ,tcfExpandStars = True
+>         ,tcfAddFullTablerefAliases = True} cat s s
+>    -- check bug with some uuagc code not adding the
+>    -- qualifiers for an identifier properly when
+>    -- the identifier appears on its own at the top level of a select list item
+>   ,r "select a from t as t(a,b);"
+>      "select t.a as a from t as t(a,b);"
+>   -- avoid some gratuitous case changes
+>   ,r "select A from t as t(a,b);"
+>      "select t.A as A from t as t(a,b);"
+>   ,r "select T.A from t as t(a,b);"
+>      "select T.A as A from t as t(a,b);"
+>    -- check not using the alias correctly when qualifying ids
+>   ,r "select tbl.a as a from t as tbl(a,b);"
+>      "select tbl.a as a from t as tbl(a,b);"
+
+>   --,r "select * from t u inner join t1 u1 on u.a=u1.c;"
+>   --   "select * from t u inner join t1 u1 on u.a=u1.c;"
+>   ]
+>   where
+>     r = RewriteQueryExpr defaultTypeCheckFlags {tcfDialect = postgresDialect}
+>         {tcfAddQualifiers = True
+>         ,tcfAddSelectItemAliases = True
+>         ,tcfExpandStars = True
+>         ,tcfAddFullTablerefAliases = True}
+>         cat
+>     cat =
+>         [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                             ,("b", mkCatNameExtra "int4")]
+>         ,CatCreateTable ("public","t1") [("c", mkCatNameExtra "int4")
+>                              ,("d", mkCatNameExtra "int4")]]
+
+
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/Joins.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/Joins.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/Joins.lhs
@@ -0,0 +1,103 @@
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.Joins
+>     (joins) where
+
+> --import Database.HsSqlPpp.Internals.TypesInternal
+> import Database.HsSqlPpp.Tests.TestTypes
+> import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Tests.TypeChecking.Utils
+> import Database.HsSqlPpp.Catalog
+> import Database.HsSqlPpp.Dialect
+> --import Database.HsSqlPpp.Internals.TypesInternal hiding (mkTypeExtra,mkTypeExtraNN)
+
+
+> joins :: Item
+> joins =
+>   Group "joins"
+>   [qe "select * from t0 cross join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                               ,("b", mkTypeExtra $ ScalarType "text")
+>                               ,("c", mkTypeExtra typeInt)
+>                               ,("d", mkTypeExtra $ ScalarType "text")]
+>   ,qe "select a from t0 cross join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+>   ,qe "select b from t0 cross join t1"
+>       $ Right $ CompositeType [("b", mkTypeExtra $ ScalarType "text")]
+>   ,qe "select c from t0 cross join t1"
+>       $ Right $ CompositeType [("c", mkTypeExtra typeInt)]
+>   ,qe "select d from t0 cross join t1"
+>       $ Right $ CompositeType [("d", mkTypeExtra $ ScalarType "text")]
+>   ,qe "select a,b,c,d from t0 cross join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                               ,("b", mkTypeExtra $ ScalarType "text")
+>                               ,("c", mkTypeExtra typeInt)
+>                               ,("d", mkTypeExtra $ ScalarType "text")]
+>
+>   ,qe "select * from (select 1 as a, 2 as b) a\n\
+>       \  cross join (select true as c, 4.5 as d) b;"
+>       $ Right $ CompositeType [("a", mkTypeExtraNN typeInt)
+>                               ,("b", mkTypeExtraNN typeInt)
+>                               ,("c", mkTypeExtraNN typeBool)
+>                               ,("d", mkTypeExtraNN typeNumeric)]
+>   ,qe "select * from (select 1 as a, 2 as b) a\n\
+>       \  inner join (select true as c, 4.5 as d) b on true;"
+>       $ Right $ CompositeType [("a", mkTypeExtraNN typeInt)
+>                               ,("b", mkTypeExtraNN typeInt)
+>                               ,("c", mkTypeExtraNN typeBool)
+>                               ,("d", mkTypeExtraNN typeNumeric)]
+>   ,qe "select * from (select 1 as a, 2 as b) a\n\
+>       \  inner join (select 1 as a, 4.5 as d) b using(a);"
+>       $ Right $ CompositeType [("a", mkTypeExtraNN typeInt)
+>                               ,("b", mkTypeExtraNN typeInt)
+>                               ,("d", mkTypeExtraNN typeNumeric)]
+>   ,qe "select * from (select 1 as a, 2 as b) a\n\
+>         \  natural inner join (select 1 as a, 4.5 as d) b;"
+>        $ Right $ CompositeType [("a", mkTypeExtraNN typeInt)
+>                                ,("b", mkTypeExtraNN typeInt)
+>                                ,("d", mkTypeExtraNN typeNumeric)]
+>         --check the attribute order
+>   ,qe "select * from (select 2 as b, 1 as a) a\n\
+>       \ natural inner join (select 4.5 as d, 1 as a) b;"
+>         $ Right $ CompositeType [("a", mkTypeExtraNN typeInt)
+>                                 ,("b", mkTypeExtraNN typeInt)
+>                                 ,("d", mkTypeExtraNN typeNumeric)]
+>         -- todo: need to fix this so that the star
+>         -- expand error doesn't appear: better error
+>         -- handling in the environment
+>   ,qe "select * from (select 1 as a1, 2 as b) a\n\
+>         \ natural inner join (select true as a1, 4.5 as d) b;"
+>         $ Left [IncompatibleTypeSet [ScalarType "int4"
+>                                     ,ScalarType "bool"]]
+>   ,qe "select * from (select 1 as a1, 2 as b) a\n\
+>         \ natural inner join (select true as a1, 4.5 as d) b;"
+>         $ Left [IncompatibleTypeSet [ScalarType "int4"
+>                                     ,ScalarType "bool"]]
+>   ,qe "select * from (select 1 as a1) a, (select 2 as a2) b;"
+>         $ Right $ CompositeType [("a1", mkTypeExtraNN typeInt)
+>                                 ,("a2", mkTypeExtraNN typeInt)]
+>   -- needs tref aliases in env
+>   ,qe "select * from (select 1 as a1) a, (select 2 as a1) b;"
+>         $ Right $ CompositeType [("a1", mkTypeExtraNN typeInt)
+>                                 ,("a1", mkTypeExtraNN typeInt)]
+>   ,qe "select a1 from (select 1 as a1) a,  (select 2 as a1) b;"
+>         $ Left [AmbiguousIdentifier "a1"]
+
+>   ,qe "select a from t0 inner join t1 on t0.a = t1.c;"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+>   ,qe "select x.a from (select * from t0) x \n\
+>       \ inner join t1 Y on X.a = Y.C"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+
+>   ]
+>   where
+>     qe = tcQueryExpr [CatCreateTable ("public","t0") [("a", mkCatNameExtra "int4")
+>                                         ,("b", mkCatNameExtra "text")]
+>                    ,CatCreateTable ("public","t1") [("c", mkCatNameExtra "int4")
+>                                         ,("d", mkCatNameExtra "text")]]
+>     tcQueryExpr cus =
+>         let cat = makeCatalog postgresDialect cus
+>         in TCQueryExpr cat defaultTypeCheckFlags {tcfDialect = postgresDialect}
+>     typeInt = ScalarType "int4"
+>     typeNumeric = ScalarType "numeric"
+>     typeBool = ScalarType "bool"
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/OdbcTypechecking.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/OdbcTypechecking.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/OdbcTypechecking.lhs
@@ -0,0 +1,116 @@
+
+See the odbcparsing for an overview.
+
+1. date, time, and timestamp literals: these are trivially type
+checked (and we don't check the format of the literal string
+in hssqlppp currently)
+2. scalar function calls: see below
+3. escapes for like strings: not currently supported
+4. outer joins: works like trefparens
+5. calling a procedure: not currently supported
+
+scalar functions
+
+if we write:
+select _f_(a), {fn _g_(b)} from t
+
+the _f_ function is looked up in the usual catalog
+but the _g_ function is looked up in an alternative namespace for
+functions. We can't combine these two namespaces because the valid
+functions are different in each namespace.
+
+So we have to create a special case in the catalog and type checking
+code. Since odbc is old, this is considered a fixed list and is just
+implemented as a separate list of function prototypes to check against
+when you are directly inside a {fn ... } node.
+
+Here is the 'catalog' for odbc scalar functions:
+
+https://msdn.microsoft.com/en-us/library/ms711813(v=vs.85).aspx
+
+
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.OdbcTypechecking (odbcTypechecking) where
+>
+> --import Database.HsSqlPpp.Ast
+> import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Catalog
+> import Database.HsSqlPpp.Dialect
+
+> --import Database.HsSqlPpp.Tests.Parsing.Utils
+> import Database.HsSqlPpp.Tests.TestTypes
+> import Database.HsSqlPpp.Tests.TypeChecking.Utils
+> --import Database.HsSqlPpp.Internals.TypesInternal hiding (mkTypeExtra,mkTypeExtraNN)
+
+> odbcTypechecking:: Item
+> odbcTypechecking =
+>    Group "odbcTypechecking" [
+>        -- literals
+>        scalExpr "{d '2000-01-01'}" $ Right typeDate
+>       ,scalExpr "{t '12:00:01.1'}" $ Right $ ScalarType "time"
+>       ,scalExpr "{ts '2000-01-01 12:00:01.1'}" $ Right typeTimestamp
+>       -- scalar functions
+>       ,scalExpr "{fn ascii('test')}" $ Right typeInt
+>       ,scalExpr "{fn extract(hour from date 'dt')}" $ Right typeInt
+>       ,scalExpr "(extract(hour from date 'dt'))" $ Right typeInt
+>       -- position not supported in the parser
+>       --,scalExpr "{fn POSITION('aaa' IN 'bbb')}" $ Right typeVarChar
+>       ,scalExpr "{fn CONVERT(3, SQL_BIGINT)}" $ Right typeBigInt
+>       ,scalExpr "{fn CONVERT(3, SQL_FLOAT)}" $ Right typeFloat8
+
+>       ,scalExpr "{fn timestampadd(SQL_TSI_SECOND,3, {t '12:00:00'})}" $ Right typeTime
+>       ,scalExpr "{fn timestampadd(SQL_TSI_MINUTE,3, {ts '2001-01-01 12:00:00'})}" $ Right typeTimestamp
+>       ,scalExpr "{fn timestampadd(SQL_TSI_YEAR,3, {d '2001-01-01'})}" $ Right typeDate
+
+>       ,scalExpr "{fn timestampdiff(SQL_TSI_YEAR,{d '2001-01-01'}, {d '2001-01-01'})}" $ Right typeInt
+
+
+
+>       ,scalExpr "{fn left('test',3)}" $ Right $ ScalarType "text"
+
+        -- todo: somehow, the generated catalog ended up wrong here
+ >       ,scalExpr "left(3,'test')" $ Right $ ScalarType "text"
+
+ >       ,scalExpr "{fn left(3,'test')}" $ Left [NoMatchingOperator "!odbc-left" [ScalarType "int4",UnknownType]]
+ >       ,scalExpr "left('test',3)" $ Left [NoMatchingOperator "left" [UnknownType,ScalarType "int4"]]
+
+ >       ,scalExpr "{fn left(left(3,'test'),3)}" $ Right $ ScalarType "text"
+ >       ,scalExpr "left(3,{fn left('test',3)})" $ Right $ ScalarType "text"
+
+
+
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")]]
+>         "select {fn ascii('test')} as a, a as b, {d '2000-01-01'} as c,\n\
+>         \       {fn CONVERT('text', SQL_VARCHAR)} || {t '12:00:01.1'} as d from t"
+>        $ Right $ CompositeType [("a", (mkTypeExtra typeInt) {teNullable=False})
+>                                ,("b", mkTypeExtra typeInt)
+>                                ,("c", mkTypeExtra typeDate)
+>                                ,("d", mkTypeExtra $ ScalarType "text")]
+
+>       -- outer join
+>       ,tcQueryExpr [CatCreateTable ("public","t0") [("a", mkCatNameExtra "int4")
+>                                         ,("b", mkCatNameExtra "text")]
+>                    ,CatCreateTable ("public","t1") [("c", mkCatNameExtra "int4")
+>                                         ,("d", mkCatNameExtra "text")]]
+>        "select * from {oj t0 left outer join t1 on t0.a=t1.c}"
+>        $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                                ,("b", mkTypeExtra $ ScalarType "text")
+>                                ,("c", mkTypeExtra typeInt)
+>                                ,("d", mkTypeExtra $ ScalarType "text")]
+
+
+>   ]
+>   where
+>     scalExpr = TCScalExpr (diDefaultCatalog postgresDialect) emptyEnvironment
+>                           defaultTypeCheckFlags {tcfDialect = postgresDialect}
+>     tcQueryExpr cus =
+>         let cat = makeCatalog postgresDialect cus
+>         in TCQueryExpr cat defaultTypeCheckFlags {tcfDialect = postgresDialect}
+>     typeDate = ScalarType "date"
+>     typeTimestamp = ScalarType "timestamp"
+>     typeInt = ScalarType "int4"
+>     typeBigInt = ScalarType "int8"
+>     typeTime = ScalarType "time"
+>     typeFloat8 = ScalarType "float8"
+
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/PrecisionAndNullable.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/PrecisionAndNullable.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/PrecisionAndNullable.lhs
@@ -0,0 +1,209 @@
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.PrecisionAndNullable
+>     (precisionAndNullable) where
+
+> --import Database.HsSqlPpp.Internals.TypesInternal
+> import Database.HsSqlPpp.Tests.TestTypes
+> import Database.HsSqlPpp.Catalog
+> import Database.HsSqlPpp.Dialect
+> --import Database.HsSqlPpp.Internals.AstInternal
+> --import Database.HsSqlPpp.Internals.TypeChecking.Environment
+> import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Tests.TypeChecking.Utils
+> --import qualified Data.Text.Lazy as L
+> --import Database.HsSqlPpp.Internals.TypesInternal hiding (mkTypeExtra,mkTypeExtraNN)
+
+> precisionAndNullable :: Item
+> precisionAndNullable =
+>   Group "PrecisionAndNullable" $
+>   [Group "ScalarExprs"
+>    [seePg anEnv  "an"  (Right anType)
+>    ,seePg aEnv   "a"   (Right aType)
+>    ,seePg cnEnv  "cn"  (Right cnType)
+>    ,seePg cEnv   "c"   (Right cType)
+>    ,seePg vnEnv  "vn"  (Right vnType)
+>    ,seePg vEnv   "v"   (Right vType)
+>    ,seePg dnEnv  "dn"  (Right dnType)
+>    ,seePg dEnv   "d"   (Right dType)
+>    ,seePg vConcatEnv vConcatExpr (Right vConcatType)
+>    ,seePg vConcatEnv "v||'test12'" (Right $ TypeExtra (ScalarType "text") (Just 12) Nothing False)
+>    ,seePg vEqEnv vEqExpr (Right vEqType)
+>    ,seeTs a2Env "isnull(an,a)" (Right aType)
+>    ,seeTs anEnv "isnull(an,an)" (Right anType)
+>    ,seePg aEnv "a is null" (Right isNType)
+>    ,seePg aEnv "a is not null" (Right isNType)
+>    ,seePg anEnv "an is null" (Right isNType)
+>    ,seePg anEnv "an is not null" (Right isNType)
+>    ,seePg coalEnv "coalesce(an,dn,a)" (Right coalType)
+>    -- gives incompatible types
+>    --,seePg case1Env "case an when v then a when c then an end" (Right case1Type)
+>    ,seeTs case1Env "case vn when v then a when c then an end" (Right case1Type)
+>    ,seePg case2Env "case when an is null then a when v is null then an else dn end" (Right case2Type)
+>    ,seeTs (selListEnv []) "dateadd(year,1,'1997/01/01')" (Right $ mkTypeExtraNN $ ScalarType "timestamp")
+>    ,seeTs vEnv   "len(v)"   (Right aType)
+>    ]
+>   ]
+>   ++ [Group "PrecisionAndNullabletcQueryExpr"
+>       [tcQueryExpr
+>         [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                             ,("b", CatNameExtra "varchar" (Just 7) Nothing False)]]
+>         "select a,b from t"
+>         $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                                 ,("b", TypeExtra typeVarChar (Just 7) Nothing False)]
+>
+>
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", CatNameExtra "numeric" (Just 6) (Just 2) False)
+>                                      ,("b", CatNameExtra "numeric" (Just 10) (Just 3) False)]]
+>        "select nullif(a,b) as ni from t"
+>        $ Right $ CompositeType [("ni", TypeExtra typeNumeric (Just 6) (Just 2) True)]
+>
+>
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", CatNameExtra "float" (Just 10) (Just 2) False)
+>                                      ,("b", CatNameExtra "varchar" (Just 12) Nothing True)]]
+>        "select * from t"
+>        $ Right $ CompositeType [("a", TypeExtra typeFloat8 (Just 10) (Just 2) False)
+>                                ,("b", TypeExtra typeVarChar (Just 12) Nothing True)]
+>       ,tsqlQueryExpr
+>                   [CatCreateTable ("public","t1")  [("a", CatNameExtra "int4" Nothing Nothing True)
+>                                         ,("b", CatNameExtra "char" (Just 5) Nothing False)]
+>                   ,CatCreateTable ("public","t2")  [("c", CatNameExtra "float" (Just 10) (Just 2) False)
+>                                         ,("d", CatNameExtra "varchar" (Just 6) Nothing False)]]
+>        "select * from t1 union all select * from t2"
+>        $ Right $ CompositeType [("a", TypeExtra typeFloat8 (Just 10) (Just 2) True)
+>                                ,("b", TypeExtra typeVarChar (Just 6) Nothing False)]
+
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                                      ,("b", CatNameExtra "varchar" (Just 13) Nothing False)
+>                                      ,("c", CatNameExtra "varchar" (Just 15) Nothing True)]]
+>        "select case when a is null then b else c end as cs from t u"
+>        $ Right $ CompositeType [("cs", TypeExtra typeVarChar (Just 15) Nothing True)]
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                                      ,("b", mkCatNameExtra "text")]]
+>        "select * from t u(c,d)"
+>        $ Right $ CompositeType [("c", mkTypeExtra typeInt)
+>                                ,("d", mkTypeExtra $ ScalarType "text")]
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                                      ,("b", mkCatNameExtra "text")]]
+>        "select u.a,u.b from t u"
+>        $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                                ,("b", mkTypeExtra $ ScalarType "text")]
+
+>
+>
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                                      ,("b", mkCatNameExtra "text")]]
+>        "select count(*) from t"
+>        $ Right $ CompositeType [("count", mkTypeExtraNN typeBigInt)]
+
+
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")]
+>                  ,CatCreateTable ("public","u") [("a", mkCatNameExtra "int4")]]
+>        "select * from t union select * from u"
+>        $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")]
+>                  ,CatCreateTable ("public","u") [("b", mkCatNameExtra "int4")]]
+>        "select * from t union select * from u"
+>        $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")]]
+>        "select a,count(*) over () as r from t"
+>        $ Right $ CompositeType  [("a", mkTypeExtra typeInt),
+>                                 ("r", mkTypeExtraNN typeBigInt)]
+>       -- postponed until we decide about implicit casts from numeric to string types
+>       --,tsqlQueryExpr [CatCreateTable ("public","t") [("a", CatNameExtra "int4" Nothing Nothing False)]]
+>       -- "select a, lower(a) as l from t"
+>       -- $ Right $ CompositeType  [("a", TypeExtra (ScalarType "int4") Nothing Nothing False),
+>       --                          ("l", TypeExtra (ScalarType "text") Nothing Nothing False)]
+>       ,tsqlQueryExpr [CatCreateTable ("public","t") [("d", CatNameExtra "date" Nothing Nothing False)]]
+>        "select d from t where d > dateadd(year,1,'1997-01-01')"
+>        $ Right $ CompositeType  [("d", mkTypeExtraNN typeDate)]
+>       ,tsqlQueryExpr [CatCreateTable ("public","t") [("a", CatNameExtra "int4" Nothing Nothing False)],
+>                       CatCreateTable ("public","tt") [("v", CatNameExtra "varchar" (Just 6) Nothing False)]]
+>        "select t.a from t inner join tt on t.a=tt.v"
+>        $ Right $ CompositeType  [("a", mkTypeExtraNN typeInt)]
+
+>       ,tsqlQueryExpr [CatCreateTable ("public","t") [("tv", CatNameExtra "nvarchar" (Just 15) Nothing False)]]
+>        "select tv from t"
+>        $ Right $ CompositeType  [("tv", mkTe 15 False)]
+>       ,tsqlQueryExpr [CatCreateTable ("public","t") [("a",CatNameExtra "int4" Nothing Nothing False)
+>                                                     ,("tv", CatNameExtra "nvarchar" (Just 15) Nothing False)]]
+>        "select * from t"
+>        $ Right $ CompositeType  [("a", mkTypeExtraNN typeInt)
+>                                 ,("tv", mkTe 15 False)]
+
+>       ,tsqlQueryExpr [CatCreateTable ("public","t") [("tv", CatNameExtra "nvarchar" (Just 15) Nothing False)]]
+>        "select substring(tv,0,2) from t"
+>        $ Right $ CompositeType  [("substring",TypeExtra typeNvc (Just 15) Nothing False)]
+
+>       ,tsqlQueryExpr [CatCreateTable ("public","t") [("tv", CatNameExtra "nvarchar" (Just 15) Nothing False)]]
+>        "select len(tv) from t"
+>        $ Right $ CompositeType  [("len", mkTypeExtraNN typeInt)]
+
+>       ,tsqlQueryExpr [CatCreateTable ("public","t") [("tv", CatNameExtra "nvarchar" (Just 15) Nothing False)]]
+>        "SELECT tv LIKE '%foo' FROM t"
+>        $ Right $ CompositeType  [("?column?", mkTypeExtraNN typeBool)]
+
+>       ,tsqlQueryExpr [CatCreateTable ("public","t") [("tv1",CatNameExtra "nvarchar" (Just 9) Nothing False)
+>                                                     ,("tv", CatNameExtra "nvarchar" (Just 15) Nothing False)]]
+>        "SELECT tv=tv1 FROM t"
+>        $ Right $ CompositeType  [("?column?", mkTypeExtraNN typeBool)]
+
+>       ,tsqlQueryExpr [CatCreateTable ("public","t") [("tv", CatNameExtra "nvarchar" (Just 15) Nothing False)]]
+>        "SELECT tv='foo' FROM t"
+>        $ Right $ CompositeType  [("?column?", mkTypeExtraNN typeBool)]
+>       ]
+>     ]
+>   where
+>     --cat1 = diDefaultCatalog postgresDialect
+>     --cat2 = diDefaultCatalog sqlServerDialect
+>     anType = TypeExtra typeInt Nothing Nothing True
+>     anEnv = selListEnv [("an", anType)]
+>     aType = mkTypeExtraNN typeInt
+>     aEnv = selListEnv [("a", aType)]
+>     a2Env = selListEnv [("a", aType),("an", anType)]
+>     cnType = TypeExtra typeChar (Just 4) Nothing True
+>     cnEnv = selListEnv [("cn", cnType)]
+>     cType = TypeExtra typeChar (Just 3) Nothing False
+>     cEnv = selListEnv [("c", cType)]
+>     vnType = TypeExtra typeVarChar (Just 7) Nothing True
+>     vnEnv = selListEnv [("vn", vnType)]
+>     vType = TypeExtra typeVarChar (Just 6) Nothing False
+>     vEnv = selListEnv [("v", vType)]
+>     dnType = TypeExtra typeNumeric (Just 10) (Just 2) True
+>     dnEnv = selListEnv [("dn", dnType)]
+>     dType = TypeExtra typeNumeric (Just 9) (Just 3) False
+>     dEnv = selListEnv [("d", dType)]
+>     vConcatType = TypeExtra (ScalarType "text") (Just 13) Nothing True
+>     vConcatExpr = "v||vn"
+>     vConcatEnv = selListEnv [("vn", vnType),("v", vType)]
+>     vEqType = TypeExtra typeBool Nothing Nothing True
+>     vEqExpr = "v=vn"
+>     vEqEnv = selListEnv [("vn", vnType),("v", vType)]
+>     isNType = mkTypeExtraNN typeBool
+>     coalEnv = selListEnv [("a", aType),("an", anType),("dn", dnType)]
+>     coalType = TypeExtra typeNumeric (Just 10) (Just 2) False
+>     case1Env = selListEnv [("vn", vnType),("a", aType),("an", anType),("c", cType),("v", vType)]
+>     case1Type = anType
+>     case2Env = selListEnv [("a", aType),("an", anType),("dn", dnType),("v", vType)]
+>     case2Type = dnType
+>     --
+>     selListEnv env = either (const brokeEnvironment) id $ envSelectListEnvironment env
+>     tcQueryExpr cus =
+>         let cat = makeCatalog postgresDialect cus
+>         in TCQueryExpr cat defaultTypeCheckFlags {tcfDialect = postgresDialect}
+>     tsqlQueryExpr cus =
+>         let cat = makeCatalog sqlServerDialect cus
+>         in TCQueryExpr cat defaultTypeCheckFlags {tcfDialect = sqlServerDialect}
+>     seePg = ScalarExprExtra postgresDialect (diDefaultCatalog postgresDialect)
+>     seeTs = ScalarExprExtra sqlServerDialect (diDefaultCatalog sqlServerDialect)
+>     typeInt = ScalarType "int4"
+>     typeBigInt = ScalarType "int8"
+>     typeVarChar = ScalarType "varchar"
+>     typeNumeric = ScalarType "numeric"
+>     typeFloat8 = ScalarType "float8"
+>     typeDate = ScalarType "date"
+>     typeChar = ScalarType "char"
+>     typeBool = ScalarType "bool"
+>     typeNvc = ScalarType "nvarchar"
+>     mkTe i isNull = TypeExtra (typeNvc) (Just i) Nothing isNull
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/QueryExprs.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/QueryExprs.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/QueryExprs.lhs
@@ -0,0 +1,116 @@
+
+New set of tests for new typechecking. Will catch more issues than the
+old typechecker, and the tests are focus on lots of checks for bad
+typechecks as well as correct queries compared to the old tests.
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.QueryExprs
+>     (queryExprs) where
+
+> import Database.HsSqlPpp.Catalog
+> import Database.HsSqlPpp.Dialect
+> import Database.HsSqlPpp.Internals.TypesInternal
+> import Database.HsSqlPpp.Tests.TestTypes
+> --import Database.HsSqlPpp.Internals.AstInternal as A
+> --import Database.HsSqlPpp.Tests.Parsing.Utils
+> --import qualified Data.Text as T
+> import qualified Data.Text.Lazy as L
+
+> queryExprs :: Item
+> queryExprs =
+>   Group "queryExprs" [
+>       tcQueryExpr simpleTEnv
+>         (L.concat ["with tbl1(c,d) as (select a,b from tbl), tbl2(e,f) as (select c,d from tbl1)"
+>                   ," select c,d,e,f from tbl1 join tbl2"])
+>         $ Right $ CompositeType [("c", mkTypeExtra typeInt)
+>                                 ,("d", mkTypeExtra $ ScalarType "text")
+>                                 ,("e", mkTypeExtra typeInt)
+>                                 ,("f", mkTypeExtra $ ScalarType "text")
+>                                 ]
+>   ]
+>   where
+>     simpleTEnv = [CatCreateTable ("public","tbl")
+>       [("a", mkCatNameExtra "int4")
+>       ,("b", mkCatNameExtra "text")]]
+>     typeInt = ScalarType "int4"
+>     tcQueryExpr cus =
+>         let cat = makeCatalog postgresDialect cus
+>         in TCQueryExpr cat defaultTypeCheckFlags {tcfDialect=postgresDialect}
+
+= basic select list
+
+column name
+*
+aliases
+correlation names
+
+can embed in view to check additional stuff like no duplicate or
+unnamed columns
+
+= from
+
+tableref
+funtableref
+subquery tref
+join
+parens
+aliases
+lateral
+
+= set valued functions in select list
+
+= aggregates
+
+== simple
+== with extra exprs
+== in other contexts
+== grouping set stuff
+== having
+= windows
+
+= orderby
+= where
+= csq
+= distinct
+= set ops
+
+= limit, offset
+
+
+= additional scalar expr syntax tests
+
+where, having, order by, limit, offset
+
+
+
+= errors
+
+what kind of errors can there be with a sql statement?
+
+static errors: these are errors which can be detected with syntax
+analysis and static checking without executing anything (and before
+any cost based optimiser)
+
+transaction errors: these are errors which occur because of
+transactions and concurrency. Some other transaction can commit first
+and then your transaction fails and cannot work (e.g. someone drops a
+table you are referencing), and you can have serializable errors which
+you can just retry and expect it to work.
+
+'dynamic' errors: bad parses, arithmetic overflow, etc. These are
+errors which only occur during statement execution. Are they all
+related to data type conversion and/or scalar functions (maybe also
+aggs and windows?). can other phys ops fail like this?
+
+apparent hanging? is this an error? this means stuff like the cost
+based optimiser takes forever (or even some other part of the
+statement compiler), or the runtime takes forever (e.g. some
+degenerate sort means it does a new io for each row and it never
+completes). Real hangs should only occur from programmer errors. We
+should have methods to detect and recover from these (cancelling a
+statement or connection, and restarting the server process for
+instance).
+
+unexpected errors: these can come from programming errors, e.g. assert
+or bad memory writes, or running out of memory (this is a programmer
+error), or from hardware issues
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/Rewrites.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/Rewrites.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/Rewrites.lhs
@@ -0,0 +1,119 @@
+test adding qualifiers, tableref aliases, expanding *, adding select
+item aliases
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.Rewrites
+>     (rewrites) where
+
+> import Database.HsSqlPpp.Tests.TestTypes
+> --import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Catalog
+> import Database.HsSqlPpp.Dialect
+> --import Database.HsSqlPpp.TypeCheck
+
+
+
+> rewrites :: Item
+> rewrites =
+>   Group "rewrites"
+>   [RewriteQueryExpr defaultTypeCheckFlags {tcfAddSelectItemAliases = True
+>                                              ,tcfDialect = postgresDialect}
+>          [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                              ,("b", mkCatNameExtra "text")]]
+>    "select a,b from t"
+>    "select a as a,b as b from t"
+
+>   ,RewriteQueryExpr defaultTypeCheckFlags {tcfExpandStars = True
+>                                              ,tcfDialect = postgresDialect}
+>          [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                              ,("b", mkCatNameExtra "text")]]
+>    "select * from t"
+>    "select t.a,t.b from t"
+
+>   ,RewriteQueryExpr defaultTypeCheckFlags {tcfAddQualifiers = True
+>                                              ,tcfDialect = postgresDialect}
+>          [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                              ,("b", mkCatNameExtra "text")]]
+>    "select b,count(a) from t group by b"
+>    "select t.b,count(t.a) from t group by t.b"
+
+>   ,RewriteQueryExpr defaultTypeCheckFlags {tcfAddQualifiers = True
+>                                              ,tcfDialect = postgresDialect}
+>          [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                              ,("b", mkCatNameExtra "text")]]
+>    "select * from t where a > 3"
+>    "select * from t where t.a > 3"
+
+>   ,RewriteQueryExpr defaultTypeCheckFlags {tcfAddQualifiers = True
+>                                              ,tcfDialect = postgresDialect}
+>          [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                              ,("b", mkCatNameExtra "text")]]
+>    "select * from t u where a > 3"
+>    "select * from t u where u.a > 3"
+
+
+>   ,RewriteQueryExpr defaultTypeCheckFlags {tcfAddQualifiers = True
+>                                              ,tcfDialect = postgresDialect}
+>          [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                              ,("b", mkCatNameExtra "text")]]
+>    "select * from t order by a"
+>    "select * from t order by t.a"
+
+
+
+>   ,RewriteQueryExpr defaultTypeCheckFlags {tcfAddFullTablerefAliases = True
+>                                              ,tcfDialect = postgresDialect}
+>          [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                              ,("b", mkCatNameExtra "text")]]
+>    "select * from t"
+>    "select * from t as t(a,b)"
+
+
+>   ,RewriteQueryExpr defaultTypeCheckFlags {tcfAddFullTablerefAliases = True
+>                                              ,tcfDialect = postgresDialect}
+>          [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                              ,("b", mkCatNameExtra "text")]]
+>    "select * from (select a,b from t) u"
+>    "select * from (select a,b from t t(a,b)) u(a,b)"
+
+>   ,RewriteQueryExpr defaultTypeCheckFlags {tcfAddFullTablerefAliases = True
+>                                              ,tcfDialect = postgresDialect}
+>          [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                              ,("b", mkCatNameExtra "text")]
+>          ,CatCreateTable ("public","u") [("c", mkCatNameExtra "int4")
+>                              ,("d", mkCatNameExtra "text")]]
+>    "select * from t cross join u"
+>    -- can't add an alias to the join since the qualifiers
+>    -- aren't all the same
+>    "select * from t t(a,b) cross join u u(c,d)"
+
+>   ,RewriteQueryExpr defaultTypeCheckFlags {tcfAddFullTablerefAliases = True
+>                                              ,tcfDialect = postgresDialect}
+>          [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                              ,("b", mkCatNameExtra "text")]
+>          ,CatCreateTable ("public","u") [("c", mkCatNameExtra "int4")
+>                              ,("d", mkCatNameExtra "text")]]
+>    "select * from t cross join u t"
+>    "select * from (t t(a,b) cross join u t(c,d)) t(a,b,c,d)"
+
+
+
+
+>   ,RewriteQueryExpr defaultTypeCheckFlags {tcfAddQualifiers = True
+>                                              ,tcfDialect = postgresDialect}
+>          [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                              ,("b", mkCatNameExtra "text")]]
+>    "select a,b from t"
+>    "select t.a,t.b from t"
+
+>   ,RewriteQueryExpr defaultTypeCheckFlags {tcfAddQualifiers = True
+>                                              ,tcfAddSelectItemAliases = True
+>                                              ,tcfExpandStars = True
+>                                              ,tcfAddFullTablerefAliases = True
+>                                              ,tcfDialect = postgresDialect}
+>          [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                              ,("b", mkCatNameExtra "text")]]
+>    "/*thisit*/select * from t"
+>    "select t.a as a,t.b as b from t as t(a,b)"
+
+>   ]
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/ScalarExprs.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/ScalarExprs.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/ScalarExprs.lhs
@@ -0,0 +1,46 @@
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.ScalarExprs
+>     (scalarExprs) where
+
+> import Database.HsSqlPpp.Types
+> --import Database.HsSqlPpp.Internals.TypesInternal hiding (mkTypeExtra,mkTypeExtraNN)
+> import Database.HsSqlPpp.Dialect
+
+> import Database.HsSqlPpp.Tests.TestTypes
+
+> scalarExprs :: Item
+> scalarExprs =
+>   Group "scalarExprs"
+>   [Group "simple literals"
+>    [scalExpr "true" $ Right typeBool
+>    ,scalExpr "false" $ Right typeBool
+>    ,scalExpr "41" $ Right typeInt
+>    ,scalExpr "2147483648" $ Right typeBigInt
+>    ,scalExpr "9223372036854775808" $ Right typeNumeric
+>    ,scalExpr "1.6" $ Right typeNumeric
+>    ,scalExpr "'test'" $ Right UnknownType
+>    ,scalExpr "null" $ Right UnknownType
+>    ]
+>   ,Group "other simple scalexprs"
+>     [scalExpr "'1'::int" $ Right typeInt
+>     ,scalExpr "date '2000-01-01'" $ Right $ ScalarType "date"
+>     ,scalExpr "interval '90' day" $ Right $ ScalarType "interval"
+>     ,scalExpr "?" $ Right UnknownType
+>     ]
+>   ,Group "function application"
+>     [scalExpr "length('test')" $ Right typeInt
+>     ,scalExpr "-5" $ Right typeInt
+>     ]
+>   ,Group "function application like"
+>     [scalExpr "extract(year from date '2000-01-01')" $ Right typeInt
+>     ,scalExpr "extract(year from 3)" $ Left [NoMatchingOperator "extract" [typeInt]]
+>     ]
+>   ]
+>   where
+>     scalExpr = TCScalExpr (diDefaultCatalog postgresDialect) emptyEnvironment
+>                           defaultTypeCheckFlags {tcfDialect = postgresDialect}
+>     typeBool = ScalarType "bool"
+>     typeInt = ScalarType "int4"
+>     typeBigInt = ScalarType "int8"
+>     typeNumeric = ScalarType "numeric"
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/SimpleQueryExprs.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/SimpleQueryExprs.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/SimpleQueryExprs.lhs
@@ -0,0 +1,119 @@
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.SimpleQueryExprs
+>     (simpleQueryExprs) where
+
+> --import Database.HsSqlPpp.Internals.TypesInternal
+> import Database.HsSqlPpp.Tests.TestTypes
+> --import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Catalog
+> import Database.HsSqlPpp.Dialect
+> --import Database.HsSqlPpp.TypeChecker
+> import Database.HsSqlPpp.Types
+> --import Database.HsSqlPpp.Internals.TypesInternal hiding (mkTypeExtra,mkTypeExtraNN)
+
+> import Database.HsSqlPpp.Tests.TypeChecking.Utils
+
+> simpleQueryExprs :: Item
+> simpleQueryExprs =
+>   Group "simpleQueryExpr"
+>       [tcQueryExpr
+>         [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                             ,("b", mkCatNameExtra "text")]]
+>         "select a,b from t"
+>         $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                                 ,("b", mkTypeExtra $ ScalarType "text")]
+>
+>
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                                      ,("b", mkCatNameExtra "text")]]
+>        "select a as c,b as d from t"
+>        $ Right $ CompositeType [("c", mkTypeExtra typeInt)
+>                                ,("d", mkTypeExtra $ ScalarType "text")]
+>
+>
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                                      ,("b", mkCatNameExtra "text")]]
+>        "select * from t"
+>        $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                                ,("b", mkTypeExtra $ ScalarType "text")]
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                                      ,("b", mkCatNameExtra "text")]]
+>        "select t.a,t.b from t"
+>        $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                                ,("b", mkTypeExtra $ ScalarType "text")]
+
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                                      ,("b", mkCatNameExtra "text")]]
+>        "select u.* from t u"
+>        $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                                ,("b", mkTypeExtra $ ScalarType "text")]
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                                      ,("b", mkCatNameExtra "text")]]
+>        "select * from t u(c,d)"
+>        $ Right $ CompositeType [("c", mkTypeExtra typeInt)
+>                                ,("d", mkTypeExtra $ ScalarType "text")]
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                                      ,("b", mkCatNameExtra "text")]]
+>        "select u.a,u.b from t u"
+>        $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                                ,("b", mkTypeExtra $ ScalarType "text")]
+
+>
+>
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")
+>                                      ,("b", mkCatNameExtra "text")]]
+>        "select count(*) from t"
+>        $ Right $ CompositeType [("count", mkTypeExtraNN typeBigInt)]
+
+
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")]
+>                  ,CatCreateTable ("public","u") [("a", mkCatNameExtra "int4")]]
+>        "select * from t union select * from u"
+>        $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")]
+>                  ,CatCreateTable ("public","u") [("b", mkCatNameExtra "int4")]]
+>        "select * from t union select * from u"
+>        $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4"),("b", mkCatNameExtra "int4")]
+>                    ,CatCreateTable ("public","u") [("a", mkCatNameExtra "int4")]]
+>        "select a,b from t union select a from u"
+>        $ Left [IncompatibleUnionTypes (CompositeType [("a", mkTypeExtra typeInt),("b", mkTypeExtra typeInt)])
+>                                       (CompositeType [("a", mkTypeExtra typeInt)])]
+
+todo: implicit casts in union
+
+simple window function type
+
+>       ,tcQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")]]
+>        "select a,count(*) over () as r from t"
+>        $ Right $ CompositeType [("a", mkTypeExtra typeInt), ("r", mkTypeExtraNN typeBigInt)]
+
+values
+
+>       ,tcQueryExpr []
+>        "values (1)"
+>        $ Right $ CompositeType [("values%0", mkTypeExtraNN typeInt)]
+
+>       ,tcQueryExpr []
+>        "values (1),(2)"
+>        $ Right $ CompositeType [("values%0", mkTypeExtraNN typeInt)]
+
+>       ,tcQueryExpr []
+>        "values (1,1.5),(2,2.5)"
+>        $ Right $ CompositeType [("values%0", mkTypeExtraNN typeInt), ("values%1", mkTypeExtraNN $ ScalarType "numeric")]
+
+>       ,tcQueryExpr []
+>        "values (1.5),(1)"
+>        $ Right $ CompositeType [("values%0", mkTypeExtraNN $ ScalarType "numeric")]
+>   ]
+>   where
+>     tcQueryExpr cus =
+>         let cat = makeCatalog postgresDialect cus
+>         in TCQueryExpr cat defaultTypeCheckFlags {tcfDialect = postgresDialect}
+>     --typeBool = ScalarType "bool"
+>     typeInt = ScalarType "int4"
+>     typeBigInt = ScalarType "int8"
+>     --typeNumeric = ScalarType "numeric"
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/TSQL.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/TSQL.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/TSQL.lhs
@@ -0,0 +1,138 @@
+
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.TSQL
+>     (tsqlQueryExprs) where
+
+> --import Database.HsSqlPpp.Internals.TypesInternal
+> import Database.HsSqlPpp.Tests.TestTypes
+> --import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Catalog
+> --import Database.HsSqlPpp.TypeChecker
+> import Data.Text.Lazy (pack)
+> import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Dialect
+> import Database.HsSqlPpp.Tests.TypeChecking.Utils
+> --import Database.HsSqlPpp.Internals.TypesInternal hiding (mkTypeExtra,mkTypeExtraNN)
+
+> tsqlQueryExprs :: Item
+> tsqlQueryExprs =
+>   Group "tsql" $
+
+datepart, datediff, dateadd
+
+>   [tsqlQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "date")
+>                                      ,("b", mkCatNameExtra "date")]]
+
+this doesn't work:
+    "select datediff(hour,a,b) a from t"
+todo: fix it
+
+>    "select datediff(hour,a,b) as a from t"
+>    $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+>   ,tsqlQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "tinyint")
+>                                      ,("b", mkCatNameExtra "smallint")]]
+>    "select a+b as a from t /* junk it */"
+>    $ Right $ CompositeType [("a", mkTypeExtra typeSmallInt)]]
+>   ++ [tsqlQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "date")]]
+>      (pack $ "select datepart(" ++ dp ++ ",a) as a from t")
+>      $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+>      | dp <- ["day","month","year", "hour"]]
+
+>   ++ [tsqlQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "timestamp")]]
+>      (pack $ "select datepart(" ++ dp ++ ",a) as a from t")
+>      $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+>      | dp <- ["day","month","year", "hour"]]
+
+
+>   ++ [tsqlQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "date")]]
+>      (pack $ "select dateadd(" ++ dp ++ ",5,a) as a from t")
+>      $ Right $ CompositeType [("a", mkTypeExtra typeDate)]
+>      | dp <- ["day","month","year"]]
+>   ++ [tsqlQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "date")]]
+>      (pack $ "select dateadd(" ++ dp ++ ",5,'1992-001-01') as a from t")
+>      $ Right $ CompositeType [("a", mkTypeExtraNN $ ScalarType "timestamp")]
+>      | dp <- ["day","month","year"]]
+
+
+aggregates: the types of aggregates is different in mssql to
+postgresql:
+
+http://msdn.microsoft.com/en-us/library/ms173454.aspx
+
+>   ++ [tsqlQueryExpr [CatCreateTable ("public","t") [("a", inty)]]
+>      (pack $ "select " ++ agg ++ "(a) as a from t")
+>      $ Right $ CompositeType [("a",resty)]
+>      | agg <- ["sum","avg"]
+
+avg,sum
+
+tinyint int
+smallint int
+int int
+bigint bigint
+money and smallmoney category ->  money -> todo
+float and real category -> float
+
+>      , (inty,resty) <-
+>        [(mkCatNameExtra "tinyint", mkTypeExtra typeInt)
+>        ,(mkCatNameExtra "smallint", mkTypeExtra typeInt)
+>        ,(mkCatNameExtra "int", mkTypeExtra typeInt)
+>        --,(mkCatNameExtra "int", mkTypeExtra typeInt)
+>        ,(mkCatNameExtra "bigint", mkTypeExtra typeBigInt)
+>        ,(mkCatNameExtra "float", mkTypeExtra typeFloat8)
+>        ,(mkCatNameExtra "real", mkTypeExtra typeFloat8)
+>        ]]
+
+avg
+
+decimal category (p, s) ->
+decimal(38, s) divided by decimal(10, 0)
+
+sum
+
+decimal category (p, s) ->
+decimal(38, s)
+
+(todo)
+
+
+count returns int
+count_big returns bigint
+
+>   ++
+>   [tsqlQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")]]
+>    "select count(*) as a from t"
+>    $ Right $ CompositeType [("a", mkTypeExtraNN typeInt)]
+>   ,tsqlQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int4")]]
+>    "select count_big(*) as a from t"
+>    $ Right $ CompositeType [("a", mkTypeExtraNN typeBigInt)]]
+
+todo: add new dialect and stuff for oracle
+
+>   ++
+>   [tsqlQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "timestamp")]]
+>    "select trunc(a) as a from t"
+>    $ Right $ CompositeType [("a", mkTypeExtra $ ScalarType "timestamp")]
+>   ,tsqlQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "date")]]
+>    "select trunc(a) as a from t"
+>    $ Right $ CompositeType [("a", mkTypeExtra $ ScalarType "timestamp")]
+>   ,tsqlQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "date")]]
+>    "select a from t where \
+>    \ trunc(a) between '2001-01-01 00:00:00' and '2001-04-01 00:00:00'"
+>    $ Right $ CompositeType [("a", mkTypeExtra typeDate)]
+
+>   ,tsqlQueryExpr [CatCreateTable ("public","t") [("a", mkCatNameExtra "int")]]
+>    "select decode(a,0,0,1,5,2,6,3,7,10) as a from t"
+>    $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+
+>   ]
+>   where
+>     tsqlQueryExpr cus =
+>         let cat = makeCatalog sqlServerDialect cus
+>         in TCQueryExpr cat defaultTypeCheckFlags {tcfDialect = sqlServerDialect}
+>     typeInt = ScalarType "int4"
+>     typeSmallInt = ScalarType "int2"
+>     typeDate = ScalarType "date"
+>     typeBigInt = ScalarType "int8"
+>     typeFloat8 = ScalarType "float8"
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/Tpch.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/Tpch.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/Tpch.lhs
@@ -0,0 +1,136 @@
+
+Tests using the tpch queries. Just tests the result type at the
+moment.
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.Tpch
+>     (tpch) where
+> --import Database.HsSqlPpp.Internals.TypesInternal
+> --import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Tests.TpchData
+> import Database.HsSqlPpp.Tests.TestTypes
+> import qualified Data.Text.Lazy as L
+> import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Dialect
+> import Database.HsSqlPpp.Tests.TypeChecking.Utils
+> --import Database.HsSqlPpp.Internals.TypesInternal hiding (mkTypeExtra,mkTypeExtraNN)
+
+> tpch :: Item
+> tpch =
+>   Group "tpch" $
+>         -- FIXME: 15 has cte which isn't implemented yet
+>         let (s,e) = splitAt 14 t
+>         in s ++ drop 1 e
+>   where
+>     t = zipWith (\(_n,s) t' -> tcQueryExpr tpchCatalog (L.pack s)
+>                               (Right $ {-Pseudo $ SetOfType $ -}CompositeType t'))
+>          tpchQueries
+>          [-- q1
+>           [("l_returnflag", mkTypeExtra typeChar)
+>           ,("l_linestatus", mkTypeExtra typeChar)
+>           ,("sum_qty", mkTypeExtra typeNumeric)
+>           ,("sum_base_price", mkTypeExtra typeNumeric)
+>           ,("sum_disc_price", mkTypeExtra typeNumeric)
+>           ,("sum_charge", mkTypeExtra typeNumeric)
+>           ,("avg_qty", mkTypeExtra typeNumeric)
+>           ,("avg_price", mkTypeExtra typeNumeric)
+>           ,("avg_disc", mkTypeExtra typeNumeric)
+>           ,("count_order", mkTypeExtraNN typeBigInt)]
+>          ,--q2
+>           [("s_acctbal", mkTypeExtra typeNumeric)
+>           ,("s_name", mkTypeExtra typeChar)
+>           ,("n_name", mkTypeExtra typeChar)
+>           ,("p_partkey", mkTypeExtra typeInt)
+>           ,("p_mfgr", mkTypeExtra typeChar)
+>           ,("s_address", mkTypeExtra typeVarChar)
+>           ,("s_phone", mkTypeExtra typeChar)
+>           ,("s_comment", mkTypeExtra typeVarChar)]
+>          ,--q3
+>           [("l_orderkey", mkTypeExtra typeInt)
+>           ,("revenue", mkTypeExtra typeNumeric)
+>           ,("o_orderdate", mkTypeExtra typeDate)
+>           ,("o_shippriority", mkTypeExtra typeInt)]
+>          ,--q4
+>           [("o_orderpriority", mkTypeExtra typeChar)
+>           ,("order_count", mkTypeExtraNN typeBigInt)]
+>          ,--q5
+>           [("n_name", mkTypeExtra typeChar)
+>           ,("revenue", mkTypeExtra typeNumeric)]
+>          ,--q6
+>           [("revenue", mkTypeExtra typeNumeric)]
+>          ,--q7
+>           [("supp_nation", mkTypeExtra typeChar)
+>           ,("cust_nation", mkTypeExtra typeChar)
+>           ,("l_year", mkTypeExtra typeInt)
+>           ,("revenue", mkTypeExtra typeNumeric)]
+>          ,--q8
+>           [("o_year", mkTypeExtra typeInt)
+>           ,("mkt_share", mkTypeExtra typeNumeric)]
+>          ,--q9
+>           [("nation", mkTypeExtra typeChar)
+>           ,("o_year", mkTypeExtra typeInt)
+>           ,("sum_profit", mkTypeExtra typeNumeric)]
+>          ,--q10
+>           [("c_custkey", mkTypeExtra typeInt)
+>           ,("c_name", mkTypeExtra typeChar)
+>           ,("revenue", mkTypeExtra typeNumeric)
+>           ,("c_acctbal", mkTypeExtra typeNumeric)
+>           ,("n_name", mkTypeExtra typeChar)
+>           ,("c_address", mkTypeExtra typeVarChar)
+>           ,("c_phone", mkTypeExtra typeChar)
+>           ,("c_comment", mkTypeExtra typeVarChar)]
+>          ,--q11
+>           [("ps_partkey", mkTypeExtra typeInt)
+>           ,("value", mkTypeExtra typeNumeric)]
+>          ,--q12
+>           [("l_shipmode", mkTypeExtra typeChar)
+>           ,("high_line_count", mkTypeExtraNN typeBigInt)
+>           ,("low_line_count", mkTypeExtraNN typeBigInt)]
+>          ,--q13
+>           [("c_count", mkTypeExtraNN typeBigInt)
+>           ,("custdist", mkTypeExtraNN typeBigInt)]
+>          ,--q14
+>           [("promo_revenue", mkTypeExtra typeNumeric)]
+>          ,--q15
+>           [("s_suppkey", mkTypeExtra typeInt)
+>           ,("s_name", mkTypeExtra typeChar)
+>           ,("s_address", mkTypeExtra typeVarChar)
+>           ,("s_phone", mkTypeExtra typeChar)
+>           ,("total_revenue", mkTypeExtra typeNumeric)]
+>          ,--q16
+>           [("p_brand", mkTypeExtra typeChar)
+>           ,("p_type", mkTypeExtra typeVarChar)
+>           ,("p_size", mkTypeExtra typeInt)
+>           ,("supplier_cnt", mkTypeExtraNN typeBigInt)]
+>          ,--q17
+>           [("avg_yearly", mkTypeExtra typeNumeric)]
+>          ,--q18
+>           [("c_name", mkTypeExtra typeChar)
+>           ,("c_custkey", mkTypeExtra typeInt)
+>           ,("o_orderkey", mkTypeExtra typeInt)
+>           ,("o_orderdate", mkTypeExtra typeDate)
+>           ,("o_totalprice", mkTypeExtra typeNumeric)
+>           ,("sum", mkTypeExtra typeNumeric)]
+>          ,--q19
+>           [("revenue", mkTypeExtra typeNumeric)]
+>          ,--q20
+>           [("s_name", mkTypeExtra typeChar)
+>           ,("s_address", mkTypeExtra typeVarChar)]
+>          ,--q21
+>           [("s_name", mkTypeExtra typeChar)
+>           ,("numwait", mkTypeExtraNN typeBigInt)]
+>          ,--q22
+>           [("cntrycode", mkTypeExtra $ ScalarType "char")
+>           ,("numcust", mkTypeExtraNN typeBigInt)
+>           ,("totacctbal", mkTypeExtra typeNumeric)]
+>          ]
+>     tcQueryExpr cus =
+>         let cat = makeCatalog ansiDialect cus
+>         in TCQueryExpr cat defaultTypeCheckFlags
+>     typeChar = ScalarType "char"
+>     typeNumeric = ScalarType "numeric"
+>     typeBigInt = ScalarType "bigint"
+>     typeVarChar = ScalarType "varchar"
+>     typeInt = ScalarType "int"
+>     typeDate = ScalarType "date"
+
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/TrefIdentifiers.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/TrefIdentifiers.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/TrefIdentifiers.lhs
@@ -0,0 +1,114 @@
+
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.TrefIdentifiers
+>     (trefIdentifiers) where
+
+> --import Database.HsSqlPpp.Internals.TypesInternal
+> import Database.HsSqlPpp.Tests.TestTypes
+> --import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Catalog
+> import Database.HsSqlPpp.Dialect
+> import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Tests.TypeChecking.Utils
+> --import Database.HsSqlPpp.Internals.TypesInternal hiding (mkTypeExtra,mkTypeExtraNN)
+
+
+> trefIdentifiers :: Item
+> trefIdentifiers =
+>   Group "trefIdentifiers"
+>   [qenc "select * from t0 cross join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                               ,("b", mkTypeExtra $ ScalarType "text")
+>                               ,("c", mkTypeExtra typeInt)
+>                               ,("d", mkTypeExtra $ ScalarType "text")]
+>   ,qenc "select t0.* from t0 cross join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                               ,("b", mkTypeExtra $ ScalarType "text")]
+>   ,qenc "select t1.* from t0 cross join t1"
+>       $ Right $ CompositeType [("c", mkTypeExtra typeInt)
+>                               ,("d", mkTypeExtra $ ScalarType "text")]
+>   ,qenc "select *, t0.*, t1.* from t0 cross join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                               ,("b", mkTypeExtra $ ScalarType "text")
+>                               ,("c", mkTypeExtra typeInt)
+>                               ,("d", mkTypeExtra $ ScalarType "text")
+>                               ,("a", mkTypeExtra typeInt)
+>                               ,("b", mkTypeExtra $ ScalarType "text")
+>                               ,("c", mkTypeExtra typeInt)
+>                               ,("d", mkTypeExtra $ ScalarType "text")]
+
+>   ,qec "select * from t0 cross join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                               ,("b", mkTypeExtra $ ScalarType "text")
+>                               ,("a", mkTypeExtra typeInt)
+>                               ,("c", mkTypeExtra $ ScalarType "text")]
+>   ,qec "select t0.* from t0 cross join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                               ,("b", mkTypeExtra $ ScalarType "text")]
+>   ,qec "select t1.* from t0 cross join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                               ,("c", mkTypeExtra $ ScalarType "text")]
+>   ,qec "select *, t0.*, t1.* from t0 cross join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                               ,("b", mkTypeExtra $ ScalarType "text")
+>                               ,("a", mkTypeExtra typeInt)
+>                               ,("c", mkTypeExtra $ ScalarType "text")
+>                               ,("a", mkTypeExtra typeInt)
+>                               ,("b", mkTypeExtra $ ScalarType "text")
+>                               ,("a", mkTypeExtra typeInt)
+>                               ,("c", mkTypeExtra $ ScalarType "text")]
+>   ,qec "select t0.a from t0 cross join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+>   ,qec "select t1.a from t0 cross join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+>   ,qec "select a from t0 cross join t1"
+>       $ Left [AmbiguousIdentifier "a"]
+
+>   ,qec "select * from t0 natural inner join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                               ,("b", mkTypeExtra $ ScalarType "text")
+>                               ,("c", mkTypeExtra $ ScalarType "text")]
+>   ,qec "select t0.* from t0 natural inner join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                               ,("b", mkTypeExtra $ ScalarType "text")]
+>   ,qec "select t1.* from t0 natural inner join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                               ,("c", mkTypeExtra $ ScalarType "text")]
+>   ,qec "select *, t0.*, t1.* from t0 natural inner join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                               ,("b", mkTypeExtra $ ScalarType "text")
+>                               ,("c", mkTypeExtra $ ScalarType "text")
+>                               ,("a", mkTypeExtra typeInt)
+>                               ,("b", mkTypeExtra $ ScalarType "text")
+>                               ,("a", mkTypeExtra typeInt)
+>                               ,("c", mkTypeExtra $ ScalarType "text")]
+>   ,qec "select t0.a from t0 natural inner join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+>   ,qec "select t1.a from t0 natural inner join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+>   ,qec "select a from t0 natural inner join t1"
+>       $ Right $ CompositeType [("a", mkTypeExtra typeInt)]
+
+
+
+>   ]
+>   where
+>     qenc = tcQueryExpr [CatCreateTable ("public","t0") [("a", mkCatNameExtra "int4")
+>                                           ,("b", mkCatNameExtra "text")]
+>                      ,CatCreateTable ("public","t1") [("c", mkCatNameExtra "int4")
+>                                           ,("d", mkCatNameExtra "text")]]
+>     qec = tcQueryExpr [CatCreateTable ("public","t0") [("a", mkCatNameExtra "int4")
+>                                          ,("b", mkCatNameExtra "text")]
+>                     ,CatCreateTable ("public","t1") [("a", mkCatNameExtra "int4")
+>                                          ,("c", mkCatNameExtra "text")]]
+>     tcQueryExpr cus =
+>         let cat = makeCatalog postgresDialect cus
+>         in TCQueryExpr cat defaultTypeCheckFlags {tcfDialect = postgresDialect}
+>     typeInt = ScalarType "int4"
+
+
+
+todo:
+unrecognised id
+bogus qualifier for real id
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/TrefSchemas.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/TrefSchemas.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/TrefSchemas.lhs
@@ -0,0 +1,61 @@
+
+Testing schemas in trefs in simple queries
+
+default schema is public - no schema search path
+check explicit schemas match
+check rewrite to add schemas to syntax if missing
+
+schemas affect typechecking of views and tables only currently
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.TrefSchemas
+>     (trefSchemas) where
+
+> --import Database.HsSqlPpp.Internals.TypesInternal
+> import Database.HsSqlPpp.Tests.TestTypes
+> --import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Catalog
+> import Database.HsSqlPpp.Dialect
+> --import Database.HsSqlPpp.TypeChecker
+> import Database.HsSqlPpp.Types
+
+> import Database.HsSqlPpp.Tests.TypeChecking.Utils
+> --import Database.HsSqlPpp.Internals.TypesInternal hiding (mkTypeExtra,mkTypeExtraNN)
+
+> trefSchemas :: Item
+> trefSchemas =
+>   Group "trefSchemas"
+>       [tcQueryExpr simpleTEnv
+>         "select a,b from public.t"
+>         $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                                 ,("b", mkTypeExtra $ ScalarType "text")]
+>       ,tcQueryExpr simpleTEnv
+>         "select a,b from t"
+>         $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                                 ,("b", mkTypeExtra $ ScalarType "text")]
+>       ,tcQueryExpr simpleTEnv
+>         "select a,b from something.t"
+>         $ Left $ [UnrecognisedRelation ("something", "t")]
+
+>       ,tcQueryExpr anotherUEnv
+>         "select a,b from public.u"
+>         $ Left [UnrecognisedRelation ("public", "u")]
+>       ,tcQueryExpr anotherUEnv
+>         "select a,b from u"
+>         $ Left [UnrecognisedRelation ("public", "u")]
+>       ,tcQueryExpr anotherUEnv
+>         "select a,b from something.u"
+>         $ Right $ CompositeType [("a", mkTypeExtra typeInt)
+>                                 ,("b", mkTypeExtra $ ScalarType "text")]
+>       ]
+>   where
+>     simpleTEnv = [CatCreateTable ("public","t")
+>                   [("a", mkCatNameExtra "int4")
+>                   ,("b", mkCatNameExtra "text")]]
+>     anotherUEnv = [CatCreateTable ("something","u")
+>                   [("a", mkCatNameExtra "int4")
+>                   ,("b", mkCatNameExtra "text")]]
+>     tcQueryExpr cus =
+>         let cat = makeCatalog postgresDialect cus
+>         in TCQueryExpr cat defaultTypeCheckFlags {tcfDialect=postgresDialect}
+>     typeInt = ScalarType "int4"
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/TypeCheckTests.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/TypeCheckTests.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/TypeCheckTests.lhs
@@ -0,0 +1,56 @@
+
+
+> module Database.HsSqlPpp.Tests.TypeChecking.TypeCheckTests
+>     (typeCheckTestData
+>     ,Item(..)) where
+
+> --import Test.Framework
+
+
+> import Database.HsSqlPpp.Tests.TestTypes
+> --import Database.HsSqlPpp.Tests.TypeChecking.AnsiScalarExprs
+> import Database.HsSqlPpp.Tests.TypeChecking.ScalarExprs
+> import Database.HsSqlPpp.Tests.TypeChecking.SimpleQueryExprs
+> import Database.HsSqlPpp.Tests.TypeChecking.Rewrites
+> import Database.HsSqlPpp.Tests.TypeChecking.Joins
+> import Database.HsSqlPpp.Tests.TypeChecking.Tpch
+> import Database.HsSqlPpp.Tests.TypeChecking.TrefIdentifiers
+> import Database.HsSqlPpp.Tests.TypeChecking.CaseExpressions
+> import Database.HsSqlPpp.Tests.TypeChecking.ImplicitCasts
+> import Database.HsSqlPpp.Tests.TypeChecking.TSQL
+> import Database.HsSqlPpp.Tests.TypeChecking.Issues
+> import Database.HsSqlPpp.Tests.TypeChecking.Aggregates
+> import Database.HsSqlPpp.Tests.TypeChecking.PrecisionAndNullable
+> import Database.HsSqlPpp.Tests.TypeChecking.InsertQueryExprs
+> import Database.HsSqlPpp.Tests.TypeChecking.TypeConversion
+> import Database.HsSqlPpp.Tests.TypeChecking.OdbcTypechecking
+> import Database.HsSqlPpp.Tests.TypeChecking.TrefSchemas
+> import Database.HsSqlPpp.Tests.TypeChecking.QueryExprs
+> import Database.HsSqlPpp.Tests.TypeChecking.Updates
+> import Database.HsSqlPpp.Tests.TypeChecking.DDL
+> import Database.HsSqlPpp.Tests.TypeChecking.Catalog
+
+> typeCheckTestData :: Item
+> typeCheckTestData =
+>   Group "typeCheckTests"
+>     [catalog
+>     ,scalarExprs
+>     ,simpleQueryExprs
+>     ,joins
+>     ,trefIdentifiers
+>     ,rewrites
+>     ,caseExpressions
+>     ,tpch
+>     ,impCasts
+>     ,tsqlQueryExprs
+>     ,issues
+>     ,aggregates
+>     ,precisionAndNullable
+>     ,insertQueryExprs
+>     ,typeConversionTests
+>     ,odbcTypechecking
+>     ,trefSchemas
+>     ,ddl
+>     ,queryExprs
+>     ,updates
+>     ]
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/TypeConversion.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/TypeConversion.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/TypeConversion.lhs
@@ -0,0 +1,114 @@
+
+> {-# LANGUAGE OverloadedStrings,LambdaCase #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.TypeConversion
+>        (typeConversionTests) where
+
+> import Data.Text ()
+> --import Database.HsSqlPpp.Catalog
+> import Database.HsSqlPpp.Types
+> --import Database.HsSqlPpp.Ast
+> --import Database.HsSqlPpp.Dialect
+> import Database.HsSqlPpp.Tests.TestTypes
+> --import Database.HsSqlPpp.Internals.TypesInternal hiding (mkTypeExtra,mkTypeExtraNN)
+
+
+tests:
+numeric operators simulator
+  choose each pair of number types with the plus operator
+    and check the return type
+  choose one type with unknown and plus op
+  two unknowns and plus -> error
+
+> typeConversionTests :: Item
+> typeConversionTests = Group "typeConversionTests"
+>     [binaryOperators]
+
+
+> binaryOperators :: Item
+> binaryOperators = Group "binaryOperators"
+>     [{-MatchApp PostgreSQLDialect defaultTemplate1Catalog
+>      [Nmc "+"] [(intNotNull,Nothing),(intNotNull, Nothing)]
+>      (Right ([intNotNull,intNotNull],intNotNull))
+>     ,MatchApp PostgreSQLDialect defaultTemplate1Catalog
+>      [Nmc "+"] [(intNotNull,Nothing),(unk, Nothing)]
+>      (Right ([intNotNull,intNotNull],intNotNull))
+>     ,MatchApp PostgreSQLDialect defaultTemplate1Catalog
+>      [Nmc "+"] [(unk,Nothing),(unk, Nothing)]
+>      (Left [NoMatchingOperator "+" [UnknownType,UnknownType]])-}
+
+different types with implicit casts
+
+>     {-,MatchApp PostgreSQLDialect defaultTemplate1Catalog
+>      [Nmc "+"] [(intNotNull,Nothing),(te typeNumeric, Nothing)]
+>      (Right ([te typeNumeric,te typeNumeric],te typeNumeric))
+
+
+nullability
+
+>     ,MatchApp PostgreSQLDialect defaultTemplate1Catalog
+>      [Nmc "+"] [(intNull,Nothing),(intNotNull, Nothing)]
+>      (Right ([intNull,intNotNull],intNull))-}
+
+
+precision and scale
+not quite right
+
+>     {-,MatchApp PostgreSQLDialect defaultTemplate1Catalog
+>      [Nmc "+"] [(numeric,Nothing),(numeric, Nothing)]
+>      (Right ([numeric,numeric],numeric))-}
+
+
+>     ]
+>   where
+>     _intNotNull = TypeExtra typeInt Nothing Nothing False
+>     _intNull = TypeExtra typeInt Nothing Nothing True
+>     _unk = TypeExtra UnknownType Nothing Nothing False
+>     _te s = TypeExtra s Nothing Nothing False
+>     _numeric = TypeExtra typeNumeric (Just 15) (Just 2) False
+>     typeInt = ScalarType "int4"
+>     typeNumeric = ScalarType "numeric"
+
+text conversions
+  do something similar to numeric with pairs of string types
+  and the || op
+domains
+  do a simple test for these
+function style cast: test some success and fails
+time types
+  can do something similar to numeric ops?
+binary strings
+  don't have these right now
+
+review each branch in the matchapp and fix it
+
+precision tests
+nullability tests
+
+what are all the special cases currently:
+special cases for precision
+special cases for result null
+in OldTypeConverion.findCallMatch:
+   between, not between, greatest, least
+   rowctor
+   .
+   comparisons for composite/set types
+more stuff in TypeConversion.matchApp
+  sql server date stuff
+  decode
+  something to do with datetimes?
+  string precisions?:
+    ||, substring, replace
+  some nullability special cases?
+  more stuff
+SqlTypeConversions: special case for implicit casts from text types to
+  numeric (see if can handle in rule system)
+ScalarExprs.ag
+  needs implicit cast
+  implicit cast type
+  check the types (e.g. cast syntax should use this typeconversion
+   machinery)
+  tcAppLike: more mssql date stuff
+
+  getmaybeintsfromliterals: also suggests only need to support int
+    literals in the matchapp function here
+
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/Updates.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/Updates.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/Updates.lhs
@@ -0,0 +1,241 @@
+
+This file tests the basic typechecking for non query dml (aka updates).
+
+insert
+update
+delete
+copy from
+copy to
+truncate
+
+
+> {-# LANGUAGE OverloadedStrings #-}
+> module Database.HsSqlPpp.Tests.TypeChecking.Updates
+>     (updates) where
+
+> --import Database.HsSqlPpp.Internals.TypesInternal
+> import Database.HsSqlPpp.Tests.TestTypes
+> --import Database.HsSqlPpp.Types
+> import Database.HsSqlPpp.Catalog
+> import Database.HsSqlPpp.Dialect
+> --import Database.HsSqlPpp.TypeChecker
+> import Database.HsSqlPpp.Types
+
+> import Database.HsSqlPpp.Tests.TypeChecking.Utils
+> --import Database.HsSqlPpp.Internals.TypesInternal hiding (mkTypeExtra,mkTypeExtraNN)
+
+> updates :: Item
+> updates =
+>   Group "updates"
+>   [Group "tcinsert"
+>   [
+
+simplest insert
+
+>    tcStatements simpleTEnv
+>    "insert into t values (1,'2');"
+>    $ Nothing
+
+too many values
+
+>   ,tcStatements simpleTEnv
+>    "insert into t values (1,'2',3);"
+>    $ Just [TooManyColumnsInInsert]
+
+too few values: this is ok, not currently statically checked
+
+>   ,tcStatements simpleTEnv
+>    "insert into t values (1);"
+>    $ Nothing
+
+
+bad types in one row of multi values
+todo: I'm not sure this is correct.
+
+For an insert, I think you should see if there is an assignment cast
+available on a row by row basis, not use the resolve result set on
+each value row. For values in every other context, I think you should
+use the resolve result set. This will change the error message when it
+fails, and probably give different results in some unusual scenarios.
+
+>   ,tcStatements simpleTEnv
+>    "insert into t values (1,'2'), ('1'::text,2);"
+>    $ Just [IncompatibleUnionTypes
+>           -- todo: how should the column names work?
+>           -- todo: check nullability
+>           -- why does the unknown type string literal already have a precision of 1?
+>           (CompositeType [("", (mkTypeExtra typeInt) {teNullable=False})
+>                          ,("", (mkTypeExtra UnknownType) {teNullable=False,tePrecision=Just 1})])
+>           (CompositeType [("values%0", (mkTypeExtra $ ScalarType "text") {teNullable=False})
+>                          ,("values%1", (mkTypeExtra typeInt) {teNullable=False})])]
+
+>   ,tcStatements simpleTEnv
+>    "insert into t values ('1'::text,2), (1,'2');"
+>    $ Just [IncompatibleUnionTypes
+>           (CompositeType [("", (mkTypeExtra $ ScalarType "text") {teNullable=False})
+>                          ,("", (mkTypeExtra typeInt) {teNullable=False})])
+>           (CompositeType [("values%0", (mkTypeExtra typeInt) {teNullable=False})
+>                          ,("values%1", (mkTypeExtra UnknownType) {teNullable=False,tePrecision=Just 1})])]
+
+non existent table
+
+>   ,tcStatements simpleTEnv
+>    "insert into zt values (1,'2');"
+>    $ Just [UnrecognisedRelation ("public","zt")]
+
+table with explicit schema
+
+>   ,tcStatements simpleTEnv
+>    "insert into public.t values (1,'2');"
+>    $ Nothing
+
+table with wrong explicit schema
+
+>   ,tcStatements simpleTEnv
+>    "insert into something.t values (1,'2');"
+>    $ Just [UnrecognisedRelation ("something","t")]
+
+name all columns
+
+>   ,tcStatements simpleTEnv
+>    "insert into t(a,b) values (1,'2');"
+>    $ Nothing
+
+name columns in different order
+
+>   ,tcStatements simpleTEnv
+>    "insert into t(b,a) values ('2'::text,1);"
+>    $ Nothing
+
+too many values for the named columns
+
+>   ,tcStatements simpleTEnv
+>    "insert into t(a) values (1,'2');"
+>    $ Just [TooManyColumnsInInsert]
+
+>   ,tcStatements simpleTEnv
+>    "insert into t(a,b) values (1,'2',3);"
+>    $ Just [TooManyColumnsInInsert]
+
+The typechecker will never catch this issue for now, even if it is
+statically determinable that the insert will fail because of defaults/
+not null.
+
+>   ,tcStatements simpleTEnv
+>    "insert into t(a) values (1);"
+>    $ Nothing
+
+name wrong column
+
+>   ,tcStatements simpleTEnv
+>    "insert into t(a,c) values (1,'2');"
+>    $ Just [UnrecognisedIdentifier "c"]
+
+duplicate columns
+
+>   ,tcStatements simpleTEnv
+>    "insert into t(a,b,a) values (1,'2',1);"
+>    $ Just [DuplicateColumnName "a"]
+
+***todo: implicit casts
+make sure to check casts which are assignment and not implicit
+also works with no column names given
+
+1. implicit casts from literals: already tested
+
+2. implicit casts from typed expressions
+
+>   --,tcStatements simpleTEnv
+>   -- "insert into t(a,b) values (1::int8,'2');"
+>   -- $ Nothing
+
+3. casts which are only available explicitly: for now treated no
+different to casts which aren't possible at all, in future could give
+a nicer error message
+
+>   --,tcStatements simpleTEnv
+>   -- "insert into t(a,b) values ('1'::text,'2');"
+>   -- $ Just []
+
+4. casts which aren't possible at all
+
+>   --,tcStatements simpleTEnv
+>   -- "insert into t(a,b) values ('2005-01-01'::interval,'2');"
+>   -- $ Just []
+
+
+*** todo: repeat tests above with all the other queryexpr ctors:
+select, with, setops
+
+*** todo: check multiple values rows use resolve result set algo
+outside of insert, and use row by row assignment casts in an insert
+
+todo: more checking with presence of defaults/nulls?
+
+todo: returning
+
+see also InsertQueryExprs.lhs for some typechecking tests for insert
+
+= update
+
+regular update
+row style update
+wrong table name
+explicit schema
+qualified assignment targets, good and bad
+wrong column name
+simple where
+where with wrong col
+other type check fail in where
+
+TODO: from list, returning
+
+= delete
+
+simple delete
+with schema
+bad table name
+bad schema
+simple where
+where with wrong col
+where with non bool
+
+todo: using and returning
+
+= copy from
+
+can't check the copy from source, but can check the columns
+
+simple copy from
+with column names
+different order column names
+missing columns
+non existent columns
+repeated column
+schema table name
+bad table name
+bad schema
+
+= copy to
+
+check table name and column names
+
+check simple good and bad queries
+
+= truncate
+
+check table names + schema options
+
+>   ]
+>   ]
+>   where
+>     simpleTEnv = [CatCreateTable ("public","t")
+>                   [("a", mkCatNameExtra "int4")
+>                   ,("b", mkCatNameExtra "text")]]
+>     _anotherUEnv = [CatCreateTable ("something","u")
+>                   [("a", mkCatNameExtra "int4")
+>                   ,("b", mkCatNameExtra "text")]]
+>     tcStatements cus =
+>         let cat = makeCatalog postgresDialect cus
+>         in TCStatements cat defaultTypeCheckFlags {tcfDialect=postgresDialect}
+>     typeInt = ScalarType "int4"
diff --git a/tests/Database/HsSqlPpp/Tests/TypeChecking/Utils.lhs b/tests/Database/HsSqlPpp/Tests/TypeChecking/Utils.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Tests/TypeChecking/Utils.lhs
@@ -0,0 +1,11 @@
+
+
+> module Database.HsSqlPpp.Tests.TypeChecking.Utils where
+
+> import Database.HsSqlPpp.Types
+
+> mkTypeExtra :: Type -> TypeExtra
+> mkTypeExtra t = TypeExtra t Nothing Nothing True
+
+> mkTypeExtraNN :: Type -> TypeExtra
+> mkTypeExtraNN t = TypeExtra t Nothing Nothing False
diff --git a/tests/Database/HsSqlPpp/Utils/GroomUtils.lhs b/tests/Database/HsSqlPpp/Utils/GroomUtils.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Utils/GroomUtils.lhs
@@ -0,0 +1,85 @@
+
+Utilities to show asts more nicely
+
+groomAAnns: show anns as A
+groomTypes: show anns as Type|TypeErrors
+
+
+> module Database.HsSqlPpp.Utils.GroomUtils
+>     (groomNoAnns
+>     --,groomAAnns
+>     ,groomTypes) where
+>
+> --import qualified Text.Groom as G
+> import Language.Haskell.Exts
+> import Data.Generics.Uniplate.Data
+
+> --groomAAnns = undefined
+
+> groomNoAnns :: Show a => a -> String
+> groomNoAnns = groomF $ const $ Con $ UnQual $ Ident "A"
+
+> groomF :: Show a => (Exp -> Exp) -> a -> String
+> groomF f s =
+>   case parseExp (show s) of
+>     ParseOk ast -> prettyPrint (g ast)
+>     x -> error $ show x
+>   where
+>     g = transformBi $ \x ->
+>                case x of
+>                  RecConstr (UnQual (Ident "Annotation")) _ ->
+>                           f x
+>                  x' -> x'
+
+
+> groomTypes :: Show a => a -> String
+> groomTypes = groomF $ \x -> case x of
+>   RecConstr (UnQual (Ident "Annotation"))
+>    [FieldUpdate _ _,
+>     FieldUpdate (UnQual (Ident "anType")) t,
+>     FieldUpdate (UnQual (Ident "anErrs")) (List errs),
+>     FieldUpdate _ _,
+>     FieldUpdate _ _] -> case (t,errs) of
+>                              (Con (UnQual (Ident "Nothing")),[]) ->
+>                                  Con (UnQual (Ident "A"))
+>                              (y,[]) -> y
+>                              (_,z) -> List z
+>   x' -> x'
+
+
+
+
+ (RecConstr (UnQual (Ident "Annotation"))
+      [FieldUpdate (UnQual (Ident "asrc"))
+         (Con (UnQual (Ident "Nothing"))),
+       FieldUpdate (UnQual (Ident "atype"))
+         (Con (UnQual (Ident "Nothing"))),
+       FieldUpdate (UnQual (Ident "errs")) (List []),
+       FieldUpdate (UnQual (Ident "implicitCast"))
+         (Con (UnQual (Ident "Nothing"))),
+       FieldUpdate (UnQual (Ident "catUpd")) (List [])])
+
+
+>    {-
+>   groomF tte d
+>   where
+>     tte :: Exp -> Exp
+>     tte (Paren
+>                   (App
+>                    (App
+>                     (App
+>                      (App
+>                       (App
+>                        (App (Con (UnQual (Ident "Annotation")))
+>                         _) t) te) _) _) _))
+>          = case (t,te) of
+>               (Con (UnQual (Ident "Nothing")) ,List []) ->
+>                  Con (UnQual (Ident "A"))
+>               (y,List []) -> y
+>               (_,x) -> x
+>            {-trace ("\n*************\n"
+>                   ++ groom t
+>                   ++ "\n*************\n"
+>                   ++ groom te
+>                   ++ "\n*************\n") $ Tuple [t,te]-}
+>     tte x = x-}
diff --git a/tests/Database/HsSqlPpp/Utils/Here.lhs b/tests/Database/HsSqlPpp/Utils/Here.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Database/HsSqlPpp/Utils/Here.lhs
@@ -0,0 +1,12 @@
+Simple support for multiline strings
+
+> {-# LANGUAGE TemplateHaskell #-}
+> module Database.HsSqlPpp.Utils.Here where
+> import Language.Haskell.TH.Quote
+> import Language.Haskell.TH.Lib
+
+> here :: QuasiQuoter
+> here = QuasiQuoter {quoteExp = litE . stringL
+>                    ,quotePat = litP . stringL
+>                    ,quoteType = error "no quoteType for here"
+>                    ,quoteDec = error "no quoteDec for here"}
diff --git a/tests/Tests.lhs b/tests/Tests.lhs
new file mode 100644
--- /dev/null
+++ b/tests/Tests.lhs
@@ -0,0 +1,28 @@
+test files todo:
+
+create new test hierarchy, move test code here, add new exe to run
+  them
+
+disable failing tests
+
+get website generating again
+
+start new test pages + renderer
+
+
+extensions tests
+
+local bindings tests
+
+parameterized statement tests
+parsertests
+quasiquote tests
+roundtrip tests
+type check tests
+type inference tests
+
+> import Database.HsSqlPpp.Tests.Tests
+> import Test.Tasty
+
+> main :: IO ()
+> main = defaultMain $ testGroup "Tests" $ allTests
