select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Search PostgreSQL documentation

PG 18 · Browse by category, or enter a name or keyword

Popular entries9769
ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18F.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 ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples SELECT dblink_build_sql_update('foo', '1 2', 2, '{"1", "a"}', '{"1", "b"}'); dblink_build_sql_update ------------------------------------------------------------- UPDATE foo SET f1=…Examples ExamplesManual ChaptersPG18Examples SELECT dblink_cancel_query('dtest1');Examples ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples SELECT dblink_connect('dbname=postgres options=-csearch_path='); dblink_connect ---------------- OK (1 row) SELECT dblink_connect('myconn', 'dbname=postgres options=-csearch_path=')…Examples ExamplesManual ChaptersPG18Examples SELECT dblink_disconnect(); dblink_disconnect ------------------- OK (1 row) SELECT dblink_disconnect('myconn'); dblink_disconnect ------------------- OK (1 row)Examples ExamplesManual ChaptersPG18Examples SELECT dblink_error_message('dtest1');Examples ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples SELECT dblink_get_connections();Examples ExamplesManual ChaptersPG18Examples SELECT dblink_exec('LISTEN virtual'); dblink_exec ------------- LISTEN (1 row) SELECT * FROM dblink_get_notify(); notify_name | be_pid | extra -------------+--------+------- (0 rows…Examples ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples contrib_regression=# SELECT dblink_connect('dtest1', 'dbname=contrib_regression'); dblink_connect ---------------- OK (1 row) contrib_regression=# SELECT * FROM contrib_regression-#…Examples ExamplesManual ChaptersPG18Examples SELECT dblink_is_busy('dtest1');Examples ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples SELECT dblink_send_query('dtest1', 'SELECT * FROM foo WHERE f1 < 3');Examples ExamplesManual ChaptersPG18Examples EXEC SQL ALLOCATE DESCRIPTOR mydesc;Examples ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples EXEC SQL DEALLOCATE DESCRIPTOR mydesc;Examples ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples EXEC SQL OPEN a; EXEC SQL OPEN d USING 1, 'test'; EXEC SQL OPEN c1 USING SQL DESCRIPTOR mydesc; EXEC SQL OPEN :curname1;Examples ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples EXEC SQL SET CONNECTION TO con2; EXEC SQL SET CONNECTION = con1;Examples ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG18Examples Exec sql begin declare section; short a; exec sql end declare section; EXEC SQL VAR a IS int;Examples ExamplesManual ChaptersPG18Examples 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 ExamplesManual ChaptersPG1865.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