0

Hi I want to map the sd keys and values from the result of two different query. to make it more clear i have written code.

rv = plpy.execute(select id from ABC);
if this returns 1, 2, 3

rv =  plpy.execute(select name from XYZ);
if this returns A,B,C

Now I need a way where I can map these two ids, so that id retrieved from first query can be used as key and name retrieved from second query can be used as values, so i will have something like

SD[1] = A 
SD[2] = B 
SD[3] = C 

THis is needed as I am trying to create dynamic SD for my application. Can somebody suggest me some solution.

Milen A. Radev
  • 60,241
  • 22
  • 105
  • 110
Rohita Khatiwada
  • 2,835
  • 9
  • 40
  • 52
  • 1
    This is the *wrong way* to do things. SD is a a private static data variable (as in yucky C type behaviour) that is basically a hack for pl/python. Return and collect the data somewhere else. If your two queries are related they should be joined in one sql statement. I have feeling you probably do not need this function at all and could be using sql statements for everything. – nate c Mar 16 '11 at 23:45

1 Answers1

2

I'm unfamiliar with plpy, so maybe I'm totally off. But if what you want to do is to create a python dictionary with key:value-pairs based on results from two queries this is my suggestion:

If these are your queries:

a = [a, b, c]
b = [1, 2, 3] 

Then:

dict(zip(a, b))

Gives you a dictionary like this:

{'a': '1', 'b': '2', 'c': '3'}
eumiro
  • 207,213
  • 34
  • 299
  • 261
Erika
  • 416
  • 5
  • 14