Bonjour,
Je cherche à utiliser deux fois le même argument dans une requête mais le
code ci-dessous ne fonctionne pas, une idée :
@staticmethod
def table_query():
and_id = ' '
and_trace = ' '
args = [True]
if Transaction().context.get('trace'):
and_trace = 'AND c.trace = %s '
and_id = 'a.id = %s'
args.append(Transaction().context['trace'])
return ('SELECT DISTINCT ROW_NUMBER() OVER (ORDER BY c.id) AS id, '
'MAX(d.create_uid) AS create_uid, '
'MAX(d.create_date) AS create_date, '
'MAX(d.write_uid) AS write_uid, '
'MAX(d.write_date) AS write_date, '
'c.trace AS trace, '
'c.commune AS commune, '
'c.canton AS canton, '
'd.id AS clc, '
'd.code AS code, '
'case '
' when d.code < 200 then '
' 1 '
' when d.code < 300 then '
' 2 '
' when d.code < 400 then '
' 3 '
' else '
' 4 '
'end as actions, '
'round(cast(st_area(st_intersection(c.geom, d.geom))/10000
AS numeric), 2) AS surface '
'FROM (select ROW_NUMBER() OVER (ORDER BY a.id) AS id, a.id
as trace, b.id as commune, '
'b.name||\' - \'||b.canton as canton,
st_intersection(a.geom, b.geom) as geom '
'FROM sylvia_site_trace a, commune_commune b '
'WHERE %s '
+ and_id +
' '
'AND st_dwithin(a.geom, b.geom,0)) c '
'LEFT JOIN corine_land_cover_clc_geo d '
'ON st_dwithin(c.geom, d.geom,0) '
'WHERE %s '
+ and_trace +
' '
'GROUP BY c.trace, c.commune, c.canton, d.id, c.geom, c.id',
args)