Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Mar 2004
    Messaggi
    281

    MySQL - problema di priorità tra alias e inner join

    Preciso che la query funziona in locale ma non sul server online.
    Io non posso modificare la query perche' fa parte di un prodotto esterno che devo installare.
    Io posso modificare la configurazione del server online (non chiedetemi pero' di cambiare versione di MySQL)
    config. locale: MySQL: 5.0.24
    conf. online: MySQL 5.0.27

    La query che non funziona e' questa:
    SELECT DISTINCT SGTI.sgti FROM AFRLIMM_Scheda_AFRLIMM IMM, AFRLIMM_Sub_sgti SGTI INNER JOIN AFRLSUP_Scheda_AFRLSUP SUP ON IMM.idk = SUP.rimk WHERE SUP.ubfz = 'VITRN' AND IMM.MainCounter = SGTI.MainReference AND (SGTI.sgti LIKE '%#\___\_#')

    modificandola solo introducendo le parentesi () dopo FROM e prima di INNER JOIN la query funziona.
    La query che funziona e' la seguente:

    SELECT DISTINCT SGTI.sgti FROM ( AFRLIMM_Scheda_AFRLIMM IMM, AFRLIMM_Sub_sgti SGTI) INNER JOIN AFRLSUP_Scheda_AFRLSUP SUP ON IMM.idk = SUP.rimk WHERE SUP.ubfz = 'VITRN' AND IMM.MainCounter = SGTI.MainReference AND (SGTI.sgti LIKE '%#\___\_#')

    Avete qualche idea ?

  2. #2
    Utente di HTML.it
    Registrato dal
    Mar 2004
    Messaggi
    281
    #

    Previously, the comma operator (,) and JOIN both had the same precedence, so the join expression t1, t2 JOIN t3 was interpreted as ((t1, t2) JOIN t3). Now JOIN has higher precedence, so the expression is interpreted as (t1, (t2 JOIN t3)). This change affects statements that use an ON clause, because that clause can refer only to columns in the operands of the join, and the change in precedence changes interpretation of what those operands are.

    Example:

    CREATE TABLE t1 (i1 INT, j1 INT);
    CREATE TABLE t2 (i2 INT, j2 INT);
    CREATE TABLE t3 (i3 INT, j3 INT);
    INSERT INTO t1 VALUES(1,1);
    INSERT INTO t2 VALUES(1,1);
    INSERT INTO t3 VALUES(1,1);
    SELECT * FROM t1, t2 JOIN t3 ON (t1.i1 = t3.i3);

    Previously, the SELECT was legal due to the implicit grouping of t1,t2 as (t1,t2). Now the JOIN takes precedence, so the operands for the ON clause are t2 and t3. Because t1.i1 is not a column in either of the operands, the result is an Unknown column 't1.i1' in 'on clause' error. To allow the join to be processed, group the first two tables explicitly with parentheses so that the operands for the ON clause are (t1,t2) and t3:

    SELECT * FROM (t1, t2) JOIN t3 ON (t1.i1 = t3.i3);

    Alternatively, avoid the use of the comma operator and use JOIN instead:

    SELECT * FROM t1 JOIN t2 JOIN t3 ON (t1.i1 = t3.i3);

    This change also applies to statements that mix the comma operator with INNER JOIN, CROSS JOIN, LEFT JOIN, and RIGHT JOIN, all of which now have higher precedence than the comma operator.

  3. #3
    Previously, the SELECT was legal due to the implicit grouping of t1,t2 as (t1,t2). Now the JOIN takes precedence, so the operands for the ON clause are t2 and t3. Because t1.i1 is not a column in either of the operands, the result is an Unknown column 't1.i1' in 'on clause' error. To allow the join to be processed, group the first two tables explicitly with parentheses so that the operands for the ON clause are (t1,t2) and t3:

    SELECT * FROM (t1, t2) JOIN t3 ON (t1.i1 = t3.i3);
    http://dev.mysql.com/doc/refman/5.1/en/join.html

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

  4. #4
    Utente di HTML.it
    Registrato dal
    Mar 2004
    Messaggi
    281
    Trovato anche io.
    Il problema e' che le query io non le posso riscrivere.

    Non ci sara' qualche settaggio su mysql per farlo "ragionare" come prima ?

  5. #5
    Originariamente inviato da alspam
    Trovato anche io.
    Il problema e' che le query io non le posso riscrivere.

    Non ci sara' qualche settaggio su mysql per farlo "ragionare" come prima ?
    non credo. La modifica alla sintassi e' di adeguamento allo standard SQL e sopratutto per unificarsi con Max-DB

    Potrebbero esserci anche altre variazioni nelle queries, specie nelle INSERT, per quanto riguarda i parametri gestiti da SQL-MODE.

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.