Forum OpenACS Q&A: ecommerce module throws error when trying to view orders

I'm using aolserver 3.4 with postgres 7.1. When trying to view current orders on my ecommerce site, postgres delivers the following error:

HTTP/1.0 500 Internal Server Error MIME-Version: 1.0 Date: Sun, 04 Nov 2001 22:49:46 GMT Server: AOLserver/3.4 Content- Type: text/html Content-Length: 548 Connection: close

When I go look at the watchdog error log, it says:
Error: dbinit: error(localhost::stirlingdb,ERROR: UNION types "int4" and "bpchar" not matched ): ' (select o.order_id as order_id, o.confirmed_date, o.order_state, ec_total_price(o.order_id) as price_to_display, o.user_id, count(*) as n_items, u.first_names, u.last_name from ec_orders o, users u, ec_items i where o.user_id=u.user_id and o.order_id=i.order_id and o.order_state in ('authorized_plus_avs','authorized_minus_avs','partially_fulfilled',' fulfilled') group by o.order_id, o.confirmed_date, o.order_state, ec_total_price(o.order_id), o.user_id, u.first_names, u.last_name) union (select o.order_id as order_id, o.confirmed_date, o.order_state, ec_total_price(o.order_id) as price_to_display, o.user_id, ''::char as first_names, ''::char as last_name, count(*) as n_items from ec_orders o, ec_items i where 0=(select count(*) from users where user_id= o.user_id) and o.order_id=i.order_id and o.order_state in ('authorized_plus_avs','authorized_minus_avs','partially_fulfilled',' fulfilled') group by o.order_id, o.confirmed_date, o.order_state, ec_total_price(o.order_id), o.user_id, first_names, last_name) order by order_id

I'm trying to debug the code which queries the database in the file /admin/ecommerce/orders/by-order-state-and-time.tcl. Has anybody encountered this problem and could you please offer a solution?

Thanks,
Jason Tauber
The count(*)'s in the two halves of the UNION don't appear in the same column slot.  Try shuffling one or the other to the right position and let us know what happens.  If that works, please submit the patch and bug report to the SDM!
I rearranged the fields so the order matches for the 2 sub-queries, and it works.