How to create an “on-the-fly” mapping table within a SELECT statement in Postgresql

前端 未结 3 1859
南方客
南方客 2020-12-16 00:30

I\'m creating a select statement that combines two tables, zone and output, based on a referenced device table and on a mapping of

3条回答
  •  心在旅途
    2020-12-16 00:54

    So just to complement the accepted answer, the following code is a valid, self-contained Postgresql expression which will evaluate to an 'inline' relation with columns (zone_number, output_type_id):

    SELECT * FROM 
    (VALUES 
      (1, 101), 
      (2, 202), 
      (3, 303), 
      (4, 304)
    ) as i(zone_number, output_type_id)
    

    (The (VALUES ... AS ...) part alone will not make a valid expression, which is why I added the SELECT * FROM.)

提交回复
热议问题