need the syntax for the tdQuery function in teradataR 1.0.1

Analytics
Enthusiast

need the syntax for the tdQuery function in teradataR 1.0.1

Hi,

Trying to use the tdQuery function to return a subseet of a table into R but cannot locate the syntax.  I see the entry in the function list, but if I click on it in a browser, I get "Page cannot be displayed"

Is anyone activly using this?

Regards,

Alan

3 REPLIES
Teradata Employee

Re: need the syntax for the tdQuery function in teradataR 1.0.1

The tdQuery function simply takes the query you want to run as a parameter so it would be like this:

res <- tdQuery("select * from table where age > 35")

res will contain your result data.frame.

Do you get the help page if you do help(tdQuery) when in your R client or is that not working?

Teradata Employee

Re: need the syntax for the tdQuery function in teradataR 1.0.1

Alan,

You should also be able to use the subset command to accomplish this.  So if you have a td.data.frame(tdf) that points to a table you could do...

newTdf <- subset(tdf, Income > 35000)

res <- as.data.frame(newTdf, size=50000)

You may need to change the size parameter of the as.data.frame command as it defaults to only 100 rows.

Enthusiast

Re: need the syntax for the tdQuery function in teradataR 1.0.1

Hi Todd,

Thank you very much for your responses!!

Was able to get the tdQuery function to work but am not able to run in-database analytic functions with it.

> tdConnect("HQ PRD R")

Loading required package: RODBC

> res <- tdQuery("select usd_direct_exposure_amt from

+ grm_dvl_db.comm_cons_dtl_data where rept_period = 201009")

> td.stats(res,"USD_DIRECT_EXPOSURE_AMT")

Error in td.stats(res, "USD_DIRECT_EXPOSURE_AMT") :

  'tdf' is not a td data frame

> td.stats(res)

Error in td.stats(res) : 'tdf' is not a td data frame

I have used the subset command, but was hoping to apply filters in the db since most of our operations are against one or two periods of data, not the entire set.

If I execute help(tdQuery) a browser window opens, but the site isnt known to our firewall so it requires an authentication step to get to it..  After I verify it i get the "Page Cannot be displayed " message.  That might be something to do with our firewall/security set up here.  Will try it from my home pc tonight to see if i can do it outside the corporate network.