Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read type information for nodes objects #15

Open
vbansal22 opened this issue Jul 3, 2018 · 3 comments
Open

Cannot read type information for nodes objects #15

vbansal22 opened this issue Jul 3, 2018 · 3 comments
Labels

Comments

@vbansal22
Copy link

I am trying to parse a SQL query go object, but cannot switch on any of its types. For example

`func TestSQLParseAliasQueryAsObject(t *testing.T) {

var aliasQuery = SELECT s.sl_name, s.sl_avail + shoelace_arrive.arr_quant, current_user, current_timestamp FROM shoelace_arrive shoelace_arrive, shoelace_data shoelace_data, shoelace_data s WHERE s.sl_name = shoelace_arrive.arr_name AND shoelace_data.sl_name = s.sl_name AND s.sl_avail + shoelace_arrive.arr_quant <> s.sl_avail

fmt.Print("TestSQLParseTree --->")
tree, err := pg_query.Parse(aliasQuery)
nodes := tree.Statements

fmt.Println(len(nodes))
for key, value := range nodes {
	fmt.Printf("The key is %v", key)
	switch valueType := value.(type) {
	case nodes.RawStmt: //nodes.RawStmt undefined (type []"github.com/lfittl/pg_query_go/nodes".Node has no field or method RawStmt)
	default:
		fmt.Printf("default type is %v", valueType)

	}
	//fmt.Print(reflect.TypeOf(value))
}

if err != nil {
	panic(err)
}
fmt.Printf("%s\n", tree)

}`

Please look at the above switch statement. My code needs to make a decision on whether the type is of nodes.RawStmt. But I get the error shown in comments when I do that.

@lfittl
Copy link
Member

lfittl commented Jul 3, 2018

I'm suspecting the issue here is that you have nodes twice (once as a variable, once as an import)

Could you try renaming the variable in nodes := tree.Statements to something else?

@lfittl lfittl added the question label Jul 3, 2018
@vbansal22
Copy link
Author

Tried giving variable another name (node1), but still getting the same error

nodes1 := tree.Statements

nodes1.RawStmt undefined (type []"github.com/lfittl/pg_query_go/nodes".Node has no field or method RawStmt)

Also I cannot step into the code using the debugger in vscode or atom. However on command line I can. I am using delve

@vbansal22
Copy link
Author

dbservice_test.txt

change extension to .go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants