Difference between revisions of "PostgreSQL: CREATE SCHEMA"
Jump to navigation
Jump to search
(12 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
* https://www.postgresql.org/docs/current/sql-createschema.html | * https://www.postgresql.org/docs/current/sql-createschema.html | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | where role_specification can be: | + | [[CREATE]] [[SCHEMA]] schema_name [ AUTHORIZATION [[role_specification]] ] [ schema_element [ ... ] ] |
+ | CREATE SCHEMA AUTHORIZATION role_specification [ schema_element [ ... ] ] | ||
+ | CREATE SCHEMA IF NOT EXISTS schema_name [ AUTHORIZATION role_specification ] | ||
+ | CREATE SCHEMA IF NOT EXISTS AUTHORIZATION role_specification | ||
+ | |||
+ | where role_specification can be: | ||
+ | |||
+ | user_name | ||
+ | | CURRENT_ROLE | ||
+ | | CURRENT_USER | ||
+ | | SESSION_USER | ||
− | + | == Examples == | |
− | + | Examples | |
− | + | Create a schema: | |
− | |||
− | |||
+ | CREATE SCHEMA myschema; | ||
+ | |||
+ | CREATE SCHEMA IF NOT EXISTS test AUTHORIZATION joe; | ||
+ | CREATE SCHEMA IF NOT EXISTS [[datadog]]; | ||
+ | |||
+ | CREATE SCHEMA AUTHORIZATION joe; | ||
+ | |||
+ | CREATE SCHEMA prometheus AUTHORIZATION prometheus; | ||
+ | |||
+ | CREATE SCHEMA hollywood | ||
+ | [[CREATE TABLE]] films (title text, release date, awards text[]) | ||
+ | [[CREATE VIEW]] winners AS | ||
+ | SELECT title, release FROM films WHERE awards IS NOT NULL; | ||
+ | Notice that the individual subcommands do not end with semicolons. | ||
+ | |||
+ | == Related == | ||
+ | * [[List]] schemas: <code>[[\dn]]</code> | ||
+ | * [[GRANT USAGE ON SCHEMA]] | ||
+ | * [[Amazon Redshift: CREATE SCHEMA]] | ||
== See also == | == See also == |
Latest revision as of 11:27, 8 February 2023
CREATE SCHEMA schema_name [ AUTHORIZATION role_specification ] [ schema_element [ ... ] ] CREATE SCHEMA AUTHORIZATION role_specification [ schema_element [ ... ] ] CREATE SCHEMA IF NOT EXISTS schema_name [ AUTHORIZATION role_specification ] CREATE SCHEMA IF NOT EXISTS AUTHORIZATION role_specification where role_specification can be: user_name | CURRENT_ROLE | CURRENT_USER | SESSION_USER
Examples[edit]
Examples Create a schema:
CREATE SCHEMA myschema;
CREATE SCHEMA IF NOT EXISTS test AUTHORIZATION joe; CREATE SCHEMA IF NOT EXISTS datadog;
CREATE SCHEMA AUTHORIZATION joe;
CREATE SCHEMA prometheus AUTHORIZATION prometheus;
CREATE SCHEMA hollywood CREATE TABLE films (title text, release date, awards text[]) CREATE VIEW winners AS SELECT title, release FROM films WHERE awards IS NOT NULL;
Notice that the individual subcommands do not end with semicolons.
Related[edit]
See also[edit]
- PostgreSQL:
pg_dump, pg_restore
,pgAdmin, pg_config, psql, pg_ctl, pg_isready, initdb
, Role, Schema, DBeaver, Navicat, DataGrip, OmniDB,Adminer
, docker-compose.xml PostgreSQL, PostgreSQL version, PostgreSQL logs,postgresql.conf
,pg_hba.conf, $HOME/.pg_service.conf
, Create database (PostgreSQL), Create user,createdb
,GRANT
,pg_stat
, PostgreSQL VACUUM, EXPLAIN,pg stat activity
, Autovacuum, ALTER DATABASE, PostgreSQL statistics collector, Shared buffers, EXPLAIN (PostgreSQL),EXPLAIN ANALYZE
, Bitmap scan,EXPLAIN VERBOSE
,EXPLAIN VERBOSE (PostgresSQL)
,WAL
,ALTER USER
,CREATE ROLE, CREATE USER
,\du
,show users
,\l
, The Statistics Collector, pganalyze,cron.schedule
, Master,pg_tables
, PostgreSQL replication,CREATE, SET
, TOAST, PgBouncer, Restore DB, Index, meta-commands, Table, foreign table, Schema, Sequence, Views, materialized view, Table Partitioning, monitoring, PostgreSQL System Administration Functions, PostgreSQL extension, privileges, logging, PGTune, PostgreSQL parameter tunning, PostgreSQL modules, pgbench, PostgreSQL users, catalogs
Advertising: