As I found SELECT * FROM t INTO my_data;
works only if:
DO $$
DECLARE
my_data t%ROWTYPE;
BEGIN
SELECT * FROM t INTO my_data WHERE id = ?;
END $$;
Am I right?
If I want to get only 2-3 columns instead of all columns. How can I define my_data
?
That is,
DO $$
DECLARE
my_data <WHAT HERE??>;
BEGIN
SELECT id,name,surname FROM t INTO my_data WHERE id = ?;
END $$;
One way: use a
record
variable:Note that the structure of a
record
type is undefined until assigned. So you cannot reference columns (fields) before you do that.Another way: assign multiple scalar variables:
As for your first example:
%ROWTYPE
is just noise in Postgres. The documentation:So: