The lua-resty-mysql documentation uses cjson.encode() to demonstrate how to access a mysql select query response. I want to access the "id" column from my response but get error messages. For example, when I cjson.encode() the response to ngx.log() I get (as expected):
[{"weight":2453,"id":"84200"}]
but when I try to access the "id" column from the results table via the following code:
local Query = "SELECT id FROM docs WHERE MATCH(" .. Quoted_Email .. ")"
local Res, Err, Errno, Sqlstate = db:query(Query, 10)
ngx.log(ngx.ERR, "DocID: ", Res["id"])
I get:
DocID: nil
When I try looping through the table with:
for key,value in pairs(Res) do ngx.log(ngx.ERR, key,value) end
I get:
bad argument #2 to 'log' (string, number, boolean, or nil expected, got table)
stack traceback: ...
I verified that Res is a table, how can I access the id column without json encoding the response?
thanks!
- D