2011-10-28 60 views

回答

9

PostgreSQL中有arrays。例如:

CREATE TABLE "token" (
    "id"  integer PRIMARY KEY, 
    "text"  text, 
    "category" text[] 
); 

現在你可以插入多個類別的每一行到token

INSERT INTO "token" ("id", "text", "category") 
VALUES (1, 'some text', ARRAY['cate1', 'cate2']); 

你可以找到類似的行:

SELECT * FROM "token" WHERE 'cate1' = ANY ("category"); 
+0

如果我喜歡的查詢'SELECT * FROM令牌WHERE類別=「cate1'',查詢會在數組內搜索? –

+0

@RenatoDinhaniConceição不,您可以使用'@>'運算符或['ANY'](http://www.postgresql.org/docs/9.0/interactive/functions-comparisons.html#AEN16871)hyperoperator。 – minhee

相關問題