diff --git a/Language/SQL/SimpleSQL/Parser.lhs b/Language/SQL/SimpleSQL/Parser.lhs index a14d29e..690fab7 100644 --- a/Language/SQL/SimpleSQL/Parser.lhs +++ b/Language/SQL/SimpleSQL/Parser.lhs @@ -505,6 +505,8 @@ tref > tref = nonJoinTref >>= optionSuffix joinTrefSuffix > nonJoinTref = choice [try (TRQueryExpr <$> parens queryExpr) > ,TRParens <$> parens tref +> ,try (TRFunction <$> identifierString +> <*> parens (commaSep scalarExpr)) > ,TRSimple <$> identifierString] > >>= optionSuffix aliasSuffix > aliasSuffix j = diff --git a/Language/SQL/SimpleSQL/Pretty.lhs b/Language/SQL/SimpleSQL/Pretty.lhs index 5d7a022..f7c1f0e 100644 --- a/Language/SQL/SimpleSQL/Pretty.lhs +++ b/Language/SQL/SimpleSQL/Pretty.lhs @@ -182,6 +182,8 @@ > ,nest 5 $ vcat $ punctuate comma $ map tr ts] > where > tr (TRSimple t) = text t +> tr (TRFunction f as) = +> text f <> parens (commaSep $ map scalarExpr as) > tr (TRAlias t a cs) = > sep [tr t > ,text "as" <+> text a diff --git a/Language/SQL/SimpleSQL/Syntax.lhs b/Language/SQL/SimpleSQL/Syntax.lhs index 6e58c30..9cfc630 100644 --- a/Language/SQL/SimpleSQL/Syntax.lhs +++ b/Language/SQL/SimpleSQL/Syntax.lhs @@ -195,6 +195,8 @@ I'm not sure if this is valid syntax or not. > | TRAlias TableRef String (Maybe [String]) > -- | from (query expr) > | TRQueryExpr QueryExpr +> -- | from function(args) +> | TRFunction String [ScalarExpr] > deriving (Eq,Show,Read) TODO: add function table ref diff --git a/tools/Language/SQL/SimpleSQL/Postgres.lhs b/tools/Language/SQL/SimpleSQL/Postgres.lhs index 2f2f4b3..5d6cd32 100644 --- a/tools/Language/SQL/SimpleSQL/Postgres.lhs +++ b/tools/Language/SQL/SimpleSQL/Postgres.lhs @@ -51,17 +51,17 @@ queries section > ,"SELECT * FROM people AS mother JOIN people AS child ON mother.id = child.mother_id;" > ,"SELECT * FROM my_table AS a CROSS JOIN my_table AS b;" > ,"SELECT * FROM (my_table AS a CROSS JOIN my_table) AS b;" -> --,"SELECT * FROM getfoo(1) AS t1;" -- function tableref -> {-,"SELECT * FROM foo\n\ +> ,"SELECT * FROM getfoo(1) AS t1;" -- function tableref +> ,"SELECT * FROM foo\n\ > \ WHERE foosubid IN (\n\ > \ SELECT foosubid\n\ > \ FROM getfoo(foo.fooid) z\n\ > \ WHERE z.fooid = foo.fooid\n\ -> \ );"-} -- function tableref +> \ );" > {-,"SELECT *\n\ > \ FROM dblink('dbname=mydb', 'SELECT proname, prosrc FROM pg_proc')\n\ > \ AS t1(proname name, prosrc text)\n\ -> \ WHERE proname LIKE 'bytea%';"-} -- function tableref +> \ WHERE proname LIKE 'bytea%';"-} -- types in the alias?? > --,"SELECT * FROM foo, LATERAL (SELECT * FROM bar WHERE bar.id = foo.bar_id) ss;" -- lateral > ,"SELECT * FROM foo, bar WHERE bar.id = foo.bar_id;" @@ -235,12 +235,12 @@ select page reference > \ FROM actors\n\ > \ WHERE actors.name LIKE 'W%';" -> {-,"WITH t AS (\n\ +> ,"WITH t AS (\n\ > \ SELECT random() as x FROM generate_series(1, 3)\n\ > \ )\n\ > \SELECT * FROM t\n\ > \UNION ALL\n\ -> \SELECT * FROM t"-} -- function tref +> \SELECT * FROM t" > {-,"WITH RECURSIVE employee_recursive(distance, employee_name, manager_name) AS (\n\ > \ SELECT 1, employee_name, manager_name\n\ diff --git a/tools/Language/SQL/SimpleSQL/TableRefs.lhs b/tools/Language/SQL/SimpleSQL/TableRefs.lhs index feeb67f..e00e74c 100644 --- a/tools/Language/SQL/SimpleSQL/TableRefs.lhs +++ b/tools/Language/SQL/SimpleSQL/TableRefs.lhs @@ -13,6 +13,9 @@ expression > [("select a from t" > ,ms [TRSimple "t"]) +> ,("select a from f(a)" +> ,ms [TRFunction "f" [Iden "a"]]) + > ,("select a from t,u" > ,ms [TRSimple "t", TRSimple "u"])