2

Postgresql9.2 と SQLAlchemy0.8 を使用しています。多くの out パラメータを持つストアド プロシージャがデータベースにあり、それらをドット表記で使用したいと考えています。しかし、これまで私は惨めに失敗してきました。以下は私のコードがどのように見えるかです。

私がやっていることを示す例は次のとおりです。

CREATE OR REPLACE FUNCTION stored_proc_name(IN in_user_id bigint, IN in_amount bigint,
OUT pout_one bigint, OUT pout_two bigint )
      RETURNS record AS
$BODY$
begin
    select count(*) as AliasOne into pout_one from tabe_names where conditions;
    select user_name as AliasTwo into pout_two from table_name where condition;
end;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION stored_proc_name(bigint, bigint)
  OWNER TO postgres; 

私のコードスニペットは次のとおりです。

#session object from sessionmaker
result_obj = session.execute(func.stored_proc_name(user_id, amount))
print result_obj.fetechall()
#The above print statement prints following on the console.
>> [('(1,100)',)]

明らかに、上記の結果は文字列をフェッチします。私が欲しいのはresult_obj.pout_one、私のコードでそれを使用するようなものです。

それを達成する方法はありますか?動作するコード スニペットは高く評価されます。

どうもありがとう!

4

1 に答える 1

3

次のようなことを試すことができます:

query = select([column('pout_one'), column('pout_two')], 
               from_obj=[func.stored_proc_name(user_id, amount)])
session.execute(query)

これは、誰かが同様の質問をした SQLAlchemy リストから着想を得ています。これにより、目的の出力が得られる可能性があります (今はテストできません)。

于 2013-09-10T16:42:25.323 に答える