2

I've been trying to query data from postgresql database (pgadmin) into R and analyse. Most of the queries work except when I try to write a condition specifically to filter out most of the rows. Please find the code below

dbGetQuery(con, 'select * from "db_name"."User" where "db_name"."User"."FirstName" = "Mani" ')

Error in result_create(conn@ptr, statement) : Failed to prepare query: ERROR: column "Mani" does not exist LINE 1: ...from "db_name"."User" where "db_name"."User"."FirstName" = "Mani" ^

this is the error I get, Why is it considering Mani as a column when it is just an element. Someone pls assist me

1 Answer 1

4

String literals in Postgres (and most flavors of SQL) take single quotes. This, combined with a few other optimizations in your code leave us with this:

sql <- "select * from db_name.User u where u.FirstName = 'Mani'"
dbGetQuery(con, sql)

Note that introduced a table alias, for the User table, so that we don't have to repeat the fully qualified name in the WHERE clause.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.