有2个table,
tableA{id:int,...} 和tableB{id:int,name:text tags:int[]}
怎么通过 tableB 的name找到相关的tableA中的id我的想法是这样的,
SELECT a.id
  FROM tableA a, tableB b
  where b.name ='a name'
  and b.tags@> {a.id}  ;//但是这里不知道该怎么写
//b.tags@>'{12334}'这样没错,但是'{a.id}'就不是integer了 
在线等待...

解决方案 »

  1.   

    CREATE TABLE planet_osm_nodes
    (
      id integer NOT NULL,
      lat integer NOT NULL,
      lon integer NOT NULL,
      tags text[],
      CONSTRAINT planet_osm_nodes_pkey PRIMARY KEY (id)
    )CREATE TABLE planet_osm_ways
    (
      id integer NOT NULL,
      nodes integer[] NOT NULL,//包含planet_osm_nodes中id的array
      tags text[],
      pending boolean NOT NULL,
      CONSTRAINT planet_osm_ways_pkey PRIMARY KEY (id)
    )
      

  2.   

    主要的问题就怎么把planet_osm_nodes 和planet_osm_ways 
    连接起来
      

  3.   

    和数据内容没关系
    @> : contains ARRAY[1,4,3] @> ARRAY[3,1] 
    要求2边都是array而我的数据一边是array一边是integer
      

  4.   

    select a.id
    from planet_osm_nodes a , planet_osm_ways b
    where a.id = ALL (b.nodes)