Обсуждение: PGError: ERROR: missing FROM-clause entry for table
I am getting this error: PGError: ERROR: missing FROM-clause entry for table "ca_customs_entry" LINE 1: ..._entries"."is_cadex_transmitted" = 'f') ORDER BY ca_customs... The code is generated by a Ruby-on-Rails-3.0.1 ActiveRecord model: SELECT "ca_customs_shipments".* FROM "ca_customs_shipments" INNER JOIN "ca_customs_entries" ON "ca_customs_entries"."ca_customs_shipment_id" = "ca_customs_shipments"."id" WHERE ("ca_customs_entries"."is_cadex_transmitted" = 'f') ORDER BY ca_customs_entry.is_across_transmitted, ca_customs_entry.is_across_rejected, ca_customs_entry.is_across_accepted, ca_customs_entry.is_cadex_released LIMIT 5 OFFSET 0 From what I have been able to piece together for myself I suspect that the cause may be the absence of an 'AS "alias"' immediately following the 'FROM "ca_customs_shipments"' segment. PG evidently treats this as required element whereas standard SQL does not. If someone could confirm that my suspicions are well founded then I will raise an issue to handle the matter with the software maintainers. On the other hand, if there is another cause of this then I would like to have that information as well. Sincerely, -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB@Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3
On Thu, Nov 25, 2010 at 9:21 PM, James B. Byrne <byrnejb@harte-lyne.ca> wrote:
I am getting this error:
PGError: ERROR: missing FROM-clause entry for table "ca_customs_entry"
LINE 1: ..._entries"."is_cadex_transmitted" = 'f') ORDER BY
ca_customs...
The code is generated by a Ruby-on-Rails-3.0.1 ActiveRecord model:
SELECT "ca_customs_shipments".* FROM "ca_customs_shipments" INNER
JOIN "ca_customs_entries" ON
"ca_customs_entries"."ca_customs_shipment_id" =
"ca_customs_shipments"."id" WHERE
("ca_customs_entries"."is_cadex_transmitted" = 'f') ORDER BY
ca_customs_entry.is_across_transmitted,
ca_customs_entry.is_across_rejected,
ca_customs_entry.is_across_accepted,
ca_customs_entry.is_cadex_released LIMIT 5 OFFSET 0
Looks to me like the problem is you are trying to ORDER BY columns in "ca_customs_entry", but there is no such table for that (don't confuse it with "ca_customs_entries"). You need to either set a matching alias, or fix the table name qualifier in those order by columns.
Robert Treat
play: xzilla.net
work: l42.org/lg
On Thu, November 25, 2010 21:58, Robert Treat wrote: > On Thu, Nov 25, 2010 at 9:21 PM, James B. Byrne > <byrnejb@harte-lyne.ca>wrote: >> > > Looks to me like the problem is you are trying to ORDER BY columns > in > "ca_customs_entry", but there is no such table for that (don't > confuse it > with "ca_customs_entries"). You need to either set a matching > alias, or fix > the table name qualifier in those order by columns. That was exactly the problem. Thank you very much. I am afraid that the mental gymnastics that Rails requires--table names are plural, corresponding model classes are singular--often trips me up. I would never have seen that error on my own. -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB@Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3