1

I tried uploading modules to redshift through S3 but it always says no module found. please help

CREATE or replace FUNCTION olus_layer(subs_no varchar)
RETURNS varchar volatile AS 
$$ 
import plpydbapi
dbconn = plpydbapi.connect()
cursor = dbconn.cursor()
cursor.execute("SELECT count(*) from busobj_group.olus_usage_detail")
d=cursor.fetchall()
dbconn.close()
return d 
$$ 
LANGUAGE plpythonu;

5
  • Welcome to SO. This no code service site. Please try for yourself first and come back if there's an issue with your script. Commented Nov 3, 2017 at 5:31
  • CREATE or replace FUNCTION olus_layer(subs_no varchar) RETURNS varchar volatile AS $$ import plpydbapi dbconn = plpydbapi.connect() cursor = dbconn.cursor() cursor.execute("SELECT count(*) from busobj_group.olus_usage_detail") d=cursor.fetchall() dbconn.close() return d $$ LANGUAGE plpythonu; Commented Nov 3, 2017 at 6:08
  • above is the code I used, but it is throwing an error of 'module not found'. The module I have packaged according to the Redshift standards only. Commented Nov 3, 2017 at 6:09
  • pls guide me which module to use and share links or answer if anyone has anything useful Commented Nov 3, 2017 at 6:11
  • WHY do you wish to do this? We might be able to offer an alternative. Commented Nov 4, 2017 at 5:42

3 Answers 3

2

You cannot do this in Redshift. so you will need to find another approach.

1) see here for udf constraints http://docs.aws.amazon.com/redshift/latest/dg/udf-constraints.html

2) see here http://docs.aws.amazon.com/redshift/latest/dg/udf-python-language-support.html especially this part:

Important Amazon Redshift blocks all network access and write access to the file system through UDFs.

This means that even if you try to get around the restriction, it won't work!

If you don't know an alternative way to get what you need, you should ask a new question specifying exactly what your challenge is and what you have tried, (leave this question ans answer here for future reference by others)

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

Comments

1

It can't connect to DB inside UDF, Python functions are scalar in Redshift, meaning it takes one or more values and returns only one output value.

However, if you want to execute a function against a set of rows try to use LISTAGG function to build an array of values or objects (if you need multiple properties) into a large string (beware of string size limitation), pass it to UDF as parameter and parse/loop inside the function.

Comments

1

Amazon has recently announced the support for Stored Procedures in Redshift. Unlike a user-defined function (UDF), a stored procedure can incorporate data definition language (DDL) and data manipulation language (DML) in addition to SELECT queries. Along with that, it also supports looping and conditional expressions, to control logical flow.

https://docs.aws.amazon.com/redshift/latest/dg/stored-procedure-overview.html

Comments

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.