'Create read-only temporary table when user connects
I would like to have a function or stored procedure that runs when a specific user connects to a PSQL database.
More specifically, I would like for a Temporary table to be created when the that user logs in and the user have only read access to that temporary table and nothing else.
Is this possible?
This is what I have so far:
User Setup
CREATE ROLE test_user WITH LOGIN PASSWORD 'test_pw'
NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION VALID UNTIL 'infinity';
GRANT CONNECT ON DATABASE testDB TO test_user;
GRANT USAGE ON SCHEMA testschemaTO test_user;
GRANT SELECT ON temp_table TO test_user; -- when can I do this?
Temp table
CREATE TEMP TABLE temp_table AS
SELECT id
, name
, flag
FROM some_table
WHERE colour LIKE '%blue%'
ORDER BY 1;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
