Forum OpenACS Q&A: Problem getting bootstrapped

Collapse
Posted by Ola Hansson on
Can someone please tell me whats going wrong?

I'm getting a server error when I try to bootstrap myself on a fresh install using Pg 7.1 (checked out yesterday) AOLserver 3.2ad12 and OpenACS 3.2.4 also checked out from cvs yesterday.

When logged in to OpenACS as user 'system' and in /admin/ug clicking "Administration" followed by clicking "Site-Wide Administration" the error occurs (at: http://localhost.localdomain/admin/ug/group.tcl?group_id=1).

Here's the error:
....

[30/Jan/2001:13:39:32][681.23556][-conn10-] Notice: Querying 'select
ad_group_member_p(1, system_administrator_group_id()) from dual;'
[30/Jan/2001:13:39:32][681.23556][-conn10-] Notice: dbinit:
sql(localhost::infogettable): 'select ad_group_member_p(1,
system_administrator_group_id()) from dual'
[30/Jan/2001:13:39:32][681.23556][-conn10-] Error: Ns_PgExec: result
status: 7 message: ERROR:  Attribute 'group_name' not found

[30/Jan/2001:13:39:32][681.23556][-conn10-] Error: dbinit:
error(localhost::infogettable,ERROR:  Attribute 'group_name' not found
): 'select ug.group_id as subgroup_id, group_name as subgroup_name,
ug.registration_date, 
                        ug.approved_p, count(user_id) as n_members,
                        upper(group_name)
                   from user_groups ug, user_group_map ugm
                  where parent_group_id=1
                    and ug.group_id=ugm.group_id
               group by ug.group_id, group_name, ug.registration_date,
ug.approved_p
          union
		  select ug.group_id as subgroup_id, group_name as subgroup_name,
ug.registration_date, 
                        ug.approved_p, 0 as n_members,
                        upper(group_name)
                   from user_groups ug
                  where parent_group_id=1 and
                    not exists (select 1 from user_group_map ugm
                      where ug.group_id=ugm.group_id)
           group by ug.group_id, group_name, ug.registration_date,
ug.approved_p
           order by upper(group_name)'
[30/Jan/2001:13:39:32][681.23556][-conn10-] Error: Database operation
"select" failed (exception NSDB, "Query was not a statement returning
rows.")
Database operation "select" failed (exception NSDB, "Query was not a
statement returning rows.")
    while executing
"ns_db select $db  "select ug.group_id as subgroup_id, group_name as
subgroup_name, ug.registration_date, 
                        ug.approved_p, count ..."
    invoked from within
"set selection [ns_db select $db  "select ug.group_id as subgroup_id,
group_name as subgroup_name, ug.registration_date, 
                        ug.ap ..."
    invoked from within
"if { [empty_string_p $parent_group_id] } {
	set subgroup_html 

....

I've only succeeded with intalling Open ACS about ten times before, so surely it's some obvious error from my side...

Thanks!
Collapse
Posted by Don Baccus on
OK, here's a nasty little secret ...

PG doesn't properly handle "order by" combined with "union".  I knew
this when we started porting the ACS to Postgres, but decided to
ignore the problem.  The "union" clauses are a result of unfolding
outer joins, and the "order by" only orders the last clause.  This is
a non-fatal annoyance in most cases.  I knew that eventually we'd get
both outer joins and fixed union statements, and figured that leaving
the "order by" clauses in would result in the pages magically working
better once unions were fixed.  I also figured that removing the
non-working "order by" clauses wouldn't result in any improvement to the
query's output in the interim, so why bother?

Well, PG 7.1 got outer joins but didn't get fixed union statements,
which won't happen until PG 7.2.

And to top it off, PG 7.1 is stricter on "union" and "order by"
clauses, and there are some combinations it won't allow at all.  The
error message you're getting is as a result of the new restrictions.
I can't blame the PG folk for adding it, as the query as written never
worked exactly the way one would think it did anyway.  But it is a
pain in the rear for us.

I ran into this exact query myself about a week ago, when I built a
small OpenACS+PG7.1 site for a project my girlfriend's working on.  I
just rewrote it as an outer join.  But ... I can't check that in, of
course, because PG 7.0 doesn't have outer joins.  I tried rewriting
the query in various ways to get PG to accept the "order by" clause,
but without success.

Are you running beta3 or beta4?

You might want to post this query to the pg hackers list to see if it
is intended that this particular case give an error message.

So far I've only run into a couple of queries that the new checks trip
up, but I've not tried more complex modules like e-commerce and intranet.

I wish ACS 4.1 were more complete, users will really need to use 3.2x
for some time and PG 7.1 offers some very significant advantages over
PG 7.0, like lots of bug fixes and much higher insert/update speed.

Collapse
Posted by Dan Wickstrom on
Don,

I've had good results by using an alias term to order by in a union clause. I recreated the error above and then changed it as follows:


acspg=# select   ug.group_id as subgroup_id, 
acspg-#          group_name as subgroup_name, 
acspg-#          ug.registration_date, 
acspg-#          ug.approved_p, count(user_id) as n_members,
acspg-#          upper(group_name) as u_gname
acspg-#     from user_groups ug, user_group_map ugm
acspg-#    where parent_group_id=1
acspg-#      and ug.group_id=ugm.group_id
acspg-# group by ug.group_id, group_name, ug.registration_date, ug.approved_p
acspg-#     union
acspg-#    select ug.group_id as subgroup_id, 
acspg-#           group_name as subgroup_name, ug.registration_date, 
acspg-#           ug.approved_p, 0 as n_members,
acspg-#           upper(group_name) as u_gname
acspg-#      from user_groups ug
acspg-#     where parent_group_id=1 
acspg-#       and not exists (select 1 from user_group_map ugm
acspg(#                        where ug.group_id=ugm.group_id)
acspg-#  group by ug.group_id, group_name, ug.registration_date, ug.approved_p
acspg-#  order by u_gname;
 subgroup_id | subgroup_name | registration_date | approved_p | n_members | u_gname 
-------------+---------------+-------------------+------------+-----------+---------
(0 rows)

acspg=# select version();
                               version                               
---------------------------------------------------------------------
 PostgreSQL 7.1beta3 on sparc-sun-solaris2.7, compiled by GCC 2.95.2
(1 row)

acspg=# 

Here it doesn't crash, but since I don't have anything that matches the query, you can't tell if the ordering is correct. However, I have used this trick on other work that I do outside of openacs, and it has worked well in the past.

Collapse
Posted by Don Baccus on
I could swear I tried an alias in my poking around, but I guess not.

Harumph :(

That's good news, though - thanks.  We'll want some volunteers to more thoroughly test 3.2 with PG 7.1 and to rewrite these queries as needed.  Any takers?

Collapse
Posted by Ola Hansson on
Thanks Dan and Don, you're the best (but you already know that😉!

I'm running beta4 and with the changes outlined by Dan it's working like a charm.
Don, since IOU I'll promise to take on your request and do my best to test the modules and rewrite queries as long as it's within my capability of doing so...I will keep y'all informed. Thanks again for your quick replies.
acspg=# select   ug.group_id as subgroup_id, 
    acspg-#          group_name as subgroup_name, 
    acspg-#          ug.registration_date, 
    acspg-#          ug.approved_p, count(user_id) as n_members,
    acspg-#          upper(group_name) as u_gname
    acspg-#     from user_groups ug, user_group_map ugm
    acspg-#    where parent_group_id=1
    acspg-#      and ug.group_id=ugm.group_id
    acspg-# group by ug.group_id, group_name, ug.registration_date, ug.approved_p
    acspg-#     union
    acspg-#    select ug.group_id as subgroup_id, 
    acspg-#           group_name as subgroup_name, ug.registration_date, 
    acspg-#           ug.approved_p, 0 as n_members,
    acspg-#           upper(group_name) as u_gname
    acspg-#      from user_groups ug
    acspg-#     where parent_group_id=1 
    acspg-#       and not exists (select 1 from user_group_map ugm
    acspg(#                        where ug.group_id=ugm.group_id)
    acspg-#  group by ug.group_id, group_name, ug.registration_date, ug.approved_p
    acspg-#  order by u_gname;
Collapse
Posted by Ola Hansson on
Hmm..

I thought I was doing well rewriting the almost twenty queries I've found so far (most of witch were in the intranet module). It turns out that I'm unsure of what to do with some "order by" clauses containing "upper()" functions that PG 7.1 can't seem to handle..

Usually I can't put the "upper()" stuff in the select part of the query because I don't feel like displaying an upper-case name for example. It doesn't seem like a good idea to drop the functions either.

Suggestions?

Collapse
Posted by Don Baccus on
I've committed the fix to group.tcl, you might want to get a copy and
make sure I didn't screw anything up, though I did test it under PG 7.0.

As far as your other question goes, the query we've been speaking of
demonstrates how to get around your problem:

select the_column, upper(the_column) as upper_the_column
from the_table
order by upper_the_column

In other words, return the column twice, once in upper case for
ordering purposes, and once in its stored form to be used when your
script prints out the column's value.

Collapse
Posted by Ola Hansson on
OK, thats much better, thanks.

Because each UNION query must have the same number of columns I guess I'm supposed to do the same duplication of columns (for ordering purposes) in both parts...and also, it seems wise to me to lean towards making the queries easily readable as opposed to skipping some column prefixes here and there in JOIN queries (and thereby gaining speed?).

Where shall I send the diffs when I'm done?

Collapse
Posted by Ken Kennedy on
Are the diffs for this fix in CVS yet? Luckily, I found this thread before I went crazy...*grin*. My "solution" was to lose the ORDER BY, but I like this one better...and I haven't found them all yet, so a fix in one fell swoop (from CVS or diff) would be great!
Collapse
Posted by Dan Wickstrom on
The one in www/admin/ug/group.tcl has been fixed in CVS.
Collapse
Posted by Chris Hardy on
Is 3.2.5 planning on being Pg 7.1b4 friendly at all? I grabbed the Sourceforge CVS tree, and as Ola mentioned, the union problems  breaks the intranet module (pretty badly too). I've  tried to find diff's for this problem, or find somewhere to get this info so that I don't have to do duplicate work. I don't want to be spinning my wheels with the work I do. If anyone has access to the diff that Ola mentions, let me know. In the meantime, it would be nice if people were able to open/close bugs in the modules that are being ported. Does the sdm allow for this kind of granularity with the modules?
Collapse
Posted by Ola Hansson on
Roberto must be working his butt off these days, revamping the documentation, testing contributed material - and now the porting of ACS 4.1...

I have a diff containing (not heavily tested) fixes for around 20 queries, most of which belong to Intranet and Ecommerce. I can send it to those not willing to wait the few days that I believe remain until 3.2.5 is released. I guess the best thing would be to await that release, though.