2

私はこれでPL/pgSQL関数をプログラミングしています:

cols_to_select := according to a set of rules, we get the name of the columns

FOR I IN EXECUTE 'SELECT '||cols_to_select||' FROM tabl' LOOP
  -- how to access to fields of record I without knowing their names?
  -- 

END LOOP;
4

1 に答える 1

2

これは私が理解した1つの方法です:

cols_to_select := according to a set of rules, we get the name of the columns

FOR I IN EXECUTE 'SELECT ARRAY['||cols_to_select||'] as AR FROM tabl' LOOP
  -- how to access to fields of record I without knowing their names?
  FOR j IN 1..array_upper(I.ar,1) LOOP
    RAISE NOTICE '%', I.AR[j];
  END LOOP;

END LOOP;

このソリューションの問題は、列のタイプが異なると失敗することです。

于 2009-04-26T18:54:12.317 に答える