Psql Some of the operation commands to learn

Source: Internet
Author: User
Tags function definition psql

D:\Program files\postgresql\9.3\scripts
This is the default buffer position of the psql;
Psql's command: D:\Program files\postgresql\9.3\scripts\runpsql.bat
--
Query buffer
\e [file] [line] Edit query buffer (or file) using external editor
\EF [FUNCNAME [line]] Edit function definition using external editor
\p Display the contents of the query buffer
\ r Reset (clear) the query buffer
The \w file writes the contents of the query buffer to the file

Input/Output
\copy ... Execute SQL COPY to send the data stream to the client host
\echo [string] writes a string to standard output
\i files to execute commands from a file
\ir FILE is similar to \i, but relative to the location of the current script
\o [file] writes all query results to a file or | pipeline
\qecho [string] writes a string to the query output stream (reference \o)
--
The default of these related files is put into this; \postgresql\9.3\scripts
---
\CD is the one that can switch this directory.
======================================================================================
----------------------------------------------------
Commands are divided into,
In general:
\watch [SEC]: Execute a statement query first, then \watch 2 execution, identify every 2s to execute the query again;
\h Name: \h Select will list the usage instructions for the Select
\q: Exit Psql
License Terms for \copyright PostgreSQL
\g Execute Query: SELECT * FROM mytable \g QQQ Place Query results in file or pipeline
or yes;: SELECT * FROM MyTable; The QQQ function is the same as last
-----------------------------------------------------------
Buffer:
\e uses an external editor to query; The command opens an external editor, such as Notepad, which allows you to enter a command that executes the command when it is closed;
\EF editing functions
\p Viewing buffer contents
\ r Reset Buffer
\w writes the contents of the query buffer to the file: \w filename File exists runplsql.bat location by default
----------------------------------------------------------------
Input and output:
\copy ... If it is remote, execute SQL COPY and send the data stream to the client host
\echo [string] writes a string to standard output
\i files execute command files from a file the default location is also ... \postgresql\9.3\scripts
\o [file] writes all query results to the file or | Pipeline this is the operation of the file, the file query results into the file, and the preceding \g or semicolon; These are followed by a command that places the query results in a file;
\qecho [string] writes a string to the query output stream (reference \o)
--
------------------------------------------------------------
command of informational information
(option: S = Display System object, + = rest details)
\d[s+] Lists tables, views, and sequences
\d[s+] Name Description table, view, sequence, or index
\da[s] [mode] lists aggregate functions
\db[+] [mode] List table space
\dc[s+] [PATTERN] list conversion
\dc[+] [PATTERN] lists type casts
\dd[s] [PATTERN] shows an object description that is not displayed elsewhere
\DDP [mode] List default permissions
\dd[s+] [PATTERN] lists common domains
\det[+] [PATTERN] Lists reference tables
\des[+] [mode] lists external servers
\deu[+] [mode] list user mappings
\dew[+] [mode] lists external data wrappers
\df[antw][s+] [mode] list [include aggregate/general/trigger/window] function
\df[+] [mode] List text search configuration
\dfd[+] [mode] Lists text search dictionaries
\dfp[+] [mode] List text Search parser
\dft[+] [mode] List text Search template
\dg[+] [PATTERN] Lists roles
\di[s+] [mode] List index
\DL lists large objects with the same functionality as \lo_list
\dl[s+] [PATTERN] Lists all process languages
\dm[s+] [PATTERN] Lists all materialized views
\dn[s+] [pattern] Lists all modes
\do[s] [schema] list operators
\do[s+] [PATTERN] Lists all proofing rules
\DP [mode] lists access permissions for tables, views, and sequences
\drds [Mode 1 [Mode 2]] lists the role settings for each database
\ds[s+] [mode] list sequence
\dt[s+] [mode] List table
\dt[s+] [mode] list data types
\du[+] [PATTERN] Lists roles
\dv[s+] [mode] List view
\de[s+] [PATTERN] Lists reference tables
\dx[+] [PATTERN] lists extensions
\dy [PATTERN] Lists all event triggers
\l[+] [PATTERN] Lists all databases
\sf[+] FUNCNAME display function definition
\z [mode] and \DP function the same
---------------------------
Display formatting:
\a Toggle between alignment and non-aligned modes
\h switch to HTML output mode. Default off
\pset NAME [VALUE] setting table Output Options
(NAME: = {format|border|expanded|fieldsep|fieldsep_zero|footer|null|numericlocale|recordsep|recordsep_zero| Tuples_only|title|tableattr|pager})
\ t switch to show record without caption, and display record and title

  \ t [string]         Set HTML < table > tag properties, or if not, cancel settings
  \x [ on|off|auto]       Toggle Extended Output mode (currently off)
--------------------------
Connection Operation
\c[ Onnect] [Database name |-User name |-Host |-Port |]
                  Connect to a new database (currently "Postgres")
  \encoding [encode name] Display or set client encoding
  \password [USERNAME ]  securely change passwords for users
  \conninfo               Display information about the current connection
 ------------------------------
Commands related to the operating system:
  \CD [directory]      Change the current working directory
  \SETENV NAME [value]   set or empty environment variables
 \timing [on | off]        Toggle Command Timing switch (currently off)
  \! [Command]      execute commands in the shell or start an interactive shell

]

-----------------------------------------------
Variable
\prompt [text] name prompts the user to set internal variables
\set [name [value]] SET internal variable, if no argument lists all variables
\unset name Empty (delete) internal variable

-----------------------------

Large Object
\lo_export loboid File
\lo_import file [Note]
\lo_list
\lo_unlink loboid Large Object operation

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.