質問からpostgres noob。私はポストグルに2つのテーブルを持っています。回路図については以下を参照してください。postgres select idの配列を別のテーブルから選択しました
strains_snps::table
name::str
variants_id::int array
variants::table
id::int
ref_base::str
私は
select variants_id
from strains_snps
where strains_snps.name = 'foo'
にしたいし、その後、フォローアップクエリで(int配列である)ことvariants_idを使用しています。パイソンから来る
select *
from variants
where id in the_output_from_previous_query
、I変数に最初のクエリの出力を割り当て、第2のクエリでその変数のメンバーシップを確認することになります。しかし、これはおそらくここでは最善の方法ではありません。これを単一のクエリとして機能させる方法がいくつかあると思いますか?
EDITは@Sumitは、サブクエリを使用して提案しました。私はこれを試みたが、成功しなかった。エラーpgAdminでは返さ
select * from variants
where id in
(select variants_id from strains_snps where name = 'BMD1964')
はこれを試して
ERROR: operator does not exist: integer = integer[]
LINE 2: where id in
^
HINT: No operator matches the given name and argument type(s). You
might need to add explicit type casts.
********** Error **********
ERROR: operator does not exist: integer = integer[]
SQL state: 42883
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Character: 34
お読みくださいhttp://meta.stackoverflow.com/questions/285551/why-may-i-アップロード時画像のコードをアップロードしない285557と受け入れられた答え –
このためにサブクエリを使用することができます。 – Sumit