hi Christian,
I also just got this error message when testing a migration from
sqlite to postgres. Thanks for the diagnosis of the problem.
Have you found a work around yet using the DAL?
Richard
On Aug 10, 4:56 pm, howesc <
how...@umich.edu> wrote:
> This is in Postgres.
>
> I did a little digging, and apparently mixing the JOIN syntax is a
> problem. So if i re-write thequeryin this fashion it works:
>
> SELECT
c.name,
c.id, cp.date,
a.name,
v.name, c.date, af.file
> FROM venue v
> JOIN concert c ON c.venue=
v.id
> JOIN concert_purchases cp ON cp.concert=
c.id
> JOIN artist a ON
a.id=c.artist
> LEFT JOIN audiofile af ON af.concert=
c.id
> WHERE cp.auth_user=3
> AND
c.id=cp.concert
> AND cp.expires>'2009-08-08 09:46:23'
> ORDER BY cp.date DESC;
>
> some others have suggested that mixing the join syntax has operator
> precedence issues, and that Postgres follows the standard while other
> databases let you get away with the "incorrect" syntax:
http://archives.postgresql.org/pgsql-general/2006-09/msg01046.phphttp://stackoverflow.com/questions/187146/inner-join-outer-join-is-th...
>
> based on their analysis a standard compliant SQL parser will interpret
> the web2py generatedquerylike this:
> SELECT
concert.name,
concert.id, concert_purchases.date,
artist.name,
>
venue.name, concert.date, audiofile.file FROM venue, concert,
> concert_purchases, (artist LEFT JOIN audiofile ON
> audiofile.concert=
concert.id) WHERE ((((concert_purchases.auth_user=3
> AND
concert.id=concert_purchases.concert) AND
> concert_purchases.expires>'2009-08-08 09:46:23') AND
>
artist.id=concert.artist) AND
venue.id=concert.venue) ORDER BY
> concert_purchases.date DESC;
>
> note the added parens around the last item in the from clause and the
> LEFT JOIN item - hence concert is not visible. if i re-write it
> knowing the operator precedence like this:
>
> SELECT
concert.name,
concert.id, concert_purchases.date,
artist.name,
>
venue.name, concert.date, audiofile.file
> FROM venue, artist,
> concert_purchases, concert LEFT JOIN audiofile ON
> audiofile.concert=
concert.id WHERE ((((concert_purchases.auth_user=3
> AND
concert.id=concert_purchases.concert) AND
> concert_purchases.expires>'2009-08-08 09:46:23') AND
>
artist.id=concert.artist) AND
venue.id=concert.venue) ORDER BY
> concert_purchases.date DESC;
>
> it also works...which explains to me why some of my left joins work
> and some don't - if i'm lucky and the lasttablein the from clause is
> > > > > query= db((db.concert_purchases.auth_user ==
auth.user.id) &
> > > > > (
db.concert.id == db.concert_purchases.concert) &
> > > > > (db.concert_purchases.expires > now) &
> > > > > (
db.artist.id == db.concert.artist) &
> > > > > (
db.venue.id == db.concert.venue))
> > > > > rows =query.select(
db.concert.name,
db.concert.id,
> > > > > db.concert_purchases.date,
> > > > >
db.artist.name,
> > > > >
db.venue.name,
> > > > > db.concert.date,
> > > > > db.audiofile.file,
> > > > > left=db.audiofile.on(db.audiofile.concert ==
> > > > >
db.concert.id),
> > > > > orderby=~db.concert_purchases.date)
>
> > > > > I have web2py Version 1.63.5 (2009-06-03 23:35:00)
>
> > > > > so, istherea way i can write thequeryto make the left join work,