How to Query a PostgreSQL Database

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
McJazz
Posts: 111
Joined: Sun Apr 04, 2010 5:59 am

How to Query a PostgreSQL Database

Post by McJazz » Sat Mar 12, 2011 6:19 pm

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

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: How to Query a PostgreSQL Database

Post by bangkok » Sat Mar 12, 2011 8:27 pm

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.

McJazz
Posts: 111
Joined: Sun Apr 04, 2010 5:59 am

Re: How to Query a PostgreSQL Database

Post by McJazz » Sat Mar 12, 2011 11:11 pm

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?

McJazz
Posts: 111
Joined: Sun Apr 04, 2010 5:59 am

Re: How to Query a PostgreSQL Database

Post by McJazz » Sun Mar 13, 2011 1:39 am

I found that the syntax of the select statement for PostgreSQL requires the following syntax:

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

Post Reply