PostgreSQL (i) tutorial-----SQL language

Source: Internet
Author: User
Tags psql

First, the concept

PostgreSQL is a relational database management system (RDBMS). This means that it is a system for managing the data stored in the relationship . A relationship is actually a mathematical term for a table . Today, the concept of storing data in the table is fast becoming an inherent common sense, but there are other ways to organize the database. Files and directories on Unix-like operating systems form an example of a hierarchical database. The more modern development is the object-oriented database.

Each table is a named collection of rows . Each row of a given table consists of named columns of the same group, and each column has a specific data type. Although the order of the columns in each row is fixed, it is important to remember that SQL does not guarantee the order of the rows in the table (but you can sort them explicitly for display purposes).

Tables are composed of databases, a collection of databases that are managed by a single PostgreSQL server instance .

Second, create a new table

You can create a table by specifying the name of the table and the names of all the columns and their types:

CREATE TABLE weather (city varchar), Temp_lo int,--Lowest temperature Temp_hi int, --Maximum temperature PRCP real,--humidity date date);

You can be inPsqlEnter these commands as well as line breaks.PsqlThe command can be recognized until the semicolon ends.
You can freely use whitespace (that is, spaces, tabs, and line breaks) in SQL commands. This means you can type the command with the different alignment above, or put the command all in one line. Two dashes ("--") to introduce comments.
Anything that goes behind it until the end of the line is ignored. SQL is a language that is insensitive to keywords and identifiers, and is only preserved when identifiers are surrounded by double quotation marks (not in the previous example).
varchar (+)Specifies a data type that can store any string up to 80 characters long.intis an ordinary integer type.Realis a type used to store single-precision floating-point numbers.DateThe type should be self-explanatory (yes, the type isDateThe column name is alsoDate。 This may be convenient or confusing-you choose to do so.
PostgreSQL supports the standard SQL type int,smallint,real,double precision,char (N ),varchar (N),date,time,timestamp , and Intervalalso supports other types of common functionality and rich geometry types. any number of user-defined data types can be customized in PostgreSQL. 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        );
Type point 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 rebuild it in a different form, you can delete it with the following command:
TableName;

PostgreSQL (i) tutorial-----SQL language

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.