Hi, ich habe gerade einen Knoten im Hirn und brauche eure Hilfe.
ich habe eine tabelle IDS mit eindeutiger id(bigint)
id value 1 a 2 b 3 c
nun habe ich eine function die verschiedene (für das problem unerhebliche) beziehungen herstellt und mir die ids in arrays ausspuckt.
select function(x) from tabelle y;
{1} {2,3}
nun möchte ich alle einträge aus der tabelle IDS selektieren deren id in den arrays stecken.
Bsp.
select id from IDS where id = ANY(select function(x) from tabelle y)
sagt mir >> more than one row returned by a subquery used as an expression.
also möchte ich das ergebnis von select function(x) from tabelle y zusammenführen so das
{1} {2,3}
zu
{1,2,3} oder von mir aus auch {2,3,1} us.w. wird. jedenfalls das aus den multicols der function eine col wird mit allen werten die es enthält. pgsql kann dazu eingesetzt werden. DB ist Postgres 8.3
Bitte nicht FOR LOOP. das würde die Sache endlos langsam machen.
Liebe Grüße
Sigh
--
https://www.xing.com/profile/Andreas_Kretschmer7ads Das hatte dir akretschmer gestern schon gesagt und siehe da sobald du das machst, funktioniert es ;-)
es gibt kein string_agg auf der 8.3(
habe es auch schon so gehabt das die function(x) kein array zurückgibt sondern die ids
select function(x) from tabelle y where x = 1;
function 1 2
aber das funktioniert dann nicht mit der ganzen tabelle
function(x) from tabelle y where x IN(1,2);
> set-valued function called in context that cannot accept a set
deswegen der Umweg über das Array. Wenn das problem mit dem Set lösbar ist, will ich auch lieber ohne arrays.
Kann man sich bauen:
PostgreSQL: Documentation: Manuals: PostgreSQL 8.3: User-Defined Aggregates
array_accum
Man kann natürlich auch Updaten ...
Andreas
--
https://www.xing.com/profile/Andreas_Kretschmer7ads Das hatte dir akretschmer gestern schon gesagt und siehe da sobald du das machst, funktioniert es ;-)
Updaten steht in den Sternen. Muss durch alle Test prozesse durch etc.. Will ja auch <br><br>wg. array_accum<br><br>select array_accum(array_to_string(function(x),',')) from table y;<br><br><table class="wysiwyg_dashes" width=""><tbody><tr class="wysiwyg_dashes_tr"><td class="wysiwyg_dashes_td">{1,"2,3"}<br></td></tr></tbody></table><br>setze ich das in die nächste ein<br><br>select id from IDS where id = ANY( (select array_accum(array_to_string(function(x),',')) from table y) )<br><br>kommt leider<br><br>>ERROR: operator does not exist: bigint = text[]<br>>HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
auweia
Updaten steht in den Sternen. Muss durch alle Test prozesse durch etc.. Will ja auch
wg. array_accum
select array_accum(array_to_string(function(x),',')) from table y;
{1,"2,3"}
setze ich das in die nächste ein
select id from IDS where id = ANY( (select array_accum(array_to_string(function(x),',')) from table y) )
kommt leider
>> ERROR: operator does not exist: bigint = text[]
>> HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
mache ich es ohne array_to_string
select array_accum(function(x)) from table y;
kommt:
>> ERROR: could not find array type for data type bigint[]
öhm mache ich sowas verrücktes wie
select string_to_array(array_to_string(array_accum(array_ to_string(function(x),',')),','),',') from table y
kommt tatsächlich
{1,2,3} raus
^^
mit schnell hat das dann aber auch nixmehr zu tun.
Links: Tobias Bauer - IT- und Funkdienstleistungen - Bilderrahmen-kaufen.de - Der Onlineshop für Bilderrahmen & Fotorahmen - Funkforum
Lesezeichen