Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
sql-set-session-authorization.html64 linesDownload Raw Back to html
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>SET SESSION AUTHORIZATION</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="sql-set-role.html" title="SET ROLE" /><link rel="next" href="sql-set-transaction.html" title="SET TRANSACTION" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">SET SESSION AUTHORIZATION</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-set-role.html" title="SET ROLE">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-set-transaction.html" title="SET TRANSACTION">Next</a></td></tr></table><hr /></div><div class="refentry" id="SQL-SET-SESSION-AUTHORIZATION"><div class="titlepage"></div><a id="id-1.9.3.177.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">SET SESSION AUTHORIZATION</span></h2><p>SET SESSION AUTHORIZATION — set the session user identifier and the current user identifier of the current session</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">3SET [ SESSION | LOCAL ] SESSION AUTHORIZATION <em class="replaceable"><code>user_name</code></em>4SET [ SESSION | LOCAL ] SESSION AUTHORIZATION DEFAULT5RESET SESSION AUTHORIZATION6</pre></div><div class="refsect1" id="id-1.9.3.177.5"><h2>Description</h2><p>7   This command sets the session user identifier and the current user8   identifier of the current SQL session to be <em class="replaceable"><code>user_name</code></em>.  The user name can be9   written as either an identifier or a string literal.  Using this10   command, it is possible, for example, to temporarily become an11   unprivileged user and later switch back to being a superuser.12  </p><p>13   The session user identifier is initially set to be the (possibly14   authenticated) user name provided by the client.  The current user15   identifier is normally equal to the session user identifier, but16   might change temporarily in the context of <code class="literal">SECURITY DEFINER</code>17   functions and similar mechanisms; it can also be changed by18   <a class="link" href="sql-set-role.html" title="SET ROLE"><code class="command">SET ROLE</code></a>.19   The current user identifier is relevant for permission checking.20  </p><p>21   The session user identifier can be changed only if the initial session22   user (the <em class="firstterm">authenticated user</em>) had the23   superuser privilege.  Otherwise, the command is accepted only if it24   specifies the authenticated user name.25  </p><p>26   The <code class="literal">SESSION</code> and <code class="literal">LOCAL</code> modifiers act the same27   as for the regular <a class="link" href="sql-set.html" title="SET"><code class="command">SET</code></a>28   command.29  </p><p>30   The <code class="literal">DEFAULT</code> and <code class="literal">RESET</code> forms reset the session31   and current user identifiers to be the originally authenticated user32   name.  These forms can be executed by any user.33  </p></div><div class="refsect1" id="id-1.9.3.177.6"><h2>Notes</h2><p>34   <code class="command">SET SESSION AUTHORIZATION</code> cannot be used within a35   <code class="literal">SECURITY DEFINER</code> function.36  </p></div><div class="refsect1" id="id-1.9.3.177.7"><h2>Examples</h2><pre class="programlisting">37SELECT SESSION_USER, CURRENT_USER;38 39 session_user | current_user40--------------+--------------41 peter        | peter42 43SET SESSION AUTHORIZATION 'paul';44 45SELECT SESSION_USER, CURRENT_USER;46 47 session_user | current_user48--------------+--------------49 paul         | paul50</pre></div><div class="refsect1" id="id-1.9.3.177.8"><h2>Compatibility</h2><p>51   The SQL standard allows some other expressions to appear in place52   of the literal <em class="replaceable"><code>user_name</code></em>, but these options53   are not important in practice.  <span class="productname">PostgreSQL</span>54   allows identifier syntax (<code class="literal">"<em class="replaceable"><code>username</code></em>"</code>), which SQL55   does not.  SQL does not allow this command during a transaction;56   <span class="productname">PostgreSQL</span> does not make this57   restriction because there is no reason to.58   The <code class="literal">SESSION</code> and <code class="literal">LOCAL</code> modifiers are a59   <span class="productname">PostgreSQL</span> extension, as is the60   <code class="literal">RESET</code> syntax.61  </p><p>62   The privileges necessary to execute this command are left63   implementation-defined by the standard.64  </p></div><div class="refsect1" id="id-1.9.3.177.9"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-set-role.html" title="SET ROLE"><span class="refentrytitle">SET ROLE</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-set-role.html" title="SET ROLE">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-set-transaction.html" title="SET TRANSACTION">Next</a></td></tr><tr><td width="40%" align="left" valign="top">SET ROLE </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> SET TRANSACTION</td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai