Page 1 of 1

How to Query a PostgreSQL Database

Posted: Sat Mar 12, 2011 6:19 pm
by McJazz
I can successfully connect, but I cannot seem to get a simple select query to work. Anyone have any sample connect and query code?
Thanks

Re: How to Query a PostgreSQL Database

Posted: Sat Mar 12, 2011 8:27 pm
by bangkok
McJazz wrote:I can successfully connect, but I cannot seem to get a simple select query to work. Anyone have any sample connect and query code?
Thanks
Voila.

Code: Select all

--- complete with ip adress, db name, user name and pwd
put revOpenDatabase("postgresql","xxx.Xxx.xxx.XXX","yourdbname","thedbuser","thepaswword") into dbID

if dbID is not a number then 
answer "there is a problem "&dbID
else
answer "You are connected"
end if

put "SELECT * from yourtable" into dbSQL
put revDataFromQuery(, , dbID, dbSQL) into theData
answer theData

revCloseDatabase dbID
Peruse the forum, you'll find plenty other tips.

Re: How to Query a PostgreSQL Database

Posted: Sat Mar 12, 2011 11:11 pm
by McJazz
Thanks ... that is basically what I have tried, but when I use the SQL statement

put "SELECT * FROM Departments" into sql

I get the following message

revdberr,ERROR: relation "departments" does not exist at character 15

I know that the table exists with data and I do get a connection id. Any ideas?

Re: How to Query a PostgreSQL Database

Posted: Sun Mar 13, 2011 1:39 am
by McJazz
I found that the syntax of the select statement for PostgreSQL requires the following syntax:

SELECT "Departments"."name" FROM "Main"."Departments";