Difference between revisions of "Postgres Views"
Jump to navigation
Jump to search
Line 4: | Line 4: | ||
https://hevodata.com/learn/postgresql-stored-procedures/ | https://hevodata.com/learn/postgresql-stored-procedures/ | ||
+ | ### Copy Table | ||
+ | ``` | ||
+ | CREATE TABLE users.chat as SELECT * FROM api.chat; | ||
+ | ``` | ||
− | CREATE | + | ### Create View |
+ | ``` | ||
+ | CREATE VIEW api.chat AS | ||
+ | SELECT id, | ||
+ | name, | ||
+ | user_id, | ||
+ | created_at | ||
+ | FROM users.chat | ||
+ | WHERE (user_id = ( SELECT users.id | ||
+ | FROM public.users | ||
+ | WHERE ((users.username)::text = CURRENT_USER))); | ||
+ | ``` |
Revision as of 16:32, 19 February 2024
SECURITY INVOKER indicates that the function is to be executed with the privileges of the user that calls it. That is the default. SECURITY DEFINER specifies that the function is to be executed with the privileges of the user that created it.
https://hevodata.com/learn/postgresql-stored-procedures/
Copy Table
CREATE TABLE users.chat as SELECT * FROM api.chat;
Create View
CREATE VIEW api.chat AS SELECT id, name, user_id, created_at FROM users.chat WHERE (user_id = ( SELECT users.id FROM public.users WHERE ((users.username)::text = CURRENT_USER)));