Skip to content

variables inside an Rdi-select statement?!

4 messages · Stephan Holl, Brian Ripley, Michael Dondrup

#
Dear R-users,

I would like to use an environment variable inside an SELECT-statement
from R to a postgres-db, but it will not work and so I need some advice
from you.
<code>
ezg <- Sys.getenv("EZG")
connect <- dbConnect.PgSQL(host="localhost", user="username",
dbname="dbname")
query <-  dbSendQuery(connect, "SELECT ezg.s FROM ezg  WHERE
ezg.s!='12'")
</code>
the error is, that SELECT searches for the relation ezg, but it should
use value stored in ezg.

Any suggestions?

thanks in advance

stephan
#
On Fri, 2 Aug 2002, Stephan Holl wrote:

            
In short, it did what you asked it to, which is not an error.

Use paste() to assemble the string you want to pass.  Nothing you did
tells R that `ezg' in the last line is a reference to an R variable.  I'd
give you an example except I don't see the point of your SQL.  I think you
may mean

paste("SELECT s FROM", ezg, "WHERE s!='12'")
#
Hello,
yes, indeed, that's what I ment. But I shortend my real SQL statement
for the mail-example. I did some left joins and in order to have an
atomic id-field I had to write the relation like this ("SELECT ezg.s
FROM ezg  WHERE
anyway,  thank you for your help!

cheers
  stephan
#
hi,

use paste() to build your query-string.
Stephan Holl wrote:
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._