| 875 | } |
| 876 | |
| 877 | func (c *cc) convertInSelectNode(n *parser.Expr_in_selectContext) ast.Node { |
| 878 | // Check if this is EXISTS or NOT EXISTS |
| 879 | if n.EXISTS_() != nil { |
| 880 | linkType := ast.EXISTS_SUBLINK |
| 881 | sublink := &ast.SubLink{ |
| 882 | SubLinkType: linkType, |
| 883 | Subselect: c.convert(n.Select_stmt()), |
| 884 | } |
| 885 | if n.NOT_() != nil { |
| 886 | // NOT EXISTS is represented as a BoolExpr NOT wrapping the EXISTS |
| 887 | return &ast.BoolExpr{ |
| 888 | Boolop: ast.BoolExprTypeNot, |
| 889 | Args: &ast.List{ |
| 890 | Items: []ast.Node{sublink}, |
| 891 | }, |
| 892 | } |
| 893 | } |
| 894 | return sublink |
| 895 | } |
| 896 | |
| 897 | // Check if this is an IN/NOT IN expression: expr IN (SELECT ...) |
| 898 | if n.IN_() != nil && len(n.AllExpr()) > 0 { |
| 899 | linkType := ast.ANY_SUBLINK |
| 900 | sublink := &ast.SubLink{ |
| 901 | SubLinkType: linkType, |
| 902 | Testexpr: c.convert(n.Expr(0)), |
| 903 | Subselect: c.convert(n.Select_stmt()), |
| 904 | } |
| 905 | if n.NOT_() != nil { |
| 906 | return &ast.A_Expr{ |
| 907 | Kind: ast.A_Expr_Kind_OP, |
| 908 | Name: &ast.List{Items: []ast.Node{&ast.String{Str: "NOT IN"}}}, |
| 909 | Lexpr: c.convert(n.Expr(0)), |
| 910 | Rexpr: &ast.SubLink{ |
| 911 | SubLinkType: ast.EXPR_SUBLINK, |
| 912 | Subselect: c.convert(n.Select_stmt()), |
| 913 | }, |
| 914 | } |
| 915 | } |
| 916 | return sublink |
| 917 | } |
| 918 | |
| 919 | // Plain subquery in parentheses (SELECT ...) |
| 920 | return &ast.SubLink{ |
| 921 | SubLinkType: ast.EXPR_SUBLINK, |
| 922 | Subselect: c.convert(n.Select_stmt()), |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | func (c *cc) convertReturning_caluseContext(n parser.IReturning_clauseContext) *ast.List { |
| 927 | list := &ast.List{Items: []ast.Node{}} |