PostgreSQL row to column, stitching string

Source: Internet
Author: User
Tags postgresql

Create TableK_user (op_idVARCHAR( $) not NULL, Op_nameVARCHAR( -) not NULL, PasswordVARCHAR( -) not NULL, Real_nameVARCHAR( -) not NULL, Lock_markVARCHAR( -) not NULL, Dept_noTEXT                 NULL, post_idTEXT                 NULL, TelVARCHAR( -)NULL, MailVARCHAR( -)NULL, create_idVARCHAR( $) not NULL, Create_nameVARCHAR( -) not NULL, Create_timeVARCHAR( -) not NULL, modify_idVARCHAR( $)NULL, Modify_nameVARCHAR( -)NULL, Modify_timeVARCHAR( -)NULL, RemarkVARCHAR(1024x768)NULL,   constraintPk_k_userPrimary Key(op_id));
 create  table   K_user_role ( user_id  varchar  (not
     null   varchar  (not
       null  ,  constraint  Pk_k_user_role primary  key  (user_id   
Create TableK_role (op_idVARCHAR( $) not NULL, Op_nameVARCHAR( -) not NULL, create_idVARCHAR( $) not NULL, Create_nameVARCHAR( -) not NULL, Create_timeVARCHAR( -) not NULL, modify_idVARCHAR( $)NULL, Modify_nameVARCHAR( -)NULL, Modify_timeVARCHAR( -)NULL, RemarkVARCHAR(1024x768)NULL,   constraintPk_k_rolePrimary Key(op_id));

SELECT * FROM (select u.*, array_to_string (Array (select role_id from k_user_role ur WHERE ur.user_id = u.op_id), ', ') as User_role, array_to_string (Array (SELECT op_name from K_user_role ur,k_role R WHERE ur.role_id=r.op_id an D ur.user_id = u.op_id), ', ') as role_name from K_user u) k_user limit offset 0

PostgreSQL row to column, stitching string

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.