~ubuntu-branches/ubuntu/trusty/postgresql-9.3/trusty-updates

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>GRANT</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 9.3.13 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="SQL Commands"
HREF="sql-commands.html"><LINK
REL="PREVIOUS"
TITLE="FETCH"
HREF="sql-fetch.html"><LINK
REL="NEXT"
TITLE="INSERT"
HREF="sql-insert.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2016-05-09T21:13:26"></HEAD
><BODY
CLASS="REFENTRY"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.3.13 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="FETCH"
HREF="sql-fetch.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="sql-commands.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="INSERT"
HREF="sql-insert.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="SQL-GRANT"
></A
>GRANT</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN78315"
></A
><H2
>Name</H2
>GRANT&nbsp;--&nbsp;define access privileges</DIV
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN78320"
></A
><H2
>Synopsis</H2
><PRE
CLASS="SYNOPSIS"
>GRANT { { SELECT | INSERT | UPDATE | DELETE | TRUNCATE | REFERENCES | TRIGGER }
    [, ...] | ALL [ PRIVILEGES ] }
    ON { [ TABLE ] <TT
CLASS="REPLACEABLE"
><I
>table_name</I
></TT
> [, ...]
         | ALL TABLES IN SCHEMA <TT
CLASS="REPLACEABLE"
><I
>schema_name</I
></TT
> [, ...] }
    TO { [ GROUP ] <TT
CLASS="REPLACEABLE"
><I
>role_name</I
></TT
> | PUBLIC } [, ...] [ WITH GRANT OPTION ]

GRANT { { SELECT | INSERT | UPDATE | REFERENCES } ( <TT
CLASS="REPLACEABLE"
><I
>column_name</I
></TT
> [, ...] )
    [, ...] | ALL [ PRIVILEGES ] ( <TT
CLASS="REPLACEABLE"
><I
>column_name</I
></TT
> [, ...] ) }
    ON [ TABLE ] <TT
CLASS="REPLACEABLE"
><I
>table_name</I
></TT
> [, ...]
    TO { [ GROUP ] <TT
CLASS="REPLACEABLE"
><I
>role_name</I
></TT
> | PUBLIC } [, ...] [ WITH GRANT OPTION ]

GRANT { { USAGE | SELECT | UPDATE }
    [, ...] | ALL [ PRIVILEGES ] }
    ON { SEQUENCE <TT
CLASS="REPLACEABLE"
><I
>sequence_name</I
></TT
> [, ...]
         | ALL SEQUENCES IN SCHEMA <TT
CLASS="REPLACEABLE"
><I
>schema_name</I
></TT
> [, ...] }
    TO { [ GROUP ] <TT
CLASS="REPLACEABLE"
><I
>role_name</I
></TT
> | PUBLIC } [, ...] [ WITH GRANT OPTION ]

GRANT { { CREATE | CONNECT | TEMPORARY | TEMP } [, ...] | ALL [ PRIVILEGES ] }
    ON DATABASE <TT
CLASS="REPLACEABLE"
><I
>database_name</I
></TT
> [, ...]
    TO { [ GROUP ] <TT
CLASS="REPLACEABLE"
><I
>role_name</I
></TT
> | PUBLIC } [, ...] [ WITH GRANT OPTION ]

GRANT { USAGE | ALL [ PRIVILEGES ] }
    ON DOMAIN <TT
CLASS="REPLACEABLE"
><I
>domain_name</I
></TT
> [, ...]
    TO { [ GROUP ] <TT
CLASS="REPLACEABLE"
><I
>role_name</I
></TT
> | PUBLIC } [, ...] [ WITH GRANT OPTION ]

GRANT { USAGE | ALL [ PRIVILEGES ] }
    ON FOREIGN DATA WRAPPER <TT
CLASS="REPLACEABLE"
><I
>fdw_name</I
></TT
> [, ...]
    TO { [ GROUP ] <TT
CLASS="REPLACEABLE"
><I
>role_name</I
></TT
> | PUBLIC } [, ...] [ WITH GRANT OPTION ]

GRANT { USAGE | ALL [ PRIVILEGES ] }
    ON FOREIGN SERVER <TT
CLASS="REPLACEABLE"
><I
>server_name</I
></TT
> [, ...]
    TO { [ GROUP ] <TT
CLASS="REPLACEABLE"
><I
>role_name</I
></TT
> | PUBLIC } [, ...] [ WITH GRANT OPTION ]

GRANT { EXECUTE | ALL [ PRIVILEGES ] }
    ON { FUNCTION <TT
CLASS="REPLACEABLE"
><I
>function_name</I
></TT
> ( [ [ <TT
CLASS="REPLACEABLE"
><I
>argmode</I
></TT
> ] [ <TT
CLASS="REPLACEABLE"
><I
>arg_name</I
></TT
> ] <TT
CLASS="REPLACEABLE"
><I
>arg_type</I
></TT
> [, ...] ] ) [, ...]
         | ALL FUNCTIONS IN SCHEMA <TT
CLASS="REPLACEABLE"
><I
>schema_name</I
></TT
> [, ...] }
    TO { [ GROUP ] <TT
CLASS="REPLACEABLE"
><I
>role_name</I
></TT
> | PUBLIC } [, ...] [ WITH GRANT OPTION ]

GRANT { USAGE | ALL [ PRIVILEGES ] }
    ON LANGUAGE <TT
CLASS="REPLACEABLE"
><I
>lang_name</I
></TT
> [, ...]
    TO { [ GROUP ] <TT
CLASS="REPLACEABLE"
><I
>role_name</I
></TT
> | PUBLIC } [, ...] [ WITH GRANT OPTION ]

GRANT { { SELECT | UPDATE } [, ...] | ALL [ PRIVILEGES ] }
    ON LARGE OBJECT <TT
CLASS="REPLACEABLE"
><I
>loid</I
></TT
> [, ...]
    TO { [ GROUP ] <TT
CLASS="REPLACEABLE"
><I
>role_name</I
></TT
> | PUBLIC } [, ...] [ WITH GRANT OPTION ]

GRANT { { CREATE | USAGE } [, ...] | ALL [ PRIVILEGES ] }
    ON SCHEMA <TT
CLASS="REPLACEABLE"
><I
>schema_name</I
></TT
> [, ...]
    TO { [ GROUP ] <TT
CLASS="REPLACEABLE"
><I
>role_name</I
></TT
> | PUBLIC } [, ...] [ WITH GRANT OPTION ]

GRANT { CREATE | ALL [ PRIVILEGES ] }
    ON TABLESPACE <TT
CLASS="REPLACEABLE"
><I
>tablespace_name</I
></TT
> [, ...]
    TO { [ GROUP ] <TT
CLASS="REPLACEABLE"
><I
>role_name</I
></TT
> | PUBLIC } [, ...] [ WITH GRANT OPTION ]

GRANT { USAGE | ALL [ PRIVILEGES ] }
    ON TYPE <TT
CLASS="REPLACEABLE"
><I
>type_name</I
></TT
> [, ...]
    TO { [ GROUP ] <TT
CLASS="REPLACEABLE"
><I
>role_name</I
></TT
> | PUBLIC } [, ...] [ WITH GRANT OPTION ]

GRANT <TT
CLASS="REPLACEABLE"
><I
>role_name</I
></TT
> [, ...] TO <TT
CLASS="REPLACEABLE"
><I
>role_name</I
></TT
> [, ...] [ WITH ADMIN OPTION ]</PRE
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="SQL-GRANT-DESCRIPTION"
></A
><H2
>Description</H2
><P
>   The <TT
CLASS="COMMAND"
>GRANT</TT
> command has two basic variants: one
   that grants privileges on a database object (table, column, view, foreign
   table, sequence, database, foreign-data wrapper, foreign server, function,
   procedural language, schema, or tablespace), and one that grants
   membership in a role.  These variants are similar in many ways, but
   they are different enough to be described separately.
  </P
><DIV
CLASS="REFSECT2"
><A
NAME="SQL-GRANT-DESCRIPTION-OBJECTS"
></A
><H3
>GRANT on Database Objects</H3
><P
>   This variant of the <TT
CLASS="COMMAND"
>GRANT</TT
> command gives specific
   privileges on a database object to
   one or more roles.  These privileges are added
   to those already granted, if any.
  </P
><P
>   There is also an option to grant privileges on all objects of the same
   type within one or more schemas.  This functionality is currently supported
   only for tables, sequences, and functions (but note that <TT
CLASS="LITERAL"
>ALL
   TABLES</TT
> is considered to include views and foreign tables).
  </P
><P
>   The key word <TT
CLASS="LITERAL"
>PUBLIC</TT
> indicates that the
   privileges are to be granted to all roles, including those that might
   be created later.  <TT
CLASS="LITERAL"
>PUBLIC</TT
> can be thought of as an
   implicitly defined group that always includes all roles.
   Any particular role will have the sum
   of privileges granted directly to it, privileges granted to any role it
   is presently a member of, and privileges granted to
   <TT
CLASS="LITERAL"
>PUBLIC</TT
>.
  </P
><P
>   If <TT
CLASS="LITERAL"
>WITH GRANT OPTION</TT
> is specified, the recipient
   of the privilege can in turn grant it to others.  Without a grant
   option, the recipient cannot do that.  Grant options cannot be granted
   to <TT
CLASS="LITERAL"
>PUBLIC</TT
>.
  </P
><P
>   There is no need to grant privileges to the owner of an object
   (usually the user that created it),
   as the owner has all privileges by default.  (The owner could,
   however, choose to revoke some of his own privileges for safety.)
  </P
><P
>   The right to drop an object, or to alter its definition in any way, is
   not treated as a grantable privilege; it is inherent in the owner,
   and cannot be granted or revoked.  (However, a similar effect can be
   obtained by granting or revoking membership in the role that owns
   the object; see below.)  The owner implicitly has all grant
   options for the object, too.
  </P
><P
>   PostgreSQL grants default privileges on some types of objects to
   <TT
CLASS="LITERAL"
>PUBLIC</TT
>.  No privileges are granted to
   <TT
CLASS="LITERAL"
>PUBLIC</TT
> by default on tables,
   columns, schemas or tablespaces. For other types, the default privileges
   granted to <TT
CLASS="LITERAL"
>PUBLIC</TT
> are as follows:
   <TT
CLASS="LITERAL"
>CONNECT</TT
> and <TT
CLASS="LITERAL"
>CREATE TEMP TABLE</TT
> for
   databases; <TT
CLASS="LITERAL"
>EXECUTE</TT
> privilege for functions; and
   <TT
CLASS="LITERAL"
>USAGE</TT
> privilege for languages.
   The object owner can, of course, <TT
CLASS="COMMAND"
>REVOKE</TT
>
   both default and  expressly granted privileges. (For maximum
   security, issue the <TT
CLASS="COMMAND"
>REVOKE</TT
> in the same transaction that
   creates the object; then there is no window in which another user
   can use the object.)
   Also, these initial default privilege settings can be changed using the
   <A
HREF="sql-alterdefaultprivileges.html"
>ALTER DEFAULT PRIVILEGES</A
>
   command.
  </P
><P
>   The possible privileges are:

   <P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
>SELECT</DT
><DD
><P
>       Allows <A
HREF="sql-select.html"
>SELECT</A
> from
       any column, or the specific columns listed, of the specified table,
       view, or sequence.
       Also allows the use of
       <A
HREF="sql-copy.html"
>COPY</A
> TO.
       This privilege is also needed to reference existing column values in
       <A
HREF="sql-update.html"
>UPDATE</A
> or
       <A
HREF="sql-delete.html"
>DELETE</A
>.
       For sequences, this privilege also allows the use of the
       <CODE
CLASS="FUNCTION"
>currval</CODE
> function.
       For large objects, this privilege allows the object to be read.
      </P
></DD
><DT
>INSERT</DT
><DD
><P
>       Allows <A
HREF="sql-insert.html"
>INSERT</A
> of a new
       row into the specified table.  If specific columns are listed,
       only those columns may be assigned to in the <TT
CLASS="COMMAND"
>INSERT</TT
>
       command (other columns will therefore receive default values).
       Also allows <A
HREF="sql-copy.html"
>COPY</A
> FROM.
      </P
></DD
><DT
>UPDATE</DT
><DD
><P
>       Allows <A
HREF="sql-update.html"
>UPDATE</A
> of any
       column, or the specific columns listed, of the specified table.
       (In practice, any nontrivial <TT
CLASS="COMMAND"
>UPDATE</TT
> command will require
       <TT
CLASS="LITERAL"
>SELECT</TT
> privilege as well, since it must reference table
       columns to determine which rows to update, and/or to compute new
       values for columns.)
       <TT
CLASS="LITERAL"
>SELECT ... FOR UPDATE</TT
>
       and <TT
CLASS="LITERAL"
>SELECT ... FOR SHARE</TT
>
       also require this privilege on at least one column, in addition to the
       <TT
CLASS="LITERAL"
>SELECT</TT
> privilege.  For sequences, this
       privilege allows the use of the <CODE
CLASS="FUNCTION"
>nextval</CODE
> and
       <CODE
CLASS="FUNCTION"
>setval</CODE
> functions.
       For large objects, this privilege allows writing or truncating the
       object.
      </P
></DD
><DT
>DELETE</DT
><DD
><P
>       Allows <A
HREF="sql-delete.html"
>DELETE</A
> of a row
       from the specified table.
       (In practice, any nontrivial <TT
CLASS="COMMAND"
>DELETE</TT
> command will require
       <TT
CLASS="LITERAL"
>SELECT</TT
> privilege as well, since it must reference table
       columns to determine which rows to delete.)
      </P
></DD
><DT
>TRUNCATE</DT
><DD
><P
>       Allows <A
HREF="sql-truncate.html"
>TRUNCATE</A
> on
       the specified table.
      </P
></DD
><DT
>REFERENCES</DT
><DD
><P
>       To create a foreign key constraint, it is
       necessary to have this privilege on both the referencing and
       referenced columns.  The privilege may be granted for all columns
       of a table, or just specific columns.
      </P
></DD
><DT
>TRIGGER</DT
><DD
><P
>       Allows the creation of a trigger on the specified table.  (See the
       <A
HREF="sql-createtrigger.html"
>CREATE TRIGGER</A
> statement.)
      </P
></DD
><DT
>CREATE</DT
><DD
><P
>       For databases, allows new schemas to be created within the database.
      </P
><P
>       For schemas, allows new objects to be created within the schema.
       To rename an existing object, you must own the object <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>and</I
></SPAN
>
       have this privilege for the containing schema.
      </P
><P
>       For tablespaces, allows tables, indexes, and temporary files to be
       created within the tablespace, and allows databases to be created that
       have the tablespace as their default tablespace.  (Note that revoking
       this privilege will not alter the placement of existing objects.)
      </P
></DD
><DT
>CONNECT</DT
><DD
><P
>       Allows the user to connect to the specified database.  This
       privilege is checked at connection startup (in addition to checking
       any restrictions imposed by <TT
CLASS="FILENAME"
>pg_hba.conf</TT
>).
      </P
></DD
><DT
>TEMPORARY<BR>TEMP</DT
><DD
><P
>       Allows temporary tables to be created while using the specified database.
      </P
></DD
><DT
>EXECUTE</DT
><DD
><P
>       Allows the use of the specified function and the use of any
       operators that are implemented on top of the function.  This is
       the only type of privilege that is applicable to functions.
       (This syntax works for aggregate functions, as well.)
      </P
></DD
><DT
>USAGE</DT
><DD
><P
>       For procedural languages, allows the use of the specified language for
       the creation of functions in that language.  This is the only type
       of privilege that is applicable to procedural languages.
      </P
><P
>       For schemas, allows access to objects contained in the specified
       schema (assuming that the objects' own privilege requirements are
       also met).  Essentially this allows the grantee to <SPAN
CLASS="QUOTE"
>"look up"</SPAN
>
       objects within the schema.  Without this permission, it is still
       possible to see the object names, e.g. by querying the system tables.
       Also, after revoking this permission, existing backends might have
       statements that have previously performed this lookup, so this is not
       a completely secure way to prevent object access.
      </P
><P
>       For sequences, this privilege allows the use of the
       <CODE
CLASS="FUNCTION"
>currval</CODE
> and <CODE
CLASS="FUNCTION"
>nextval</CODE
> functions.
      </P
><P
>       For types and domains, this privilege allow the use of the type or
       domain in the creation of tables, functions, and other schema objects.
       (Note that it does not control general <SPAN
CLASS="QUOTE"
>"usage"</SPAN
> of the type,
       such as values of the type appearing in queries.  It only prevents
       objects from being created that depend on the type.  The main purpose of
       the privilege is controlling which users create dependencies on a type,
       which could prevent the owner from changing the type later.)
      </P
><P
>       For foreign-data wrappers, this privilege enables the grantee
       to create new servers using that foreign-data wrapper.
      </P
><P
>       For servers, this privilege enables the grantee to create foreign
       tables using the server, and also to create, alter, or drop his own
       user's user mappings associated with that server.
      </P
></DD
><DT
>ALL PRIVILEGES</DT
><DD
><P
>       Grant all of the available privileges at once.
       The <TT
CLASS="LITERAL"
>PRIVILEGES</TT
> key word is optional in
       <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>, though it is required by
       strict SQL.
      </P
></DD
></DL
></DIV
><P>

   The privileges required by other commands are listed on the
   reference page of the respective command.
  </P
></DIV
><DIV
CLASS="REFSECT2"
><A
NAME="SQL-GRANT-DESCRIPTION-ROLES"
></A
><H3
>GRANT on Roles</H3
><P
>   This variant of the <TT
CLASS="COMMAND"
>GRANT</TT
> command grants membership
   in a role to one or more other roles.  Membership in a role is significant
   because it conveys the privileges granted to a role to each of its
   members.
  </P
><P
>   If <TT
CLASS="LITERAL"
>WITH ADMIN OPTION</TT
> is specified, the member can
   in turn grant membership in the role to others, and revoke membership
   in the role as well.  Without the admin option, ordinary users cannot
   do that.  A role is not considered to hold <TT
CLASS="LITERAL"
>WITH ADMIN
   OPTION</TT
> on itself, but it may grant or revoke membership in
   itself from a database session where the session user matches the
   role.  Database superusers can grant or revoke membership in any role
   to anyone.  Roles having <TT
CLASS="LITERAL"
>CREATEROLE</TT
> privilege can grant
   or revoke membership in any role that is not a superuser.
  </P
><P
>   Unlike the case with privileges, membership in a role cannot be granted
   to <TT
CLASS="LITERAL"
>PUBLIC</TT
>.  Note also that this form of the command does not
   allow the noise word <TT
CLASS="LITERAL"
>GROUP</TT
>.
  </P
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="SQL-GRANT-NOTES"
></A
><H2
>Notes</H2
><P
>    The <A
HREF="sql-revoke.html"
>REVOKE</A
> command is used
    to revoke access privileges.
   </P
><P
>    Since <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> 8.1, the concepts of users and
    groups have been unified into a single kind of entity called a role.
    It is therefore no longer necessary to use the keyword <TT
CLASS="LITERAL"
>GROUP</TT
>
    to identify whether a grantee is a user or a group.  <TT
CLASS="LITERAL"
>GROUP</TT
>
    is still allowed in the command, but it is a noise word.
   </P
><P
>    A user may perform <TT
CLASS="COMMAND"
>SELECT</TT
>, <TT
CLASS="COMMAND"
>INSERT</TT
>, etc. on a
    column if he holds that privilege for either the specific column or
    its whole table.  Granting the privilege at the table level and then
    revoking it for one column will not do what you might wish: the
    table-level grant is unaffected by a column-level operation.
   </P
><P
>    When a non-owner of an object attempts to <TT
CLASS="COMMAND"
>GRANT</TT
> privileges
    on the object, the command will fail outright if the user has no
    privileges whatsoever on the object.  As long as some privilege is
    available, the command will proceed, but it will grant only those
    privileges for which the user has grant options.  The <TT
CLASS="COMMAND"
>GRANT ALL
    PRIVILEGES</TT
> forms will issue a warning message if no grant options are
    held, while the other forms will issue a warning if grant options for
    any of the privileges specifically named in the command are not held.
    (In principle these statements apply to the object owner as well, but
    since the owner is always treated as holding all grant options, the
    cases can never occur.)
   </P
><P
>    It should be noted that database superusers can access
    all objects regardless of object privilege settings.  This
    is comparable to the rights of <TT
CLASS="LITERAL"
>root</TT
> in a Unix system.
    As with <TT
CLASS="LITERAL"
>root</TT
>, it's unwise to operate as a superuser
    except when absolutely necessary.
   </P
><P
>    If a superuser chooses to issue a <TT
CLASS="COMMAND"
>GRANT</TT
> or <TT
CLASS="COMMAND"
>REVOKE</TT
>
    command, the command is performed as though it were issued by the
    owner of the affected object.  In particular, privileges granted via
    such a command will appear to have been granted by the object owner.
    (For role membership, the membership appears to have been granted
    by the containing role itself.)
   </P
><P
>    <TT
CLASS="COMMAND"
>GRANT</TT
> and <TT
CLASS="COMMAND"
>REVOKE</TT
> can also be done by a role
    that is not the owner of the affected object, but is a member of the role
    that owns the object, or is a member of a role that holds privileges
    <TT
CLASS="LITERAL"
>WITH GRANT OPTION</TT
> on the object.  In this case the
    privileges will be recorded as having been granted by the role that
    actually owns the object or holds the privileges
    <TT
CLASS="LITERAL"
>WITH GRANT OPTION</TT
>.  For example, if table
    <TT
CLASS="LITERAL"
>t1</TT
> is owned by role <TT
CLASS="LITERAL"
>g1</TT
>, of which role
    <TT
CLASS="LITERAL"
>u1</TT
> is a member, then <TT
CLASS="LITERAL"
>u1</TT
> can grant privileges
    on <TT
CLASS="LITERAL"
>t1</TT
> to <TT
CLASS="LITERAL"
>u2</TT
>, but those privileges will appear
    to have been granted directly by <TT
CLASS="LITERAL"
>g1</TT
>.  Any other member
    of role <TT
CLASS="LITERAL"
>g1</TT
> could revoke them later.
   </P
><P
>    If the role executing <TT
CLASS="COMMAND"
>GRANT</TT
> holds the required privileges
    indirectly via more than one role membership path, it is unspecified
    which containing role will be recorded as having done the grant.  In such
    cases it is best practice to use <TT
CLASS="COMMAND"
>SET ROLE</TT
> to become the
    specific role you want to do the <TT
CLASS="COMMAND"
>GRANT</TT
> as.
   </P
><P
>    Granting permission on a table does not automatically extend
    permissions to any sequences used by the table, including
    sequences tied to <TT
CLASS="TYPE"
>SERIAL</TT
> columns.  Permissions on
    sequences must be set separately.
   </P
><P
>    Use <A
HREF="app-psql.html"
><SPAN
CLASS="APPLICATION"
>psql</SPAN
></A
>'s <TT
CLASS="COMMAND"
>\dp</TT
> command
    to obtain information about existing privileges for tables and
    columns.  For example:
</P><PRE
CLASS="PROGRAMLISTING"
>=&gt; \dp mytable
                              Access privileges
 Schema |  Name   | Type  |   Access privileges   | Column access privileges 
--------+---------+-------+-----------------------+--------------------------
 public | mytable | table | miriam=arwdDxt/miriam | col1:
                          : =r/miriam             :   miriam_rw=rw/miriam
                          : admin=arw/miriam        
(1 row)</PRE
><P>
    The entries shown by <TT
CLASS="COMMAND"
>\dp</TT
> are interpreted thus:
</P><PRE
CLASS="LITERALLAYOUT"
>rolename=xxxx -- privileges granted to a role
        =xxxx -- privileges granted to PUBLIC

            r -- SELECT ("read")
            w -- UPDATE ("write")
            a -- INSERT ("append")
            d -- DELETE
            D -- TRUNCATE
            x -- REFERENCES
            t -- TRIGGER
            X -- EXECUTE
            U -- USAGE
            C -- CREATE
            c -- CONNECT
            T -- TEMPORARY
      arwdDxt -- ALL PRIVILEGES (for tables, varies for other objects)
            * -- grant option for preceding privilege

        /yyyy -- role that granted this privilege</PRE
><P>

    The above example display would be seen by user <TT
CLASS="LITERAL"
>miriam</TT
> after
    creating table <TT
CLASS="LITERAL"
>mytable</TT
> and doing:

</P><PRE
CLASS="PROGRAMLISTING"
>GRANT SELECT ON mytable TO PUBLIC;
GRANT SELECT, UPDATE, INSERT ON mytable TO admin;
GRANT SELECT (col1), UPDATE (col1) ON mytable TO miriam_rw;</PRE
><P>
   </P
><P
>    For non-table objects there are other <TT
CLASS="COMMAND"
>\d</TT
> commands
    that can display their privileges.
   </P
><P
>    If the <SPAN
CLASS="QUOTE"
>"Access privileges"</SPAN
> column is empty for a given object,
    it means the object has default privileges (that is, its privileges column
    is null).  Default privileges always include all privileges for the owner,
    and can include some privileges for <TT
CLASS="LITERAL"
>PUBLIC</TT
> depending on the
    object type, as explained above.  The first <TT
CLASS="COMMAND"
>GRANT</TT
> or
    <TT
CLASS="COMMAND"
>REVOKE</TT
> on an object
    will instantiate the default privileges (producing, for example,
    <TT
CLASS="LITERAL"
>{miriam=arwdDxt/miriam}</TT
>) and then modify them per the
    specified request.  Similarly, entries are shown in <SPAN
CLASS="QUOTE"
>"Column access
    privileges"</SPAN
> only for columns with nondefault privileges.
    (Note: for this purpose, <SPAN
CLASS="QUOTE"
>"default privileges"</SPAN
> always means the
    built-in default privileges for the object's type.  An object whose
    privileges have been affected by an <TT
CLASS="COMMAND"
>ALTER DEFAULT PRIVILEGES</TT
>
    command will always be shown with an explicit privilege entry that
    includes the effects of the <TT
CLASS="COMMAND"
>ALTER</TT
>.)
   </P
><P
>    Notice that the owner's implicit grant options are not marked in the
    access privileges display.  A <TT
CLASS="LITERAL"
>*</TT
> will appear only when
    grant options have been explicitly granted to someone.
   </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="SQL-GRANT-EXAMPLES"
></A
><H2
>Examples</H2
><P
>   Grant insert privilege to all users on table <TT
CLASS="LITERAL"
>films</TT
>:

</P><PRE
CLASS="PROGRAMLISTING"
>GRANT INSERT ON films TO PUBLIC;</PRE
><P>
  </P
><P
>   Grant all available privileges to user <TT
CLASS="LITERAL"
>manuel</TT
> on view
   <TT
CLASS="LITERAL"
>kinds</TT
>:

</P><PRE
CLASS="PROGRAMLISTING"
>GRANT ALL PRIVILEGES ON kinds TO manuel;</PRE
><P>

   Note that while the above will indeed grant all privileges if executed by a
   superuser or the owner of <TT
CLASS="LITERAL"
>kinds</TT
>, when executed by someone
   else it will only grant those permissions for which the someone else has
   grant options.
  </P
><P
>   Grant membership in role <TT
CLASS="LITERAL"
>admins</TT
> to user <TT
CLASS="LITERAL"
>joe</TT
>:

</P><PRE
CLASS="PROGRAMLISTING"
>GRANT admins TO joe;</PRE
><P></P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="SQL-GRANT-COMPATIBILITY"
></A
><H2
>Compatibility</H2
><P
>    According to the SQL standard, the <TT
CLASS="LITERAL"
>PRIVILEGES</TT
>
    key word in <TT
CLASS="LITERAL"
>ALL PRIVILEGES</TT
> is required.  The
    SQL standard does not support setting the privileges on more than
    one object per command.
   </P
><P
>    <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> allows an object owner to revoke his
    own ordinary privileges: for example, a table owner can make the table
    read-only to himself by revoking his own <TT
CLASS="LITERAL"
>INSERT</TT
>,
    <TT
CLASS="LITERAL"
>UPDATE</TT
>, <TT
CLASS="LITERAL"
>DELETE</TT
>, and <TT
CLASS="LITERAL"
>TRUNCATE</TT
>
    privileges.  This is not possible according to the SQL standard.  The
    reason is that <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> treats the owner's
    privileges as having been granted by the owner to himself; therefore he
    can revoke them too.  In the SQL standard, the owner's privileges are
    granted by an assumed entity <SPAN
CLASS="QUOTE"
>"_SYSTEM"</SPAN
>.  Not being
    <SPAN
CLASS="QUOTE"
>"_SYSTEM"</SPAN
>, the owner cannot revoke these rights.
   </P
><P
>    According to the SQL standard, grant options can be granted to
    <TT
CLASS="LITERAL"
>PUBLIC</TT
>; PostgreSQL only supports granting grant options
    to roles.
   </P
><P
>    The SQL standard provides for a <TT
CLASS="LITERAL"
>USAGE</TT
> privilege
    on other kinds of objects: character sets, collations,
    translations.
   </P
><P
>    In the SQL standard, sequences only have a <TT
CLASS="LITERAL"
>USAGE</TT
>
    privilege, which controls the use of the <TT
CLASS="LITERAL"
>NEXT VALUE FOR</TT
>
    expression, which is equivalent to the
    function <CODE
CLASS="FUNCTION"
>nextval</CODE
> in PostgreSQL.  The sequence
    privileges <TT
CLASS="LITERAL"
>SELECT</TT
> and <TT
CLASS="LITERAL"
>UPDATE</TT
> are
    PostgreSQL extensions.  The application of the
    sequence <TT
CLASS="LITERAL"
>USAGE</TT
> privilege to
    the <TT
CLASS="LITERAL"
>currval</TT
> function is also a PostgreSQL extension (as
    is the function itself).
   </P
><P
>    Privileges on databases, tablespaces, schemas, and languages are
    <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> extensions.
   </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN78594"
></A
><H2
>See Also</H2
><A
HREF="sql-revoke.html"
>REVOKE</A
>, <A
HREF="sql-alterdefaultprivileges.html"
>ALTER DEFAULT PRIVILEGES</A
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="sql-fetch.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="sql-insert.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>FETCH</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="sql-commands.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>INSERT</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>