-<Chapter Id="commands">
-<Title>Commandsitle>
+<chapter Id="sql-commands">
+<title>Commandsitle>
-<Para>
-Para>
+<para>
+para>
&alterTable;
&alterUser;
&createTable;
&createTrigger;
&createType;
+&createUser;
+&createView;
+&declare;
+&delete;
&dropFunction;
+&reset;
+&revoke;
+&rollback;
&select;
+&set;
+&show;
+&update;
-
+
+
+
+
SQL Functions
+
+
+
+¤tDate;
+¤tTime;
+¤tTimestamp;
+¤tUser;
+
+
\ No newline at end of file
--- /dev/null
+
+
+
+ CREATE VIEW
+
+ SQL - Language Statements
+
+
+
+ CREATE VIEW
+
+
+Constructs a virtual table
+
+
+
+ 1998-04-15
+
+
+ CREATE VIEW view
+ AS SELECT query
+
+
+
+
+ 1998-04-15
+
+
+ Inputs
+
+
+
+
+
+
+
+
+
+
+ view
+
+
+ The name of a view to be created.
+
+
+
+
+
+ query
+
+
+An SQL query which will provide the columns and rows of the view.
+
+ Refer to the SELECT statement for more information
+ about valid arguments.
+
+
+
+
+
+
+
+
+
+
+
+ 1998-04-15
+
+
+ Outputs
+
+
+
+
+
+
+
+
+
+
+ CREATE
+
+
+ The message returned if the view is successfully created.
+
+
+
+
+
+
+ WARN amcreate: "view" relation already exists
+
+
+
+ This error occurs if the view specified already exists in the database.
+
+
+
+
+
+ NOTICE create: attribute named "column" has an unknown type
+
+
+ The view will be created having a column with an unknown type
+ if you do not specify it. For example, the following command gives
+ an error:
+ CREATE VIEW vista AS SELECT 'Hello World'
+
+ whereas this command does not:
+ CREATE VIEW vista AS SELECT 'Hello World'::text
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1998-04-15
+
+
+ Description
+
+ CREATE VIEW will define a view of a table. This view is
+ not physically materialized. Specifically, a query
+ rewrite retrieve rule is automatically generated
+ to support retrieve operations on views.
+
+
+
+
+ 1998-04-15
+
+
+ Notes
+
+ Use the DROP VIEW statement to drop views.
+
+
+
+
+
+ 1998-04-15
+
+
+ Bugs
+
+ Currently, views are read only.
+
+
+
+
+
+ Usage
+
+ Create a view consisting of all Comedy films:
+
+ CREATE VIEW kinds AS
+ SELECT *
+ FROM films
+ WHERE kind = 'Comedy';
+
+ SELECT * FROM kinds;
+
+ code |title |did| date_prod|kind |len
+ -----+-------------------------+---+----------+----------+------
+ UA502|Bananas |105|1971-07-13|Comedy | 01:22
+ C_701|There's a Girl in my Soup|107|1970-06-11|Comedy | 01:36
+
+
+
+
+
+
+ Compatibility
+
+
+
+
+
+ 1998-04-15
+
+
+ SQL92
+
+ SQL92 specifies some additional capabilities for the CREATE VIEW statement:
+
+ CREATE VIEW view [ column [, ...] ]
+ AS SELECT expression [AS colname] [, ...]
+ FROM table
+ [WHERE condition]
+ [ WITH [ CASCADE | LOCAL ] CHECK OPTION ]
+
+
+
+
+
+
+
+
+
+
+ CHECK OPTION
+
+
+
This option is to do with updatable views.
+ All INSERTs and UPDATEs on the view will be
+ checked to ensure data satisfy the view-defining
+ condition. If they do not, the update will be rejected.
+
+
+
+
+
+ LOCAL
+
+
+ Check for integrity on this view.
+
+
+
+
+
+ CASCADE
+
+
+ Check for integrity on this view and on any dependent
+ view. CASCADE is assumed if neither CASCADE nor LOCAL is specified.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
--- /dev/null
+
+
+
+ SQL_CURRENT_DATE
+
+ SQL - Functions
+
+
+
+ SQL_CURRENT_DATE
+
+
+- returns the current date, (i.e "today").
+
+
+
+ 1998-04-15
+
+
+ CURRENT_DATE
+
+
+
+
+ 1998-04-15
+
+
+ Inputs
+
+
+
+
+
+
+
+
+
+
+ None
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1998-04-15
+
+
+ Outputs
+
+
+
+
+
+
+
+
+
+
+ Returns "today"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1998-04-15
+
+
+ Description
+
+ The niladic CURRENT_DATE function has a data type of
+ DATE and returns the date at the time that it is run.
+
+
+
+
+ 1998-04-15
+
+
+ Notes
+
+ Refer to SET DATESTYLE for further information about date format.
+
+
+
+
+
+ Usage
+
+ Insert the date of insertion into a row:
+
+ INSERT INTO films
+ VALUES ('TM999','Ben Hur',105,CURRENT_DATE,'Action',NULL);
+
+
+ Display CURRENT-DATE:
+
+ SELECT CURRENT_DATE AS today;
+
+ today
+ ------------
+ 1998-03-31
+
+
+
+
+
+
+ Compatibility
+
+
+
+
+
+ 1998-04-15
+
+
+ SQL92
+
+ Full compatibility.
+
+
+
+
+
+
\ No newline at end of file
--- /dev/null
+
+
+
+ SQL_CURRENT_TIME
+
+ SQL - Functions
+
+
+
+ SQL_CURRENT_TIME
+
+
+ - returns the current local time, (i.e "now").
+
+
+
+ 1998-04-15
+
+
+ CURRENT_TIME
+
+
+
+
+ 1998-04-15
+
+
+ Inputs
+
+
+
+
+
+
+
+
+
+
+ None
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1998-04-15
+
+
+ Outputs
+
+
+
+
+
+
+
+
+
+
+ Returns "now"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1998-04-15
+
+
+ Description
+
+ The niladic CURRENT_TIME function has a data type of
+ TIME and returns the local time when it is run.
+
+
+
+
+ 1998-04-15
+
+
+ Notes
+
+
Refer to the SET TIME ZONE statement for a further description
+ of local time.
+
+
+
+
+
+ Usage
+
+
+ SELECT CURRENT_TIME AS now;
+
+ now
+ -----------
+ 17:41:31+02
+
+
+
+
+
+
+ Compatibility
+
+
+
+
+
+ 1998-04-15
+
+
+ SQL92
+
+ SQL92 specifies some additional capabilities for CURRENT_TIME:
+
+
+
+
+
+
+
+
+
+
+ CURRENT_TIME [ (scale) ]
+
+
+ The optional scale for CURRENT_TIME, if specified, is an
+ unsigned integer representing the number of digits in the
+ optional seconds fraction of the time value represented
+ by the function.
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
--- /dev/null
+
+
+
+ SQL_CURRENT_TIMESTAMP
+
+ SQL - Functions
+
+
+
+ SQL_CURRENT_TIMESTAMP
+
+
+ returns the current timestamp, (i.e the
+ date "today" concatenated with time "now").
+
+
+
+
+
+ 1998-04-15
+
+
+ CURRENT_TIMESTAMP
+
+
+
+
+ 1998-04-15
+
+
+ Inputs
+
+
+
+
+
+
+
+
+
+
+ None
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1998-04-15
+
+
+ Outputs
+
+
+
+
+
+
+
+
+
+
+ Returns "today" and "now".
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1998-04-15
+
+
+ Description
+
+ The niladic CURRENT_TIMESTAMP function has a data type of
+ TIMESTAMP and returns the date and local time at which it is run.
+
+
+
+
+ 1998-04-15
+
+
+ Notes
+
+ Refer to the SET TIME ZONE statement for a further description
+ of local time.
+
+
+
+
+
+
+
+ Usage
+
+ Display CURRENT_TIMESTAMP:
+
+ SELECT CURRENT_TIMESTAMP AS date_and_time;
+
+ date_and_time
+ ----------------------
+ 1998-03-31 07:41:21-08
+
+
+
+
+
+ Compatibility
+
+
+
+
+
+ 1998-04-15
+
+
+ SQL92
+
+ SQL92 specifies some additional capabilities for CURRENT_TIMESTAMP:
+
+
+
+
+
+
+
+
+
+
+ CURRENT_TIMESTAMP [ (scale) ]
+
+
+ The optional scale for CURRENT_TIMESTAMP, if specified, is an
+ unsigned integer representing the number of digits in the
+ optional seconds fraction of the time value represented
+ by the function.
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
--- /dev/null
+
+
+
+ SQL_CURRENT_USER
+
+ SQL - Functions
+
+
+
+ SQL_CURRENT_USER
+
+
+ - returns the current user name.
+
+
+
+ 1998-04-15
+
+
+ CURRENT_USER
+
+
+
+
+ 1998-04-15
+
+
+ Inputs
+
+
+
+
+
+
+
+
+
+
+ None
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1998-04-15
+
+
+ Outputs
+
+
+
+
+
+
+
+
+
+
+ The name of the current user.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1998-04-15
+
+
+ Description
+
+ The niladic CURRENT_USER function returns a string of type "name"
+ whose value represents a user name identification.
+
+
+
+
+ 1998-04-15
+
+
+ Notes
+
+ Data type "name" is a non-standard 31-character type for storing
+ system identifiers.
+
+
+
+
+
+ Usage
+
+ Display CURRENT_USER
+
+ SELECT CURRENT_USER AS who_am_i;
+
+ who_am_i
+ ------------
+ jose
+
+
+
+
+
+ Compatibility
+
+
+
+
+
+ 1998-04-15
+
+
+ SQL92
+
+ SQL92 specifies some additional niladic USER functions:
+
+
+
+ CURRENT_USER / USER
+
+ USER is a synonym for CURRENT_USER.
+
+
+
+
+ SESSION_USER
+
+ The SESSION_USER function returns the SQL-session user name.
+
+
+
+
+ SYSTEM_USER
+
+ The SYSTEM_USER function returns the database's initial default user.
+
+
+
+
+ A niladic USER function returns a SQL_TEXT character string whose
+ value represents a user name.
+
+
+
+
+
+
\ No newline at end of file
--- /dev/null
+
+
+
+ DECLARE STATEMENT
+
+ SQL - Language Statements
+
+
+
+ DECLARE STATEMENT
+
+
+ Declares a cursor
+
+
+
+ 1998-04-15
+
+
+ DECLARE cursor [ BINARY ]
+ FOR SELECT query
+
+
+
+ 1998-04-15
+
+
+ Inputs
+
+
+
+
+
+
+
+
+
+
+ BINARY
+
+
+ The BINARY keyword causes the cursor to fetch data in binary
+ rather than in ASCII format.
+
+
+
+
+
+ cursor
+
+
+ The cursor's name.
+
+
+
+
+
+ query
+
+
+ An SQL query which will provide the rows to be governed by the
+ cursor.
+
+ Refer to the SELECT statement for further information about
+ valid arguments.
+
+
+
+
+
+
+
+
+
+
+
+ 1998-04-15
+
+
+ Outputs
+
+
+
+
+
+
+
+
+
+
+ SELECT
+
+
+ The message returned if the SELECT is run successfully.
+
+
+
+
+
+ NOTICE
+ BlankPortalAssignName: portal "cursor" already exists
+
+
+ This error occurs if cursor "cursor" is already declared.
+
+
+
+
+
+
+
+
+
+
+
+
+ 1998-04-15
+
+
+ Description
+
+ DECLARE allows a user to create cursors, which can be used to retrieve
+ a small number of rows at a time out of a larger query. Cursors can return
+ data either in ASCII or in binary foramt.
+
+ Normal cursors return data in ASCII format. Since
+ data is stored natively in binary format, the system must
+ do a conversion to produce the ASCII format. In addition,
+ ASCII formats are often larger in size than binary format.
+ Once the information comes back in ASCII, the client
+ application often has to convert it to a binary format to
+ manipulate it anyway.
+
+ BINARY cursors give you back the data in the native binary
+ representation. So binary cursors will tend to be a
+ little faster since they suffer less conversion overhead.
+ For example, for an integer column, you get a C integer number like ^A
+ using a binary cursor, while you get a string value like '1'
+ using the non binary cursor.
+
+ However, ASCII is architecture-neutral whereas binary
+ representation can differ between different machine architectures.
+ Therefore, if your client machine and server machine use different
+ representations, you will probably not want your data returned in
+ binary format.
+ Again, if you intend to display the data in
+ ASCII, getting it back in ASCII will save you some
+ effort on the client side.
+
+
+
+
+ 1998-04-15
+
+
+ Notes
+
+ Cursors are only available in transactions.
+
+ PostgreSQL does not have an explicit OPEN cursor
+ statement; a cursor is considered to be open when it is DECLAREd.
+
+
+
+
+
+
+ Usage
+
+ To declare a cursor:
+
+ DECLARE liahona CURSOR
+ FOR SELECT * FROM films;
+
+
+
+
+
+ Compatibility
+
+
+
+
+
+ 1998-04-15
+
+
+ SQL92
+
+ SQL92 specifies some additional capabilities for the DECLARE statement:
+
+
+ DECLARE cursor [ INSENSITIVE ] [ SCROLL ] CURSOR
+ FOR SELECT expression
+ [ ORDER BY column [, ... ] [ ASC | DESC ]
+ [ FOR { READ ONLY | UPDATE [ OF column [, ...] ] } ]
+
+
+
+
+
+
+
+ INSENSITIVE
+
+ UPDATE and DELETE CURRENT operations are not allowed
+ if the cursor is declared to be INSENSITIVE.
+
+
+
+
+ SCROLL
+
+ If SCROLL is not specified, only FETCH NEXT will be allowed.
+
+
+
+
+ FOR READ ONLY/UPDATE
+
+ If READ ONLY is specified, UPDATE/DELETE CURRENT operations
+ will not be allowed.
+
+
+
+
+
+
+
+
+
+
--- /dev/null
+
+
+
+ DELETE
+
+ SQL - Language Statements
+
+
+
+ DELETE
+
+
+ Deletes rows from a table
+
+
+
+
+
+ 1998-04-15
+
+
+ DELETE FROM table [ WHERE condition ]
+
+
+
+
+ 1998-04-15
+
+
+ Inputs
+
+
+
+
+
+
+
+
+
+
+ table
+
+
+ The name of an existing table.
+
+
+
+
+
+ condition
+
+
+ This is an SQL selection query which returns the rows which
+ are to be deleted.
+
+ Refer to the SELECT statement for further description
+ of the WHERE clause.
+
+
+
+
+
+
+
+
+
+
+
+ 1998-04-15
+
+
+ Outputs
+
+
+
+
+
+
+
+
+
+
+ DELETE count
+
+
+ Message returned if items are successfully deleted. The
+ count is the number
+ of rows deleted.
+
+ If count is 0,
+ no rows are deleted.
+
+
+
+
+
+
+
+
+
+
+
+
+ 1998-04-15
+
+
+ Description
+
+ DELETE removes rows which satisfy the WHERE condition,
+ from the specified table.
+
+ If the condition is absent,
+ the effect is to delete all rows in the table.
+ The result is a valid, but empty table.
+
+ You must have write access to the table in order to modify
+ it, as well as read access to any table whose values are
+ read in the condition.
+
+
+
+
+
+ Usage
+
+ Remove all films but musicals:
+
+ DELETE FROM films WHERE kind <> 'Musical';
+
+ SELECT * FROM films;
+
+ code |title |did| date_prod|kind |len
+ -----+-------------------------+---+----------+----------+------
+ UA501|West Side Story |105|1961-01-03|Musical | 02:32
+ TC901|The King and I |109|1956-08-11|Musical | 02:13
+ WD101|Bed Knobs and Broomsticks|111| |Musical | 01:57
+
+ Clear the table films:
+
+ DELETE FROM films;
+
+ SELECT * FROM films;
+ code|title|did|date_prod|kind|len
+ ----+-----+---+---------+----+---
+ (0 rows)
+
+
+
+
+
+ Compatibility
+
+
+
+
+
+ 1998-04-15
+
+
+ SQL92
+
+ SQL92 defines a different syntax for a positioned DELETE statement:
+
+
+
+ DELETE FROM table WHERE CURRENT OF cursor
+
+ where cursor identifies an open cursor.
+
+
+
+
+
\ No newline at end of file
--- /dev/null
+
+
+
+RESET
+
+SQL - Language Statements
+
+
+
+RESET
+
+
+Restores run-time parameters for session to default values
+
+
+
+
+1998-09-01
+
+
+RESET variable
+
+
+
+
+1998-09-01
+
+
+Inputs
+
+
+
+
+
+variable
+
+
+ Refer to the SET statement for more information on available
+ variables.
+
+
+
+
+
+
+1998-04-15
+
+
+Outputs
+
+
+
+
+
+
+RESET VARIABLE
+
+
+ Message returned if successfully.
+
+
+
+
+
+
+
+
+1998-04-15
+
+
+Description
+
+ The RESET statement restores variables to the default values.
+Refer to the SET command for details on allowed values and defaults.
+RESET is an alternate form for
+
+SET variable = DEFAULT
+
+
+
+
+1998-04-15
+
+
+Notes
+
+The RESET statement is a
Postgres language extension.
+ Refer to SET/SHOW statements to set/show variable values.
+
+
+
+
+
+
+Usage
+
+ -- reset DateStyle to its default;
+ RESET DateStyle;
+
+ -- reset Geqo to its default;
+ RESET GEQO;
+
+
+
+
+
+
+Compatibility
+
+
+
+
+
+1998-04-15
+
+
+SQL92
+
+ There is no RESET statement in SQL92.
+
+
+
--- /dev/null
+
+
+
+REVOKE
+
+SQL - Language Statements
+
+
+
+REVOKE
+
+
+Revokes access privilege from a user, a group or all users.
+
+
+
+
+1998-09-01
+
+
+
+
+REVOKE privilege [, ...]
+ ON object [, ...]
+ FROM { PUBLIC | GROUP group | username }
+
+
+
+
+1998-09-01
+
+
+Inputs
+
+
+
+
+
+privilege
+
+
+ The possible privileges are:
+
+
+
+
+SELECT
+
+
+Privilege to access all of the columns of a specific
+ table/view.
+
+
+
+
+
+
+INSERT
+
+
+Privilege to insert data into all columns of a
+ specific table.
+
+
+
+UPDATE
+
+
+Privilege to update all columns of a specific
+ table.
+
+
+
+DELETE
+
+
+Privilege to delete rows from a specific table.
+
+
+
+RULE
+
+
+Privilege to define rules on table/view.
+(See the CREATE RULE statement).
+
+
+
+ALL
+
+
+Rescind all privileges.
+
+
+
+
+
+object
+
+
+The name of an object from which to revoke access.
+ The possible objects are:
+
+
+ table
+
+ view
+
+ sequence
+
+ index
+
+
+
+
+group
+
+
+ The name of a group from whom to revoke privileges.
+
+
+
+
+
+
+username
+
+
+The name of a user from whom revoke privileges. Use the PUBLIC keyword
+to specify all users.
+
+
+
+
+
+
+PUBLIC
+
+
+Rescind the specified privilege(s) for all users.
+
+
+
+
+
+
+
+
+
+1998-04-15
+
+
+Outputs
+
+
+
+
+
+
+CHANGE
+
+
+ Message returned if successfully.
+
+
+
+ERROR
+
+
+ Message returned if object is not available or impossible
+ to revoke privileges from a group or users.
+
+
+
+
+
+
+
+
+1998-09-01
+
+
+Description
+
+ REVOKE allows creator of an object to revoke permissions granted
+ before, from all users (via PUBLIC) or a certain user or group.
+
+
+
+1998-04-15
+
+
+Notes
+
+ Refer to psql \z command for further information about permissions
+ on existing objects:
+
+ Database = lusitania
+ +------------------+---------------------------------------------+
+ | Relation | Grant/Revoke Permissions |
+ +------------------+---------------------------------------------+
+ | mytable | {"=rw","miriam=arwR","group todos=rw"} |
+ +------------------+---------------------------------------------+
+ Legend:
+ uname=arwR -- privileges granted to a user
+ group gname=arwR -- privileges granted to a GROUP
+ =arwR -- privileges granted to PUBLIC
+
+ r -- SELECT
+ w -- UPDATE/DELETE
+ a -- INSERT
+ R -- RULE
+ arwR -- ALL
+
+
+
+Currently, to create a GROUP you have to insert
+ data manually into table pg_group as:
+ INSERT INTO pg_group VALUES ('todos');
+ CREATE USER miriam IN GROUP todos;
+
+
+
+
+
+
+
+Usage
+
+ -- revoke insert privilege from all users on table films:
+ --
+ REVOKE INSERT ON films FROM PUBLIC;
+
+ -- revoke all privileges from user manuel on view kinds:
+ --
+ REVOKE ALL ON kinds FROM manuel;
+
+
+
+
+
+
+Compatibility
+
+
+
+
+
+1998-09-01
+
+
+SQL92
+
+ The SQL92 syntax for REVOKE has additional capabilities for rescinding
+privileges, including those on individual columns in tables:
+
+
+
+
+
+REVOKE { SELECT | DELETE | USAGE | ALL PRIVILEGES } [, ...]
+ ON object
+ FROM { PUBLIC | username [, ...] } { RESTRICT | CASCADE }
+REVOKE { INSERT | UPDATE | REFERENCES } [, ...] [ ( column [, ...] ) ]
+ ON object
+ FROM { PUBLIC | username [, ...] } { RESTRICT | CASCADE }
+
+
+Refer to the GRANT command for details on individual fields.
+
+
+
+
+REVOKE GRANT OPTION FOR privilege [, ...]
+ ON object
+ FROM { PUBLIC | username [, ...] } { RESTRICT | CASCADE }
+
+
+Rescinds authority for a user to grant the specified privilege to others.
+Refer to the GRANT command for details on individual fields.
+
+
+
+ The possible objects are:
+
+ [ TABLE ] table/view
+ CHARACTER SET character-set
+ COLLATION collation
+ TRANSLATION translation
+ DOMAIN domain
+
+
+If user1 gives a privilege WITH GRANT OPTION to user2,
+ and user2 gives it to user3 then user1 can revoke
+ this privilege in cascade using the CASCADE keyword.
+
+If user1 gives a privilege WITH GRANT OPTION to user2,
+ and user2 gives it to user3 then if user1 try revoke
+ this privilege it fails if he/she specify the RESTRICT
+ keyword.
+
+
+
--- /dev/null
+
+
+
+ROLLBACK
+
+SQL - Language Statements
+
+
+
+ROLLBACK
+
+
+Aborts the current transaction
+
+
+
+1998-09-01
+
+
+ROLLBACK [ WORK ]
+
+
+
+
+1998-09-01
+
+
+Inputs
+
+None.
+
+
+
+
+
+1998-04-15
+
+
+Outputs
+
+
+
+
+
+ ABORT
+
+
+ Message returned if successful.
+
+
+
+NOTICE: UserAbortTransactionBlock and not in in-progress state
+ABORT
+
+
+ If there is not any transaction currently in progress.
+
+
+
+
+
+
+
+
+
+1998-04-15
+
+
+Description
+
+ ROLLBACK rolls back the current transaction and causes
+ all the updates made by the transaction to be discarded.
+
+
+
+1998-04-15
+
+
+Notes
+
+The keyword WORK is noise and can be omitted.
+
+Use the COMMIT statement to successfully terminate a transaction.
+
+
+
+
+
+Usage
+
+ --To abort all changes:
+ --
+ ROLLBACK WORK;
+
+
+
+
+
+
+Compatibility
+
+
+
+
+
+1998-04-15
+
+
+SQL92
+
+ Full compatibility.
+
+
+
Description
+SELECT is the principal means to access information
+
SELECT will get all rows which satisfy the WHERE condition
or all rows of a table if WHERE is omitted.
The GROUP BY clause allows a user to divide a table
conceptually into groups. (See GROUP BY clause).
The HAVING clause specifies a grouped table derived by the
elimination of groups from the result of the previously
specified clause. (See HAVING clause).
The ORDER BY clause allows a user to specify that he/she
wishes the rows sorted according to the ASCending or
DESCending mode operator. (See ORDER BY clause)
The UNION clause specifies a table derived from a Cartesian
product union join. (See UNION clause).
--- /dev/null
+
+
+
+SET
+
+SQL - Language Statements
+
+
+
+SET
+
+
+ Set run-time parameters for session
+
+
+
+1998-08-31
+
+
+
+
+SET variable { TO | = } { 'value' | DEFAULT }
+
+SET TIME ZONE { 'timezone' | LOCAL };
+
+
+
+
+1998-08-31
+
+
+Inputs
+
+
+
+
+variable
+
+
+Settable global parameter.
+
+
+
+value
+
+
+New value of parameter.
+
+
+ The possible variables and allowed values are:
+
+
+
+
+DateStyle
+
+
+
+
+
+
+ISO
+
+
+use ISO 8601-style dates and times
+
+
+SQL
+
+
+use Oracle/Ingres-style dates and times
+
+
+Postgres
+
+
+use traditional
Postgres format
+
+
+European
+
+
+use dd/mm/yyyy for numeric date representations.
+
+
+NonEuropean
+
+
+use mm/dd/yyyy for numeric date representations.
+
+
+German
+
+
+use dd.mm.yyyy for numeric date representations.
+
+
+US
+
+
+same as 'NonEuropean'
+
+
+default
+
+
+restores the default values ('US,Postgres')
+
+
+
+ Date format initialization my be done by:
+
+
+Setting PGDATESTYLE environment variable.
+
+
+Running postmaster using -oe parameter to set
+ dates to the 'European' convention.
+Note that this affects only the some combinations of date styles; for example
+the ISO style is not affected by this parameter.
+
+Changing variables in
+src/backend/utils/init/globals.c.
+
+
+The variables in globals.c which can be changed are:
+bool EuroDates = false
+ true
+int DateStyle = USE_ISO_DATES
+ USE_POSTGRES_DATES
+ USE_ISO_DATES
+ USE_SQL_DATES
+ USE_GERMAN_DATES
+
+
+
+
+
+
+TIMEZONE
+
+
+ The possible values for timezone depends on your operating
+ system. For example on Linux /usr/lib/zoneinfo contains the
+ database of timezones.
+ Here are some valid values for timezone:
+
+
+
+
+'PST8PDT'
+
+
+set the timezone for California
+
+
+'Portugal'
+
+
+set time zone for Portugal.
+
+
+'Europe/Rome'
+
+
+set time zone for Italy.
+
+
+DEFAULT
+
+
+set time zone to your local timezone
+(value of the TZ environment variable).
+
+
+ If an invalid time zone is specified, the time zone
+ becomes GMT (on most systems anyway).
+ A frontend which uses libpq may be initialized by setting the PGTZ
+ environment variable.
+ The second syntax shown above, allows one to set the timezone
+ with a syntax similar to SQL92 SET TIME ZONE.
+ The LOCAL keyword is just an alternate form
+ of DEFAULT for SQL92 compatibility.
+
+
+
+
+There are also several internal or optimization parameters which can be specified
+by the SET command:
+
+
+
+
+COST_HEAP
+
+
+Sets the default cost of a heap scan for use by the optimizer.
+
+
+
+
+float4
+
+
+Set the cost of a heap scan to the specified floating point value.
+
+
+
+DEFAULT
+
+
+Sets the cost of a heap scan to the default value.
+
+
+ The frontend may be initialized by setting the PGCOSTHEAP
+ environment variable.
+
+
+
+COST_INDEX
+
+
+Sets the default cost of an index scan for use by the optimizer.
+
+
+
+
+float4
+
+
+Set the cost of an index scan to the specified floating point value.
+
+
+
+DEFAULT
+
+
+Sets the cost of an index scan to the default value.
+
+
+ The frontend may be initialized by setting the PGCOSTINDEX
+ environment variable.
+
+
+
+GEQO
+
+
+Sets the threshold for using the genetic optimizer algorithm.
+
+
+
+
+On
+
+
+enables the genetic optimizer algorithm
+ for statements with 8 or more tables.
+
+
+On=#
+
+
+enables the genetic optimizer algorithm
+ for statements with # or more tables.
+
+
+Off
+
+
+disables the genetic optimizer algorithm.
+
+
+DEFAULT
+
+
+Equivalent to specifying SET GEQO=On
+
+
+
+ This algorithm is on by default, which used GEQO for
+ statements of eight or more tables.
+ (See the chapter on GEQO in the Programmer's Guide
+for more information).
+
+ The frontend may be initialized by setting PGGEQO
+ environment variable.
+
+
+
+
+R_PLANS
+
+
+Determines whether right-hand plan evaluation is allowed:
+
+
+
+
+On
+
+
+enables right-hand evaluation of plans.
+
+
+
+Off
+
+
+disables right-hand evaluation of plans.
+
+
+
+DEFAULT
+
+
+Equivalent to specifying SET R_PLANS=Off.
+
+
+ It may be useful when joining big relations with
+ small ones. This algorithm is off by default.
+ It's not used by GEQO anyway.
+ The frontend may be initialized by setting the PGRPLANS
+ environment variable.
+
+
+
+
+R_PLANS
+
+
+Determines whether right-hand plan evaluation is allowed:
+
+
+
+
+On
+
+
+enables right-hand evaluation of plans.
+
+
+
+Off
+
+
+disables right-hand evaluation of plans.
+
+
+
+DEFAULT
+
+
+Equivalent to specifying SET R_PLANS=Off.
+
+
+ It may be useful when joining big relations with
+ small ones. This algorithm is off by default.
+ It's not used by GEQO anyway.
+ The frontend may be initialized by setting the PGRPLANS
+ environment variable.
+
+
+
+
+
+
+
+1998-08-31
+
+
+Outputs
+
+
+
+
+
+ SET VARIABLE
+
+
+ Message returned if successfully.
+
+
+
+ WARN: Bad value for variable (value)
+
+
+ If fails to set variable.
+
+
+
+
+
+
+
+
+1998-08-31
+
+
+Description
+
+SET will modify configuration parameters for variable during
+ a session.
+
+ Current values can be obtained using SHOW statement, and values
+ can be restored to the defaults using RESET statement.
+ Parameters and values are case-insensitive. Note that the value
+ field is always specified as a string, so is enclosed in
+ single-quotes.
+ SET TIME ZONE changes the session's default time zone offset.
+ A SQL-session always begins with an initial default time zone
+ offset.
+ The SET TIME ZONE statement is used to change the default
+ time zone offset for the current SQL session.
+
+
+
+1998-08-31
+
+
+Notes
+
+The SET variable
+ statement is a
Postgres language extension.
+
+ Refer to SHOW/RESET statements to show/reset variable values.
+
+
+
+
+
+
+Usage
+
+
+ --Set the style of date to ISO:
+ --
+ SET DATESTYLE TO 'ISO';
+
+ --Set GEQO to default:
+ --
+ SET GEQO = DEFAULT;
+
+ --Turn on right-hand evaluation of plans:
+ --
+ SET R_PLANS TO 'on';
+
+ --set the timezone for Berkeley, California:
+ SET TIME ZONE 'PST8PDT';
+
+ SELECT CURRENT_TIMESTAMP AS today;
+
+ today
+ ----------------------
+ 1998-03-31 07:41:21-08
+
+ --set the timezone for Italy:
+ SET TIME ZONE 'Europe/Rome';
+
+ SELECT CURRENT_TIMESTAMP AS today;
+
+ today
+ ----------------------
+ 1998-03-31 17:41:31+02
+
+
+
+
+
+
+Compatibility
+
+
+
+
+
+1998-04-15
+
+
+SQL92
+
+ There is no
+SET variable
+ in SQL92.
+
+ The SQL92 syntax for SET TIME ZONE is slightly different,
+ allowing only a single integer value for time zone specification:
+
+SET TIME ZONE { interval_value_expression | LOCAL }
+
+
+
+
+
--- /dev/null
+
+
+
+SHOW
+
+SQL - Language Statements
+
+
+
+SHOW
+
+
+Shows run-time parameters for session
+
+
+
+1998-08-31
+
+
+SHOW variable
+
+
+
+
+1998-08-31
+
+
+Inputs
+
+
+
+
+
+variable
+
+
+ Refer to the SET statement for more information on available
+ variables.
+
+
+
+
+
+
+
+1998-08-31
+
+
+Outputs
+
+
+
+
+
+NOTICE: variable is value
+SHOW VARIABLE
+
+
+ Message returned if successfully.
+
+
+
+NOTICE: Unrecognized variable value
+
+Message returned if value does not exist.
+
+
+
+
+
+
+
+
+
+1998-08-31
+
+
+Description
+
+ SHOW will display the current configuration parameters for
+ variable during a session.
+
+ The session can be configured using SET statement, and values
+ can be restored to the defaults using RESET statement.
+ Parameters and values are case-insensitive.
+
+
+
+1998-08-31
+
+
+Notes
+
+ The SHOW statement is a
Postgres
+ language extension.
+
+ Refer to the SET/RESET statements to set/reset variable values.
+ See also the SET TIME ZONE statement.
+
+ If the TZ environment variable is not set the SHOW TIME ZONE statement
+ gives the message: Time zone is unknown
+
+
+
+
+
+Usage
+
+ -- show DateStyle;
+ SHOW DateStyle;
+ NOTICE:DateStyle is Postgres with US (NonEuropean) conventions
+
+ -- show Geqo;
+ SHOW GEQO;
+ NOTICE:GEQO is ON
+
+
+
+
+
+
+Compatibility
+
+
+
+
+
+1998-08-31
+
+
+SQL92
+
+ There is no SET statement defined in
SQL92.
+
+
+
--- /dev/null
+
+
+
+UPDATE
+
+SQL - Language Statements
+
+
+
+UPDATE
+
+
+Replaces values of columns in a table
+
+
+
+
+1998-04-15
+
+
+UPDATE table SET column = expression [, ...]
+ [FROM fromlist]
+ [WHERE condition]
+
+
+
+
+1998-04-15
+
+
+Inputs
+
+
+
+
+
+table
+
+
+ The name of an existing table.
+
+
+
+
+column
+
+
+The name of a column in table.
+
+
+
+
+expression
+
+
+ A valid expression or value to assign to column.
+
+
+
+
+fromlist
+
+
+ non-standard extension to allow columns
+ from other tables to appear in the WHERE condition.
+
+
+
+
+condition
+
+
+ Refer to the SELECT statement for a further description
+ of the WHERE clause.
+
+
+
+
+
+
+
+1998-04-15
+
+
+Outputs
+
+
+
+
+
+UPDATE #
+
+
+ Message returned if successful.
+The #
+ means the number of rows updated.
+If #
+ is equal 0 no rows are updated.
+
+
+
+
+
+
+
+
+
+1998-04-15
+
+
+Description
+
+ UPDATE changes the values of the columns specified for
+ all rows which satisfy condition. Only the columns
+ to be modified need appear as column.
+
+ Array references use the same syntax found in SELECT.
+ That is, either single array elements, a range of array
+ elements or the entire array may be replaced with a single
+ query.
+
+ You must have write access to the table in order to modify
+ it, as well as read access to any table whose values are
+ mentioned in the WHERE condition.
+
+
+
+
+
+Usage
+
+
+ --Change word "Drama" with "Dramatic" on column kind:
+ --
+ UPDATE films
+ SET kind = 'Dramatic'
+ WHERE kind = 'Drama';
+
+ SELECT * FROM films WHERE kind = 'Dramatic' OR kind = 'Drama';
+
+ code |title |did| date_prod|kind |len
+ -----+-------------+---+----------+----------+------
+ BL101|The Third Man|101|1949-12-23|Dramatic | 01:44
+ P_302|Becket |103|1964-02-03|Dramatic | 02:28
+ M_401|War and Peace|104|1967-02-12|Dramatic | 05:57
+ T_601|Yojimbo |106|1961-06-16|Dramatic | 01:50
+ DA101|Das Boot |110|1981-11-11|Dramatic | 02:29
+
+
+
+
+
+
+Compatibility
+
+
+
+
+
+1998-04-15
+
+
+SQL92
+
+ SQL92 defines a different syntax for positioned UPDATE statement:
+
+ UPDATE table SET column = expression [, ...]
+ WHERE CURRENT OF cursor
+
+
+ where cursor
+ identifies an open cursor.
+