I am getting the below error for the following Block-
SQL Error [42601]: ERROR: syntax error at or near "int"
Position: 14
BLOCK
declare v_id int;
v_col_1 int;
v_col_1_input int = '21bb232s-3r22-8ns1-ad31-2f78c1c52b7a';
v_audit_datetime timestamp(3);
v_audit_datetime_input timestamp(3) = '2021-09-10 12:02:20';
v_audit_action varchar(100);
Kindly help me in pointing my mistake.
CodePudding user response:
First of all the types like smallint
, integer
, bigint
and int
store whole numbers, that is, numbers without fractional components, of various ranges. Attempts to store values outside of the allowed range will result in an error.
You add a text in a int
value and this is not allowed:
v_col_1_input int = '21bb232s-3r22-8ns1-ad31-2f78c1c52b7a';
Second to avoid the error you should add $$ LANGUAGE plpgsql
to your code:
DO $$
declare
...
begin
...
end;
$$ LANGUAGE plpgsql