Skip to content
Advertisement

Postgres: SQL Error [42601]: ERROR: syntax error at or near “int”

I am getting the below error for the following Block-

SQL Error [42601]: ERROR: syntax error at or near “int”

Position: 14

BLOCK

declare id int;
    col_1 int; 
    col_1_input int = '21bb232s-3r22-8ns1-ad31-2f78c1c52b7a'; 
    audit_datetime timestamp(3);
    audit_datetime_input timestamp(3) = '1612-09-10 12:02:20';
    audit_action varchar(100);

Kindly help me in pointing my mistake.

Advertisement

Answer

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
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement