I tried to declare the local variable value
with RECORD[]
type in a DO statement as shown below:
DO $$
DECLARE
value RECORD[];
BEGIN
END
$$;
But, I got the error below:
ERROR: variable "value" has pseudo-type record[]
I referred to these questions and answers but I could not solve the error:
Actually, I could declare value
with RECORD
or INT[]
type without error as shown below:
DO $$
DECLARE
value RECORD;
BEGIN
END
$$;
DO $$
DECLARE
value INT[];
BEGIN
END
$$;
So, how can I declare value
with RECORD[]
type?
2
Answers
Like the error message says,
record
is a pseudo-type. You cannot declare an array based on that. Note how pseudo-types are absent from this list in the manual:I have never had the need for something like
record[]
(which isn’t implemented to begin with). Maybe you can use an array based on a registered row type. But, typically, there is a better way. You would have do disclose what you are trying to achieve.Let me preface by saying I agree that you shouldn’t need that. But can you have it? You sure can:
Your
record[]
is now inside thatrecord
, but it’s there. All I can wish you is good luck using that.If you think about it, a local variable holding an array of records sounds an awful lot like a temp table. If your aim was to do something like this (pseudo-code):
You could just as well: (working demo)