当前位置:网站首页>PostgreSQL create table
PostgreSQL create table
2022-06-11 15:52:00 【happytree001】
One 、 Environmental Science
[email protected]:~$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
[email protected]:~$ /usr/local/pgsql/bin/psql -V
psql (PostgreSQL) 14.2
Two 、 Create table
2.1 grammar
CREATE [ [ GLOBAL | LOCAL ] {
TEMPORARY | TEMP } | UNLOGGED ] TABLE
[ IF NOT EXISTS ] table_name ( [
{
column_name data_type [ COMPRESSION compression_method ]
[ COLLATE collation ] [ column_constraint [ ... ] ]
| table_constraint
| LIKE source_table [ like_option ... ] }
[, ... ]
] )
[ INHERITS ( parent_table [, ... ] ) ]
[ PARTITION BY {
RANGE | LIST | HASH } ( {
column_name |( expression ) } [ COLLATE collation ] [ opclass ] [, ... ] ) ]
[ USING method ]
[ WITH ( storage_parameter [= value] [, ... ] ) | WITHOUT OIDS ]
[ ON COMMIT {
PRESERVE ROWS | DELETE ROWS | DROP } ]
[ TABLESPACE tablespace_name ]
CREATE [ [ GLOBAL | LOCAL ] {
TEMPORARY | TEMP } | UNLOGGED ] TABLE
[ IF NOT EXISTS ] table_name
OF type_name [ ({
column_name [ WITH OPTIONS ] [ column_constraint [ ... ] ]
| table_constraint }
[, ... ]
) ]
[ PARTITION BY {
RANGE | LIST | HASH } ( {
column_name |( expression ) } [ COLLATE collation ] [ opclass ] [, ... ] ) ]
[ USING method ]
[ WITH ( storage_parameter [= value] [, ... ] ) | WITHOUT OIDS ]
[ ON COMMIT {
PRESERVE ROWS | DELETE ROWS | DROP } ]
[ TABLESPACE tablespace_name ]
CREATE [ [ GLOBAL | LOCAL ] {
TEMPORARY | TEMP } | UNLOGGED ] TABLE
[ IF NOT EXISTS ] table_name
PARTITION OF parent_table [ (
{
column_name [ WITH OPTIONS ] [ column_constraint [ ... ] ]
| table_constraint }
[, ... ]
) ] {
FOR VALUES partition_bound_spec | DEFAULT }
[ PARTITION BY {
RANGE | LIST | HASH } ( {
column_name |
( expression ) } [ COLLATE collation ] [ opclass ] [, ... ] ) ]
[ USING method ]
[ WITH ( storage_parameter [= value] [, ... ] ) | WITHOUT OIDS ]
[ ON COMMIT {
PRESERVE ROWS | DELETE ROWS | DROP } ]
[ TABLESPACE tablespace_name ]
where column_constraint is:
[ CONSTRAINT constraint_name ]
{
NOT NULL |
NULL |
CHECK ( expression ) [ NO INHERIT ] |
DEFAULT default_expr |
GENERATED ALWAYS AS ( generation_expr ) STORED |
GENERATED {
ALWAYS | BY DEFAULT } AS IDENTITY
[ ( sequence_options ) ] |
UNIQUE index_parameters |
PRIMARY KEY index_parameters |
REFERENCES reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH
PARTIAL | MATCH SIMPLE ]
[ ON DELETE referential_action ] [ ON UPDATE referential_action
] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY
IMMEDIATE ]
and table_constraint is:
[ CONSTRAINT constraint_name ]
{
CHECK ( expression ) [ NO INHERIT ] |
UNIQUE ( column_name [, ... ] ) index_parameters |
PRIMARY KEY ( column_name [, ... ] ) index_parameters |
EXCLUDE [ USING index_method ] ( exclude_element WITH operator
[, ... ] ) index_parameters [ WHERE ( predicate ) ] |
FOREIGN KEY ( column_name [, ... ] ) REFERENCES reftable
[ ( refcolumn [, ... ] ) ]
[ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ] [ ON
DELETE referential_action ] [ ON UPDATE referential_action ] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY
IMMEDIATE ]
and like_option is:
{
INCLUDING | EXCLUDING } {
COMMENTS | COMPRESSION | CONSTRAINTS |
DEFAULTS | GENERATED | IDENTITY | INDEXES | STATISTICS | STORAGE |
ALL }
and partition_bound_spec is:
IN (partition_bound_expr [, ...] ) |
FROM ( {
partition_bound_expr | MINVALUE | MAXVALUE } [, ...] )
TO ( {
partition_bound_expr | MINVALUE | MAXVALUE } [, ...] ) |
WITH ( MODULUS numeric_literal, REMAINDER numeric_literal )
index_parameters in UNIQUE, PRIMARY KEY, and EXCLUDE constraints
are:
[ INCLUDE ( column_name [, ... ] ) ]
[ WITH ( storage_parameter [= value] [, ... ] ) ]
[ USING INDEX TABLESPACE tablespace_name ]
exclude_element in an EXCLUDE constraint is:
{
column_name | ( expression ) } [ opclass ] [ ASC | DESC ] [ NULLS
{
FIRST | LAST } ]
2.2 Create table
[email protected]:~$ /usr/local/pgsql/bin/psql mydb
psql (14.2)
Type "help" for help.
mydb=# CREATE TABLE mytable (id int, name char(32), age int);
CREATE TABLE
mydb=#
2.3 Delete table
[email protected]:~$ /usr/local/pgsql/bin/psql mydb
psql (14.2)
Type "help" for help.
mydb=# DROP TABLE mytable;
DROP TABLE
mydb=#
- No, show databases/tables; It's not convenient to check , We haven't found out how to look at the existing libraries yet / surface ,
- For tablespaces 、schema Waiting to learn
边栏推荐
- [0006] titre, mots clés et description de la page
- [digital signal processing] correlation function (correlation function property | conjugate symmetry property of correlation function | even symmetry of real signal autocorrelation function | conjugat
- Maui introductory tutorial series (1. framework introduction)
- Kaixia was selected into the 2022 global top 100 innovation institutions list of Kerui Weian
- Using cloud DB to build app quick start - quick application
- AI4DB:人工智能之慢SQL根因分析
- 从屡遭拒稿到90后助理教授,罗格斯大学王灏:好奇心驱使我不断探索
- AGC安全规则是如何简化用户授权和验证请求
- I have used 20K for 5 years and met all major manufacturers. These high-frequency interview questions have helped you figure out
- HowNet has been filed for investigation; Byte beat established Tiktok group or listed in Hong Kong; The nail was exposed to be cut by 30%; Beijing's per capita deposit exceeds 200000 yuan | Q informat
猜你喜欢

泰雷兹云安全报告显示,云端数据泄露和复杂程度呈上升趋势

How to predict SQL statement query time?

鼻孔插灯,智商上升,风靡硅谷,3万就成

如何预测SQL语句查询时间?

码农必备SQL调优(上)

使用Cloud DB构建APP 快速入门-快应用篇

openGauss数据库性能调优概述及实例分析
![[daily question series]: how to test web forms?](/img/80/d0862275b547a7b5224d1c0effa779.jpg)
[daily question series]: how to test web forms?
![[Yugong series] June 2022 Net architecture class 078 worker cluster of distributed middleware schedulemaster](/img/73/5636ba7a0772c4f9e2d1174df40839.png)
[Yugong series] June 2022 Net architecture class 078 worker cluster of distributed middleware schedulemaster

Is it possible to use multiple indexes together in a query?
随机推荐
CF662B Graph Coloring题解--zhengjun
Zero foundation self-study software test, I spent 7 days sorting out a set of learning routes, hoping to help you
Application of AI in index recommendation
数据库密态等值查询概述及操作
Db4ai: database driven AI
Code farming essential SQL tuning (Part 1)
Performance of MOS transistor 25n120 of asemi in different application scenarios
拿到20K我用了5年,面了所有大厂,这些高频面试问题都帮你们划出来啦
Code farming essential SQL tuning (Part 2)
GO语言-值类型和引用类型
Google Earth engine (GEE) - create a simple panel demo to display the map
Learn how to parse SQL from kernel code
【愚公系列】2022年06月 .NET架构班 079-分布式中间件 ScheduleMaster的集群原理
Connect to the database using GSQL
[0006] title, keyword and page description
MAUI 入门教程系列(1.框架简介)
Thales cloud security report shows that cloud data leakage and complexity are on the rise
零基础自学软件测试,我花7天时间整理了一套学习路线,希望能帮助到大家..
码农必备SQL调优(下)
DB4AI: 数据库驱动AI