Search code examples
pythonpostgresqlplpyplpython

mapping in SD in python


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.


Solution

  • 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'}