Need to convert the %rowtype
of oracle to equivalent in postgresql.
My try:
create table public.test
(
id int,
name varchar(20)
);
insert into test values (1,'A');
insert into test values (2,'B');
insert into test values (3,'C');
Note: I have a variable declare with table %rowtype
using which we are checking multiple different column condition’s as shown below in the example. It’s not working in postgres.
do
$$
declare pky public.test%rowtype;
begin
if pky.id=1
then
raise info 'id:1';
elsif pky.name = 'B'
then
raise info 'name:B';
else
raise info 'false';
end if;
end;
$$;
pky
is a input parameter of function in actual code.
2
Answers
The input parameter can be declared using the table name
For a column type, use
%type
The variable is correctly declared, but you have not assigned any value to it. You can do this with a simple assignment statement
or in a query with
into
or use it as a loop variable
As you can see, the
%rowtype
is not necessary.