PostgreSQL Logical Structure-view (v)

Source: Internet
Author: User
Tags postgresql

Defined

First, create a view

1. Syntax create [or replace] [temp |  Temporary] View name [(column_name [,...])] As query

2. Example: Create a view that can hide password:

postgres=# CREATE table users (ID int,user_name varchar (+), password varchar (n), user_email text,user_mark text); postgres=# CREATE View vw_users as select Id,user_name,user_email,user_mark from users; CREATE VIEW

  

3, you can also use the temp or temporary keyword to create a view, when the session ends, the view disappears:

postgres=# Create temp View vw_users as select Id,user_name,user_email,user_mark from users; CREATE viewpostgres=# INSERT INTO  users values (1, ' A ', ' 123455 ', ' [email protected] '); Insert 0 1

\q exits and disappears after landing.

4. The view can also define another name for each column of the query. column names, such as the ID, user_name, user_email, User_mark, etc. in the original table, are redefined as no, name, email, Mark,

postgres=# CREATE View Vm_users (No,name,email,mark) as select id,user_name,postgres-# User_email,user_mark from users; CREATE viewpostgres=# SELECT * from Vm_users; No | name |    Email     | Mark----+------+--------------+------  1 | a    | [Email protected] | (1 row) postgres=#

  

Second, can update the view

PostgreSQL Logical Structure-view (v)

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.