Pooja
Pooja

Reputation: 333

Trying to declare a variable of a table type, and print its value in PostgreSQL

Below syntax I have used.

 declare
      v_data emp_tab ;
    BEGIN
      select * into v_data from emp_tab where emp_id= 121 limit 1;
      raise notice 'Value: %', v_data.emp_info;
    END;

which is throwing an error. "syntax error at or near emp_tab" Kindly help.

Upvotes: 0

Views: 56

Answers (1)

Oto Shavadze
Oto Shavadze

Reputation: 42763

Try this:

do $$
    declare
    v_data emp_tab ;
    BEGIN
        select * into v_data from emp_tab where emp_id= 121 limit 1;
        raise notice 'Value: %', v_data.emp_info;
    END;
$$ language plpgsql

Upvotes: 1

Related Questions