Search code examples
vertica

Create Temorary table into Begin and End scope- vertica


I'm trying to create a temporary table within the scope of begin and end:

DO $$
DECLARE
     Is_Full_Exect INT;
BEGIN
     Is_Full_Exect: = 5; - since y refers to x, x = 5
     CREATE TEMP TABLE IF NOT EXISTS StringMapBase (VALUE VARCHAR (300) NULL, AttributeValue INT NULL, AttributeName VARCHAR (80) NOT NULL);
END;
$$;

And accepts the following error:

ERROR 10448: PL / vSQL parser failed at 6.12-15 of source string: syntax error, unexpected IDENT, expecting: = or <- at character 109 LINE 6: CREATE TEMP TABLE IF NOT EXISTS StringMapBase (VALUE VAR ...

I would be very grateful to anyone who can help me understand the error


Solution

  • Three errors to fix:

    1. remove the space between colon : and equal sign = on Line 5
    2. the comment starts with a double dash -- , not single, on Line 5
    3. to perform SQL within a SP, put the PERFORM keyword in front of the statement.
    DO $$
    DECLARE
         Is_Full_Exect INT;
    BEGIN
         Is_Full_Exect:= 5; --- since y refers to x, x = 5
         PERFORM CREATE TEMP TABLE IF NOT EXISTS StringMapBase (VALUE VARCHAR (300) NULL, AttributeValue INT NULL, AttributeName VARCHAR (80) NOT NULL);
    END;
    $$;