How to Learn PostgreSQL SQL syntax

Source: Internet
Author: User
Tags psql

How to Learn PostgreSQL SQL syntax

We can use the psql command to query the SQL syntax. Switch to the PostgreSQL user,

[Doctor @ localhost ~] $ Su-postgres
Password:
Su: Fault Identification
[Doctor @ localhost ~] $ Su-postgres
Password:
-Bash-4.3 $ bash
Bash-4.3 $ psql
Psql (9.4.2)
Enter "help" to obtain help information.

Postgres = #

Postgres = # help
You are using psql. This is a command line interface for accessing PostgreSQL.
Type \ copyright to display the release terms
\ H display description of SQL commands
\? Instructions on displaying pgsql commands
\ G or end with a semicolon (;) to execute the query
\ Q exit
Postgres = #

The \ h command is used to learn SQL syntax.

Postgres = # \ h
Available description:
ABORT DEALLOCATE
ALTER AGGREGATE DECLARE
ALTER COLLATION DELETE
ALTER CONVERSION DISCARD
ALTER DATABASE DO
ALTER DEFAULT PRIVILEGES DROP AGGREGATE
ALTER DOMAIN DROP CAST
ALTER EVENT TRIGGER DROP COLLATION
ALTER EXTENSION DROP CONVERSION
ALTER FOREIGN DATA WRAPPER DROP DATABASE
ALTER FOREIGN TABLE DROP DOMAIN
ALTER FUNCTION DROP EVENT TRIGGER
ALTER GROUP DROP EXTENSION
ALTER INDEX DROP FOREIGN DATA WRAPPER
ALTER LANGUAGE DROP FOREIGN TABLE
ALTER LARGE OBJECT DROP FUNCTION
ALTER MATERIALIZED VIEW DROP GROUP
ALTER OPERATOR DROP INDEX
ALTER OPERATOR CLASS DROP LANGUAGE
ALTER OPERATOR FAMILY DROP MATERIALIZED VIEW
ALTER ROLE DROP OPERATOR
ALTER RULE DROP OPERATOR CLASS

Postgres = # \ h select
Command: SELECT
Description: reads data from a data table or view table.
Syntax:
[WITH [RECURSIVE] with query statement (with_query) [,...]
SELECT [ALL | DISTINCT [ON (expression [,...])]
[* | Expression [[AS] Output name] [,...]
[FROM from list item [,...]
[WHERE condition]
[Group by expression [,...]
[HAVING condition [,...]
[WINDOW name AS (WINDOW definition) [,...]
[{UNION | INTERSECT | EXCEPT t} [ALL | DISTINCT] query]
[Order by expression [ASC | DESC | USING operator] [NULLS {FIRST | LAST}] [
,...]
[LIMIT {maximum number of returned records used for query | ALL}]
[OFFSET start value [ROW | ROWS]
[FETCH {FIRST | NEXT} [maximum number of returned records used for query] {ROW | ROWS} ONLY
]
[FOR {UPDATE | no key update | SHARE | key share} [OF table name [,...] [N
OWAIT] [...]

The items in the from list can be one of the following

[ONLY] Table name [*] [[AS] alias [(column alias [,...])]
[LATERAL] (query) [AS] alias [(column alias [,...])]
WITH query statement name (with_query_name) [[AS] alias [(column alias [,...])]
[LATERAL] function name ([parameter [,...])
[With ordinality] [[AS] alias [(column alias [,...])]
[LATERAL] function name ([parameter [,...]) [AS] alias (column Definition [,...])
[LATERAL] function name ([parameter [,...]) AS (column Definition [,...])
[LATERAL] rows from (function name ([parameter [,...]) [AS (column Definition [,...])
] [,...])
[With ordinality] [[AS] alias [(column alias [,...])]
From list item [NATURAL] connection operation type from list item [ON connection operation condition |
USING (Column Used for connection operation [,...])]

The with query statement is:

WITH query statement name (with_query_name) [(column name [,...])] AS (query | value | in
Sert | update | delete)

TABLE [ONLY] TABLE name [*]

Postgres = #

This command is useful for learning SQL syntax.

------------------------------------ Lili split line ------------------------------------

Install PostgreSQL 6.3 on yum in CentOS 9.3

PostgreSQL cache details

Compiling PostgreSQL on Windows

Configuration and installation of LAPP (Linux + Apache + PostgreSQL + PHP) Environment in Ubuntu

Install and configure phppgAdmin on Ubuntu

Install PostgreSQL9.3 on CentOS

Configure a Streaming Replication cluster in PostgreSQL

How to install PostgreSQL 7/6 and phpPgAdmin in CentOS 5/6. 4

------------------------------------ Lili split line ------------------------------------

PostgreSQL details: click here
PostgreSQL: click here

This article permanently updates the link address:

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.