2.3 PostgreSQL Creating a new table

Source: Internet
Author: User
Tags postgresql psql

You can create a table by declaring the name of the table and the names of all the fields and their types:

CREATE TABLE Weather (    City            varchar),    temp_lo         int,           --Lowest temperature    temp_hi         int,--           maximum temperature    PRCP            Real,          --precipitation    date            date);

You can type these things in psql with a newline character. Psql can recognize the command until the semicolon ends.

You can freely use whitespace (spaces/tab/line breaks) in SQL commands. This means that you can type commands with different alignments (even on the same line) as above. A double dash ("--") introduces a comment, and anything that follows it is ignored until the end of the line. SQL is a language that is insensitive to keywords and identifiers, and only retains their casing properties if the identifiers are surrounded by double quotation marks (which is not the case).

varchar declares a data type that can store any string up to 80 characters long. int is an ordinary integer type. Real is a type for storing single-precision floating-point numbers. The date type should be self-explanatory. Yes, the field name of type date is also date . This may be convenient or confusing, and you can see for yourself.

Postgres SQL supports standard SQL types:int, smallint, real, double precision, char (N ), varchar (N), date, time, timestamp, interval , other common types and rich geometry types are also supported. PostgreSQL allows you to customize any number of data types. Thus the type name is not a syntax keyword, except for the special exceptions that SQL standard requires.

The second example will save the city and their associated geographic location:

CREATE TABLE Cities (    name            varchar, location point        );

The point type is an example of a PostgreSQL-specific data type.

Finally, we also mention that if you no longer need a table, or if you want to create a different table, you can delete it with the following command:

TableName;

For more information, please refer to Http://www.infocool.net

2.3 PostgreSQL Creating a new table

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.