Get table primary Key name in PostgreSQL database

Source: Internet
Author: User
Tags postgresql

get table primary key name in PostgreSQL database

First, to obtain the primary key information for the teacher table, as follows:

SelectPg_constraint.conname asPk_name,pg_attribute.attname asColname,pg_type.typname asTypeName fromPg_constraintInner JoinPg_class onPg_constraint.conrelid=pg_class.oidInner JoinPg_attribute onPg_attribute.attrelid=pg_class.oid andPg_attribute.attnum=Pg_constraint.conkey[1]Inner JoinPg_type onPg_type.oid=Pg_attribute.atttypidwherePg_class.relname= 'Teacher'  andPg_constraint.contype='P'

Two:

By graph, the name of the primary KEY constraint is pk_teacher, the primary key field (column) is ID, and the primary key field is the type: UUID.

--Song Xingju was published on July 30, 2015 in Jinan middle di zhi industry.

Get table primary Key name in PostgreSQL database

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.