0

I am trying to implement a nested udf in redshift.

select 
     custom_function(custom_function('', column1), column2) 
from 
     table1 

But it says nested udfs are not supported. can someone help me here?

Tried using the python library approach mentioned in the answer and its shown below!!

class f_string:
   def __init__(self, current_value, key, value):
   self.current_value = current_value
   self.key = key
   self.value = value

def f_make_json(self):
   import json
   current_value = json.loads(self.current_value)
   self.value.replace('"', '\"')
   current_value[self.key] = self.value
   return (json.dumps(current_value))

1 Answer 1

0

you have to organize the UDF that you'd like to nest as a Python library and import that library to your cluster, here is the instruction

Sign up to request clarification or add additional context in comments.

6 Comments

not sure I understand how they are supposed to be nested and what exactly did you do in terms of library bundling
i am trying to create a json string. something like this make_json(make_json('{}', 'key1', 'value1'), 'key2', 'value2') which will return {'key1':'value1', 'key2':'value2'}
ah, it's the same function nested... I thought it's different functions nested. Can you try the first function in a subquery and the second function in the outer query?
there could be more than 2 variables. so having multiple subqueries wont be the ideal solution here!!
after all, why don't you just build your json using concatenation operator? I was always doing this and it was pretty easy and clean with proper formatting of the code like every key/value pair on a new line and proper indentation for embedded objects
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.