I've been learning some PL/pgSQL and am having a hard time declaring and using a table type.
I know this script is dumb and doesn't accomplish anything, I'm just trying to learn.
Here is my query:
do $$
DECLARE
TYPE employee_collection IS TABLE OF employee%ROWTYPE;
emp_data employee_collection;
BEGIN
SELECT *
BULK COLLECT INTO emp_data
FROM employee;
END;
$$
When I run this I get this error: syntax error at or near "TABLE"
.
Everywhere I look online this looks like the way to do this. I even copied most of this code from a website.
Is there a syntax error or is something else going on?
I'm running PostgreSQL 12.11.
I even copied most of this code from a website.
- what website - you say "most" - please show us all of this code and the bits you took - if it was an Oracle PL/SQL site, it's hardly surprising that it won't work exactly as is, even though PL/pgSQL is more or less an effort at cloning Oracle's procedural language.