views:

70

answers:

3

I'm not used to working with PostgreSQL, but am using Zend_Db_Select to create my queries. What does the error below mean?

SQL error:
ERROR:  schema "il" does not exist

In statement:
SELECT il.count(*) AS "count" FROM "image_lite" AS "il" 
INNER JOIN "exif_parse" AS "ex" ON il.image_id = ex.image_id 
WHERE (ex.cam_make = 'apple')
+5  A: 

You can think of schema in PostgreSQL as you would a database in MySQL. Also try removing the double quotes around everything because that's just plain strange and might be causing the problem.

Oh I see il.count(*) make no sense at all.

Just do this instead:

select count(*) cnt       
  from image_lite il 
  join exif_parse ex on il.image_id = ex.image_id 
 where ex.cam_make = 'apple'
Khorkrak
+1 for removing the double-quotes. That irritates me just as much when people backtick the heck out of everything in a MySQL statement... probably where the bad habit came from!
Charles
The quotes are automatically inserted by the Zend_Db_Select
Ben Dauphinee
quotes can lead to unexpected behaviours in postgresql if identifiers are not lowercase (not your case but anyway). Khorkrak gives the correct sane syntax
leonbloy
+6  A: 

It's parsing il.count(*) as a call to a function "count" in the schema "il". Probably what you want is the expression:

count(il.*)
Edmund
+1  A: 

Postgres is interpreting the "il" in "il.count(*)" as a schema name. You can simply omit it and ask for count(*), or if you want to get specific, count(il.*)

If you're coming from MySQL, schemas are what the rest of the world calls what MySQL calls a database.

Charles