Search PostgreSQL documentation
PG 18 · Browse by category, or enter a name or keyword
Popular entries9769
ExamplesExamples
To start postgres in the background using default values, type:
$ nohup postgres >logfile 2>&1 </dev/null &
To start postgres with a specific port, e.g., 1234:
$ postgres -p 1234
To…Examples
ExamplesExamples
The first example shows how to spread a command over several lines of input. Notice the changing prompt:
testdb=> CREATE TABLE my_table ( testdb(> first integer not null default 0, …Examples
ExamplesExamples
To reindex the database test:
$ reindexdb test
To reindex the table foo and the index bar in a database named abcd:
$ reindexdb --table=foo --index=bar abcdExamples
ExamplesExamples
To clean the database test:
$ vacuumdb test
To clean and analyze for the optimizer a database named bigdb:
$ vacuumdb --analyze bigdb
To clean a single table foo in a database named…Examples
ExamplesF.6.2. Examples
This is an example of creating a bloom index:
CREATE INDEX bloomidx ON tbloom USING bloom (i1,i2,i3) WITH (length=80, col1=2, col2=2, col3=4);
The index is created with a sig…Examples
ExamplesExamples
SELECT dblink_build_sql_delete('"MyFoo"', '1 2', 2, '{"1", "b"}'); dblink_build_sql_delete --------------------------------------------- DELETE FROM "MyFoo" WHERE f1='1' AND f2='b' …Examples
ExamplesExamples
SELECT dblink_build_sql_insert('foo', '1 2', 2, '{"1", "a"}', '{"1", "b''a"}'); dblink_build_sql_insert -------------------------------------------------- INSERT INTO foo(f1,f2,f3) …Examples
ExamplesExamples
SELECT dblink_build_sql_update('foo', '1 2', 2, '{"1", "a"}', '{"1", "b"}'); dblink_build_sql_update ------------------------------------------------------------- UPDATE foo SET f1=…Examples
ExamplesExamples
SELECT dblink_cancel_query('dtest1');Examples
ExamplesExamples
SELECT dblink_connect('dbname=postgres options=-csearch_path='); dblink_connect ---------------- OK (1 row) SELECT dblink_open('foo', 'select proname, prosrc from pg_proc'); dblink_…Examples
ExamplesExamples
SELECT dblink_connect('dbname=postgres options=-csearch_path='); dblink_connect ---------------- OK (1 row) SELECT dblink_connect('myconn', 'dbname=postgres options=-csearch_path=')…Examples
ExamplesExamples
SELECT dblink_disconnect(); dblink_disconnect ------------------- OK (1 row) SELECT dblink_disconnect('myconn'); dblink_disconnect ------------------- OK (1 row)Examples
ExamplesExamples
SELECT dblink_error_message('dtest1');Examples
ExamplesExamples
SELECT dblink_connect('dbname=dblink_test_standby'); dblink_connect ---------------- OK (1 row) SELECT dblink_exec('insert into foo values(21, ''z'', ''{"a0","b0","c0"}'');'); dblin…Examples
ExamplesExamples
SELECT dblink_connect('dbname=postgres options=-csearch_path='); dblink_connect ---------------- OK (1 row) SELECT dblink_open('foo', 'select proname, prosrc from pg_proc where pron…Examples
ExamplesExamples
SELECT * FROM dblink('dbname=postgres options=-csearch_path=', 'select proname, prosrc from pg_proc') AS t1(proname name, prosrc text) WHERE proname LIKE 'bytea%'; proname | prosrc …Examples
ExamplesExamples
SELECT dblink_get_connections();Examples
ExamplesExamples
SELECT dblink_exec('LISTEN virtual'); dblink_exec ------------- LISTEN (1 row) SELECT * FROM dblink_get_notify(); notify_name | be_pid | extra -------------+--------+------- (0 rows…Examples
ExamplesExamples
CREATE TABLE foobar ( f1 int, f2 int, f3 int, PRIMARY KEY (f1, f2, f3) ); CREATE TABLE SELECT * FROM dblink_get_pkey('foobar'); position | colname ----------+--------- 1 | f1 2 | f2…Examples
ExamplesExamples
contrib_regression=# SELECT dblink_connect('dtest1', 'dbname=contrib_regression'); dblink_connect ---------------- OK (1 row) contrib_regression=# SELECT * FROM contrib_regression-#…Examples
ExamplesExamples
SELECT dblink_is_busy('dtest1');Examples
ExamplesExamples
SELECT dblink_connect('dbname=postgres options=-csearch_path='); dblink_connect ---------------- OK (1 row) SELECT dblink_open('foo', 'select proname, prosrc from pg_proc'); dblink_…Examples
ExamplesExamples
SELECT dblink_send_query('dtest1', 'SELECT * FROM foo WHERE f1 < 3');Examples
ExamplesExamples
EXEC SQL ALLOCATE DESCRIPTOR mydesc;Examples
ExamplesExamples
Here a several variants for specifying connection parameters:
EXEC SQL CONNECT TO "connectdb" AS main; EXEC SQL CONNECT TO "connectdb" AS second; EXEC SQL CONNECT TO "unix:postgresq…Examples
ExamplesExamples
EXEC SQL DEALLOCATE DESCRIPTOR mydesc;Examples
ExamplesExamples
EXEC SQL CONNECT TO postgres AS con1; EXEC SQL AT con1 DECLARE sql_stmt STATEMENT; EXEC SQL DECLARE cursor_name CURSOR FOR sql_stmt; EXEC SQL PREPARE sql_stmt FROM :dyn_string; EXEC…Examples
ExamplesExamples
Examples declaring a cursor for a query:
EXEC SQL DECLARE C CURSOR FOR SELECT * FROM My_Table; EXEC SQL DECLARE C CURSOR FOR SELECT Item1 FROM T; EXEC SQL DECLARE cur1 CURSOR FOR SE…Examples
ExamplesExamples
EXEC SQL ALLOCATE DESCRIPTOR mydesc; EXEC SQL PREPARE stmt1 FROM :sql_stmt; EXEC SQL DESCRIBE stmt1 INTO SQL DESCRIPTOR mydesc; EXEC SQL GET DESCRIPTOR mydesc VALUE 1 :charvar = NAM…Examples
ExamplesExamples
int main(void) { EXEC SQL CONNECT TO testdb AS con1 USER testuser; EXEC SQL CONNECT TO testdb AS con2 USER testuser; EXEC SQL CONNECT TO testdb AS con3 USER testuser; EXEC SQL DISCO…Examples
ExamplesExamples
Here is an example that executes an INSERT statement using EXECUTE IMMEDIATE and a host variable named command:
sprintf(command, "INSERT INTO test (name, amount, letter) VALUES ('db…Examples
ExamplesExamples
An example to retrieve the number of columns in a result set:
EXEC SQL GET DESCRIPTOR d :d_count = COUNT;
An example to retrieve a data length in the first column:
EXEC SQL GET DESC…Examples
ExamplesExamples
EXEC SQL OPEN a; EXEC SQL OPEN d USING 1, 'test'; EXEC SQL OPEN c1 USING SQL DESCRIPTOR mydesc; EXEC SQL OPEN :curname1;Examples
ExamplesExamples
char *stmt = "SELECT * FROM test1 WHERE a = ? AND b = ?"; EXEC SQL ALLOCATE DESCRIPTOR outdesc; EXEC SQL PREPARE foo FROM :stmt; EXEC SQL EXECUTE foo USING SQL DESCRIPTOR indesc INT…Examples
ExamplesExamples
EXEC SQL SET CONNECTION TO con2; EXEC SQL SET CONNECTION = con1;Examples
ExamplesExamples
EXEC SQL SET DESCRIPTOR indesc COUNT = 1; EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = 2; EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = :val1; EXEC SQL SET DESCRIPTOR indesc VALUE …Examples
ExamplesExamples
EXEC SQL TYPE customer IS struct { varchar name[50]; int phone; }; EXEC SQL TYPE cust_ind IS struct ind { short name_ind; short phone_ind; }; EXEC SQL TYPE c IS char reference; EXEC…Examples
ExamplesExamples
Exec sql begin declare section; short a; exec sql end declare section; EXEC SQL VAR a IS int;Examples
ExamplesExamples
EXEC SQL WHENEVER NOT FOUND CONTINUE; EXEC SQL WHENEVER NOT FOUND DO BREAK; EXEC SQL WHENEVER NOT FOUND DO CONTINUE; EXEC SQL WHENEVER SQLWARNING SQLPRINT; EXEC SQL WHENEVER SQLWARN…Examples
Examples65.4.7. Examples
The core PostgreSQL distribution includes the GIN operator classes previously shown in Table 65.3. The following contrib modules also contain GIN operator classes:
btree_gin…Examples
More results
Find definitions in the PostgreSQL manuals, reference library, and extension catalogue.
pg17: choose a version ex: extensions only ↑↓ select ↵ open