I'm trying to do something super simple...or seems it should be. I have a script that truncates and updates a table...it creates unique combinations across three other tables for a dimension build. I was hoping to create a function/procedure that I could call from an application in a single line, rather than trying to store the sql in my application.
We are using postgresql and sqlworkbench/j. My code to create the table includes a view creation, distinct, union, and in insert into using select.
I was trying:
CREATE OR REPLACE FUNCTION update_table()
RETURNS void AS $$
BEGIN
CREATE OR REPLACE VIEW ...
...;
END;
$$ LANGUAGE plpgsql
IMMUTABLE;
I get the error that "Create Function is not supported".
I'm admittedly a sql rookie and everything I have tried has failed, giving me one error after another. Is there a simpler way to do this? Nothing changes in my create statement...no parameters passed in, nada. It's simply that the underlying transactional data is changing and we're only keeping valid combos, so we trunc and reload the table.
Thanks in advance!
http://docs.aws.amazon.com/redshift/latest/dg/c_unsupported-postgresql-features.html
You can create a custom user-defined 'scalar' function though
http://docs.aws.amazon.com/redshift/latest/dg/udf-security-and-privileges.html
http://docs.aws.amazon.com/redshift/latest/dg/udf-creating-a-scalar-sql-udf.html