How to search a user in the table "cwd_user" by a "userkey"?
Asked by Sascha Ziemann:

When someone uses the @ to insert a user into a Confluence page, the following string gets inserted into the "body" column of the "bodycontent" table of the Confluence database:

```
<div class="content-wrapper"><p><ac:link><ri:user ri:userkey="bee05cc37052f5240170e2d6d26b000c" /></ac:link></p></div>
```

Instead of the username a "userkey" is in the document.

How to search a user in the table "cwd_user" by a "userkey"?

I can not find any "userkey" in the table "cwd_user":

```
confluencedb=# \d cwd_user
Tabelle ?public.cwd_user?
Spalte | Typ | Attribute 
---------------------+-----------------------------+-----------
id | bigint | not null
user_name | character varying(255) | not null
lower_user_name | character varying(255) | not null
active | character(1) | not null
created_date | timestamp without time zone | not null
updated_date | timestamp without time zone | not null
first_name | character varying(255) | 
lower_first_name | character varying(255) | 
last_name | character varying(255) | 
lower_last_name | character varying(255) | 
display_name | character varying(255) | 
lower_display_name | character varying(255) | 
email_address | character varying(255) | 
lower_email_address | character varying(255) | 
external_id | character varying(255) | 
directory_id | bigint | not null
credential | character varying(255) | 
Indexe:
"cwd_user_pkey" PRIMARY KEY, btree (id)
"cwd_user_name_dir_id" UNIQUE CONSTRAINT, btree (lower_user_name, directory_id)
"idx_user_active" btree (active, directory_id)
"idx_user_external_id" btree (external_id)
"idx_user_lower_display_name" btree (lower_display_name, directory_id)
"idx_user_lower_email_address" btree (lower_email_address, directory_id)
"idx_user_lower_first_name" btree (lower_first_name, directory_id)
"idx_user_lower_last_name" btree (lower_last_name, directory_id)
"idx_user_lower_user_name" btree (lower_user_name)
"idx_user_name_dir_id" btree (directory_id)
Fremdschl?ssel-Constraints:
"fk_user_dir_id" FOREIGN KEY (directory_id) REFERENCES cwd_directory(id)
Fremdschl?sselverweise von:
TABLE "cwd_user_credential_record" CONSTRAINT "fk2rfdh2ap00b8mholdsy1b785b" FOREIGN KEY (user_id) REFERENCES cwd_user(id)
TABLE "cwd_membership" CONSTRAINT "fk_child_user" FOREIGN KEY (child_user_id) REFERENCES cwd_user(id)
TABLE "cwd_user_attribute" CONSTRAINT "fk_user_attribute_id_user_id" FOREIGN KEY (user_id) REFERENCES cwd_user(id)
```

BTW: Why gets the source code format destroyed by the forum?


Answers:
author: Ivan Lima
body: Hi [@Sascha Ziemann](/t5/user/viewprofilepage/user-id/2450983), you will find this reference, as well as other references of Confluence tables at [Confluence Data Model](https://confluence.atlassian.com/doc/confluence-data-model-127369837.html). In the section **Database tables and references,** expand the list of tables, and you will find USER_KEY at the USER_MAPPING table.

Therefore, you'll find the user key from users:

```
SELECT user_key FROM user_mapping WHERE lower_username = '<username>';
```

The string you mentioned is the resource identifier of the user, in this case, the user key. It is useful, for example, when you work with [Confluence Storage Format](https://confluence.atlassian.com/doc/confluence-storage-format-790796544.html) to dynamically create Confluence resources such as mentions, macros, etc.

I hope it helps.  
IL.


Tags: confluence-server

server