Download Manual del usuario de PostgreSQL [ Postgres

Transcript
Capítulo 15. Aplicaciones
QUIET
This variable is equivalent to the command line option -q. It is probably not too
useful in interactive mode.
SINGLELINE
This variable is set be the command line options -S. You can unset or reset it at
run time.
SINGLESTEP
This variable is equivalent to the command line option -s.
USER
The database user you are currently connected as. This is set everytime you
connect to a database (including program startup), but can be unset.
SQL Interpolation
An additional useful feature of psql variables is that you can substitute (“interpolate”)
them into regular SQL statements. The syntax for this is again to prepend the variable
name with a colon (:).
testdb=> \set foo ’my_table’
testdb=> SELECT * FROM :foo;
would then query the table my_table. The value of the variable is copied literally, so it
can even contain unbalanced quotes or backslash commands. You must make sure that
it makes sense where you put it. Variable interpolation will not be performed into
quoted SQL entities.
A popular application of this facility is to refer to the last inserted OID in subsequent
statement to build a foreign key scenario. Another possible use of this mechanism is to
421