Schema
-- syntax to create new schema
CREATE SCHEMA sales;
-- syntax to create new schema
CREATE SCHEMA hr;
-- syntax to rename existing schema
ALTER SCHEMA sales RENAME TO marketing;
-- drop schema, DO THIS CAREFULLY !!
DROP SCHEMA hr;
-- specify the schema for the table explicitly
select * from hr.public.jobs;
-- creating a sample table
CREATE TABLE temporders ( id SERIAL PRIMARY KEY );
-- moving the table from one schema to another
ALTER TABLE public.temporders SET SCHEMA marketing;
-- show current schema
select current_schema();
-- get default search path where the query will start looking
show search_path;
search_path
-----------------
"$user", public
-- order to search path is important
SET search_path to '$user', marketing, public;PG_CATALOG
Last updated