add support for functions in tablerefs
This commit is contained in:
parent
adfeac8d16
commit
d49b3ddb99
|
@ -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 =
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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\
|
||||
|
|
|
@ -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"])
|
||||
|
||||
|
|
Loading…
Reference in a new issue