mirror of
https://github.com/postgres/postgres.git
synced 2025-11-07 19:06:32 +03:00
Doc: use uppercase keywords in SQLs
Use uppercase SQL keywords consistently throughout the documentation to ease reading. Also add whitespace in a couple of places where it improves readability. Author: Erik Wienhold <ewie@ewie.name> Reviewed-by: David Rowley <dgrowleyml@gmail.com> Discussion: https://postgr.es/m/82eb512b-8ed2-46be-b311-54ffd26978c4%40ewie.name
This commit is contained in:
@@ -101,12 +101,12 @@ SELECT * FROM myview;
|
|||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE TABLE cities (
|
CREATE TABLE cities (
|
||||||
name varchar(80) primary key,
|
name varchar(80) PRIMARY KEY,
|
||||||
location point
|
location point
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE weather (
|
CREATE TABLE weather (
|
||||||
city varchar(80) references cities(name),
|
city varchar(80) REFERENCES cities (name),
|
||||||
temp_lo int,
|
temp_lo int,
|
||||||
temp_hi int,
|
temp_hi int,
|
||||||
prcp real,
|
prcp real,
|
||||||
|
|||||||
@@ -445,7 +445,7 @@
|
|||||||
join sequence. The planner preferentially considers joins between any
|
join sequence. The planner preferentially considers joins between any
|
||||||
two relations for which there exists a corresponding join clause in the
|
two relations for which there exists a corresponding join clause in the
|
||||||
<literal>WHERE</literal> qualification (i.e., for
|
<literal>WHERE</literal> qualification (i.e., for
|
||||||
which a restriction like <literal>where rel1.attr1=rel2.attr2</literal>
|
which a restriction like <literal>WHERE rel1.attr1 = rel2.attr2</literal>
|
||||||
exists). Join pairs with no join clause are considered only when there
|
exists). Join pairs with no join clause are considered only when there
|
||||||
is no other choice, that is, a particular relation has no available
|
is no other choice, that is, a particular relation has no available
|
||||||
join clauses to any other relation. All possible plans are generated for
|
join clauses to any other relation. All possible plans are generated for
|
||||||
|
|||||||
@@ -101,12 +101,12 @@ CREATE INDEX bloomidx ON tbloom USING bloom (i1,i2,i3)
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
=# CREATE TABLE tbloom AS
|
=# CREATE TABLE tbloom AS
|
||||||
SELECT
|
SELECT
|
||||||
(random() * 1000000)::int as i1,
|
(random() * 1000000)::int AS i1,
|
||||||
(random() * 1000000)::int as i2,
|
(random() * 1000000)::int AS i2,
|
||||||
(random() * 1000000)::int as i3,
|
(random() * 1000000)::int AS i3,
|
||||||
(random() * 1000000)::int as i4,
|
(random() * 1000000)::int AS i4,
|
||||||
(random() * 1000000)::int as i5,
|
(random() * 1000000)::int AS i5,
|
||||||
(random() * 1000000)::int as i6
|
(random() * 1000000)::int AS i6
|
||||||
FROM
|
FROM
|
||||||
generate_series(1,10000000);
|
generate_series(1,10000000);
|
||||||
SELECT 10000000
|
SELECT 10000000
|
||||||
|
|||||||
@@ -570,13 +570,13 @@ CREATE COLLATION
|
|||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
CREATE COLLATION mycollation5 (provider = icu, deterministic = false, locale = 'en-US-u-kn-ks-level2');
|
CREATE COLLATION mycollation5 (provider = icu, deterministic = false, locale = 'en-US-u-kn-ks-level2');
|
||||||
SELECT 'aB' = 'Ab' COLLATE mycollation5 as result;
|
SELECT 'aB' = 'Ab' COLLATE mycollation5 AS result;
|
||||||
result
|
result
|
||||||
--------
|
--------
|
||||||
t
|
t
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT 'N-45' < 'N-123' COLLATE mycollation5 as result;
|
SELECT 'N-45' < 'N-123' COLLATE mycollation5 AS result;
|
||||||
result
|
result
|
||||||
--------
|
--------
|
||||||
t
|
t
|
||||||
|
|||||||
@@ -6394,8 +6394,8 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
|
|||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE TABLE parent(key integer, ...);
|
CREATE TABLE parent(key integer, ...);
|
||||||
CREATE TABLE child1000(check (key between 1000 and 1999)) INHERITS(parent);
|
CREATE TABLE child1000(CHECK (key BETWEEN 1000 AND 1999)) INHERITS(parent);
|
||||||
CREATE TABLE child2000(check (key between 2000 and 2999)) INHERITS(parent);
|
CREATE TABLE child2000(CHECK (key BETWEEN 2000 AND 2999)) INHERITS(parent);
|
||||||
...
|
...
|
||||||
SELECT * FROM parent WHERE key = 2400;
|
SELECT * FROM parent WHERE key = 2400;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|||||||
@@ -249,7 +249,7 @@
|
|||||||
For example, the nearest neighbor of the 3-D point (0.5, 0.5, 0.5)
|
For example, the nearest neighbor of the 3-D point (0.5, 0.5, 0.5)
|
||||||
could be found efficiently with:
|
could be found efficiently with:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
SELECT c FROM test ORDER BY c <-> cube(array[0.5,0.5,0.5]) LIMIT 1;
|
SELECT c FROM test ORDER BY c <-> cube(ARRAY[0.5, 0.5, 0.5]) LIMIT 1;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@@ -540,7 +540,7 @@ SELECT c FROM test ORDER BY c ~> 3 DESC LIMIT 5;
|
|||||||
This union:
|
This union:
|
||||||
</para>
|
</para>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
select cube_union('(0,5,2),(2,3,1)', '0');
|
SELECT cube_union('(0,5,2),(2,3,1)', '0');
|
||||||
cube_union
|
cube_union
|
||||||
-------------------
|
-------------------
|
||||||
(0, 0, 0),(2, 5, 2)
|
(0, 0, 0),(2, 5, 2)
|
||||||
@@ -552,7 +552,7 @@ cube_union
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
select cube_inter('(0,-1),(1,1)', '(-2),(2)');
|
SELECT cube_inter('(0,-1),(1,1)', '(-2),(2)');
|
||||||
cube_inter
|
cube_inter
|
||||||
-------------
|
-------------
|
||||||
(0, 0),(1, 0)
|
(0, 0),(1, 0)
|
||||||
@@ -579,7 +579,7 @@ cube_inter('(0,-1),(1,1)','(-2,0),(2,0)');
|
|||||||
</para>
|
</para>
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
select cube_contains('(0,0),(1,1)', '0.5,0.5');
|
SELECT cube_contains('(0,0),(1,1)', '0.5,0.5');
|
||||||
cube_contains
|
cube_contains
|
||||||
--------------
|
--------------
|
||||||
t
|
t
|
||||||
|
|||||||
@@ -717,7 +717,7 @@ NUMERIC(3, 5)
|
|||||||
SELECT x,
|
SELECT x,
|
||||||
round(x::numeric) AS num_round,
|
round(x::numeric) AS num_round,
|
||||||
round(x::double precision) AS dbl_round
|
round(x::double precision) AS dbl_round
|
||||||
FROM generate_series(-3.5, 3.5, 1) as x;
|
FROM generate_series(-3.5, 3.5, 1) AS x;
|
||||||
x | num_round | dbl_round
|
x | num_round | dbl_round
|
||||||
------+-----------+-----------
|
------+-----------+-----------
|
||||||
-3.5 | -4 | -4
|
-3.5 | -4 | -4
|
||||||
@@ -1259,7 +1259,7 @@ SELECT '52093.89'::money::numeric::float8;
|
|||||||
semantically insignificant and disregarded when comparing two values
|
semantically insignificant and disregarded when comparing two values
|
||||||
of type <type>character</type>. In collations where whitespace
|
of type <type>character</type>. In collations where whitespace
|
||||||
is significant, this behavior can produce unexpected results;
|
is significant, this behavior can produce unexpected results;
|
||||||
for example <command>SELECT 'a '::CHAR(2) collate "C" <
|
for example <command>SELECT 'a '::CHAR(2) COLLATE "C" <
|
||||||
E'a\n'::CHAR(2)</command> returns true, even though <literal>C</literal>
|
E'a\n'::CHAR(2)</command> returns true, even though <literal>C</literal>
|
||||||
locale would consider a space to be greater than a newline.
|
locale would consider a space to be greater than a newline.
|
||||||
Trailing spaces are removed when converting a <type>character</type> value
|
Trailing spaces are removed when converting a <type>character</type> value
|
||||||
|
|||||||
@@ -942,17 +942,17 @@ $ <userinput>cal 9 1752</userinput>
|
|||||||
definition when you need it: do the arithmetic in time
|
definition when you need it: do the arithmetic in time
|
||||||
zone <literal>UTC+12</literal>. For example,
|
zone <literal>UTC+12</literal>. For example,
|
||||||
<programlisting>
|
<programlisting>
|
||||||
=> SELECT extract(julian from '2021-06-23 7:00:00-04'::timestamptz at time zone 'UTC+12');
|
=> SELECT extract(julian FROM '2021-06-23 7:00:00-04'::timestamptz AT TIME ZONE 'UTC+12');
|
||||||
extract
|
extract
|
||||||
------------------------------
|
------------------------------
|
||||||
2459388.95833333333333333333
|
2459388.95833333333333333333
|
||||||
(1 row)
|
(1 row)
|
||||||
=> SELECT extract(julian from '2021-06-23 8:00:00-04'::timestamptz at time zone 'UTC+12');
|
=> SELECT extract(julian FROM '2021-06-23 8:00:00-04'::timestamptz AT TIME ZONE 'UTC+12');
|
||||||
extract
|
extract
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
2459389.0000000000000000000000000000
|
2459389.0000000000000000000000000000
|
||||||
(1 row)
|
(1 row)
|
||||||
=> SELECT extract(julian from date '2021-06-23');
|
=> SELECT extract(julian FROM date '2021-06-23');
|
||||||
extract
|
extract
|
||||||
---------
|
---------
|
||||||
2459389
|
2459389
|
||||||
|
|||||||
@@ -444,7 +444,7 @@ dblink(text sql [, bool fail_on_error]) returns setof record
|
|||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
The SQL query that you wish to execute in the remote database,
|
The SQL query that you wish to execute in the remote database,
|
||||||
for example <literal>select * from foo</literal>.
|
for example <literal>SELECT * FROM foo</literal>.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@@ -478,7 +478,7 @@ dblink(text sql [, bool fail_on_error]) returns setof record
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM dblink('dbname=mydb options=-csearch_path=',
|
FROM dblink('dbname=mydb options=-csearch_path=',
|
||||||
'select proname, prosrc from pg_proc')
|
'SELECT proname, prosrc FROM pg_proc')
|
||||||
AS t1(proname name, prosrc text)
|
AS t1(proname name, prosrc text)
|
||||||
WHERE proname LIKE 'bytea%';
|
WHERE proname LIKE 'bytea%';
|
||||||
</programlisting>
|
</programlisting>
|
||||||
@@ -513,7 +513,7 @@ SELECT *
|
|||||||
CREATE VIEW myremote_pg_proc AS
|
CREATE VIEW myremote_pg_proc AS
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM dblink('dbname=postgres options=-csearch_path=',
|
FROM dblink('dbname=postgres options=-csearch_path=',
|
||||||
'select proname, prosrc from pg_proc')
|
'SELECT proname, prosrc FROM pg_proc')
|
||||||
AS t1(proname name, prosrc text);
|
AS t1(proname name, prosrc text);
|
||||||
|
|
||||||
SELECT * FROM myremote_pg_proc WHERE proname LIKE 'bytea%';
|
SELECT * FROM myremote_pg_proc WHERE proname LIKE 'bytea%';
|
||||||
@@ -525,7 +525,7 @@ SELECT * FROM myremote_pg_proc WHERE proname LIKE 'bytea%';
|
|||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
SELECT * FROM dblink('dbname=postgres options=-csearch_path=',
|
SELECT * FROM dblink('dbname=postgres options=-csearch_path=',
|
||||||
'select proname, prosrc from pg_proc')
|
'SELECT proname, prosrc FROM pg_proc')
|
||||||
AS t1(proname name, prosrc text) WHERE proname LIKE 'bytea%';
|
AS t1(proname name, prosrc text) WHERE proname LIKE 'bytea%';
|
||||||
proname | prosrc
|
proname | prosrc
|
||||||
------------+------------
|
------------+------------
|
||||||
@@ -549,7 +549,7 @@ SELECT dblink_connect('dbname=postgres options=-csearch_path=');
|
|||||||
OK
|
OK
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT * FROM dblink('select proname, prosrc from pg_proc')
|
SELECT * FROM dblink('SELECT proname, prosrc FROM pg_proc')
|
||||||
AS t1(proname name, prosrc text) WHERE proname LIKE 'bytea%';
|
AS t1(proname name, prosrc text) WHERE proname LIKE 'bytea%';
|
||||||
proname | prosrc
|
proname | prosrc
|
||||||
------------+------------
|
------------+------------
|
||||||
@@ -573,7 +573,7 @@ SELECT dblink_connect('myconn', 'dbname=regression options=-csearch_path=');
|
|||||||
OK
|
OK
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT * FROM dblink('myconn', 'select proname, prosrc from pg_proc')
|
SELECT * FROM dblink('myconn', 'SELECT proname, prosrc FROM pg_proc')
|
||||||
AS t1(proname name, prosrc text) WHERE proname LIKE 'bytea%';
|
AS t1(proname name, prosrc text) WHERE proname LIKE 'bytea%';
|
||||||
proname | prosrc
|
proname | prosrc
|
||||||
------------+------------
|
------------+------------
|
||||||
@@ -666,7 +666,7 @@ dblink_exec(text sql [, bool fail_on_error]) returns text
|
|||||||
<para>
|
<para>
|
||||||
The SQL command that you wish to execute in the remote database,
|
The SQL command that you wish to execute in the remote database,
|
||||||
for example
|
for example
|
||||||
<literal>insert into foo values(0, 'a', '{"a0","b0","c0"}')</literal>.
|
<literal>INSERT INTO foo VALUES (0, 'a', '{"a0","b0","c0"}')</literal>.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@@ -793,7 +793,7 @@ dblink_open(text connname, text cursorname, text sql [, bool fail_on_error]) ret
|
|||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
The <command>SELECT</command> statement that you wish to execute in the remote
|
The <command>SELECT</command> statement that you wish to execute in the remote
|
||||||
database, for example <literal>select * from pg_class</literal>.
|
database, for example <literal>SELECT * FROM pg_class</literal>.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@@ -848,7 +848,7 @@ SELECT dblink_connect('dbname=postgres options=-csearch_path=');
|
|||||||
OK
|
OK
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT dblink_open('foo', 'select proname, prosrc from pg_proc');
|
SELECT dblink_open('foo', 'SELECT proname, prosrc FROM pg_proc');
|
||||||
dblink_open
|
dblink_open
|
||||||
-------------
|
-------------
|
||||||
OK
|
OK
|
||||||
@@ -969,7 +969,7 @@ SELECT dblink_connect('dbname=postgres options=-csearch_path=');
|
|||||||
OK
|
OK
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT dblink_open('foo', 'select proname, prosrc from pg_proc where proname like ''bytea%''');
|
SELECT dblink_open('foo', 'SELECT proname, prosrc FROM pg_proc WHERE proname LIKE ''bytea%''');
|
||||||
dblink_open
|
dblink_open
|
||||||
-------------
|
-------------
|
||||||
OK
|
OK
|
||||||
@@ -1106,7 +1106,7 @@ SELECT dblink_connect('dbname=postgres options=-csearch_path=');
|
|||||||
OK
|
OK
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
SELECT dblink_open('foo', 'select proname, prosrc from pg_proc');
|
SELECT dblink_open('foo', 'SELECT proname, prosrc FROM pg_proc');
|
||||||
dblink_open
|
dblink_open
|
||||||
-------------
|
-------------
|
||||||
OK
|
OK
|
||||||
@@ -1301,7 +1301,7 @@ dblink_send_query(text connname, text sql) returns int
|
|||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
The SQL statement that you wish to execute in the remote database,
|
The SQL statement that you wish to execute in the remote database,
|
||||||
for example <literal>select * from pg_class</literal>.
|
for example <literal>SELECT * FROM pg_class</literal>.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
@@ -1583,7 +1583,7 @@ contrib_regression=# SELECT dblink_connect('dtest1', 'dbname=contrib_regression'
|
|||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
contrib_regression=# SELECT * FROM
|
contrib_regression=# SELECT * FROM
|
||||||
contrib_regression-# dblink_send_query('dtest1', 'select * from foo where f1 < 3') AS t1;
|
contrib_regression-# dblink_send_query('dtest1', 'SELECT * FROM foo WHERE f1 < 3') AS t1;
|
||||||
t1
|
t1
|
||||||
----
|
----
|
||||||
1
|
1
|
||||||
@@ -1603,7 +1603,7 @@ contrib_regression=# SELECT * FROM dblink_get_result('dtest1') AS t1(f1 int, f2
|
|||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
contrib_regression=# SELECT * FROM
|
contrib_regression=# SELECT * FROM
|
||||||
contrib_regression-# dblink_send_query('dtest1', 'select * from foo where f1 < 3; select * from foo where f1 > 6') AS t1;
|
contrib_regression-# dblink_send_query('dtest1', 'SELECT * FROM foo WHERE f1 < 3; SELECT * FROM foo WHERE f1 > 6') AS t1;
|
||||||
t1
|
t1
|
||||||
----
|
----
|
||||||
1
|
1
|
||||||
|
|||||||
@@ -3126,9 +3126,9 @@ GRANT UPDATE
|
|||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
-- admin can view all rows and fields
|
-- admin can view all rows and fields
|
||||||
postgres=> set role admin;
|
postgres=> SET ROLE admin;
|
||||||
SET
|
SET
|
||||||
postgres=> table passwd;
|
postgres=> TABLE passwd;
|
||||||
user_name | pwhash | uid | gid | real_name | home_phone | extra_info | home_dir | shell
|
user_name | pwhash | uid | gid | real_name | home_phone | extra_info | home_dir | shell
|
||||||
-----------+--------+-----+-----+-----------+--------------+------------+-------------+-----------
|
-----------+--------+-----+-----+-----------+--------------+------------+-------------+-----------
|
||||||
admin | xxx | 0 | 0 | Admin | 111-222-3333 | | /root | /bin/dash
|
admin | xxx | 0 | 0 | Admin | 111-222-3333 | | /root | /bin/dash
|
||||||
@@ -3137,11 +3137,11 @@ postgres=> table passwd;
|
|||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
-- Test what Alice is able to do
|
-- Test what Alice is able to do
|
||||||
postgres=> set role alice;
|
postgres=> SET ROLE alice;
|
||||||
SET
|
SET
|
||||||
postgres=> table passwd;
|
postgres=> TABLE passwd;
|
||||||
ERROR: permission denied for table passwd
|
ERROR: permission denied for table passwd
|
||||||
postgres=> select user_name,real_name,home_phone,extra_info,home_dir,shell from passwd;
|
postgres=> SELECT user_name, real_name, home_phone, extra_info, home_dir, shell FROM passwd;
|
||||||
user_name | real_name | home_phone | extra_info | home_dir | shell
|
user_name | real_name | home_phone | extra_info | home_dir | shell
|
||||||
-----------+-----------+--------------+------------+-------------+-----------
|
-----------+-----------+--------------+------------+-------------+-----------
|
||||||
admin | Admin | 111-222-3333 | | /root | /bin/dash
|
admin | Admin | 111-222-3333 | | /root | /bin/dash
|
||||||
@@ -3149,21 +3149,21 @@ postgres=> select user_name,real_name,home_phone,extra_info,home_dir,shell fr
|
|||||||
alice | Alice | 098-765-4321 | | /home/alice | /bin/zsh
|
alice | Alice | 098-765-4321 | | /home/alice | /bin/zsh
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
postgres=> update passwd set user_name = 'joe';
|
postgres=> UPDATE passwd SET user_name = 'joe';
|
||||||
ERROR: permission denied for table passwd
|
ERROR: permission denied for table passwd
|
||||||
-- Alice is allowed to change her own real_name, but no others
|
-- Alice is allowed to change her own real_name, but no others
|
||||||
postgres=> update passwd set real_name = 'Alice Doe';
|
postgres=> UPDATE passwd SET real_name = 'Alice Doe';
|
||||||
UPDATE 1
|
UPDATE 1
|
||||||
postgres=> update passwd set real_name = 'John Doe' where user_name = 'admin';
|
postgres=> UPDATE passwd SET real_name = 'John Doe' WHERE user_name = 'admin';
|
||||||
UPDATE 0
|
UPDATE 0
|
||||||
postgres=> update passwd set shell = '/bin/xx';
|
postgres=> UPDATE passwd SET shell = '/bin/xx';
|
||||||
ERROR: new row violates WITH CHECK OPTION for "passwd"
|
ERROR: new row violates WITH CHECK OPTION for "passwd"
|
||||||
postgres=> delete from passwd;
|
postgres=> DELETE FROM passwd;
|
||||||
ERROR: permission denied for table passwd
|
ERROR: permission denied for table passwd
|
||||||
postgres=> insert into passwd (user_name) values ('xxx');
|
postgres=> INSERT INTO passwd (user_name) VALUES ('xxx');
|
||||||
ERROR: permission denied for table passwd
|
ERROR: permission denied for table passwd
|
||||||
-- Alice can change her own password; RLS silently prevents updating other rows
|
-- Alice can change her own password; RLS silently prevents updating other rows
|
||||||
postgres=> update passwd set pwhash = 'abc';
|
postgres=> UPDATE passwd SET pwhash = 'abc';
|
||||||
UPDATE 1
|
UPDATE 1
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|
||||||
@@ -3196,7 +3196,7 @@ CREATE POLICY admin_local_only ON passwd AS RESTRICTIVE TO admin
|
|||||||
admin
|
admin
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
=> select inet_client_addr();
|
=> SELECT inet_client_addr();
|
||||||
inet_client_addr
|
inet_client_addr
|
||||||
------------------
|
------------------
|
||||||
127.0.0.1
|
127.0.0.1
|
||||||
@@ -3207,7 +3207,7 @@ CREATE POLICY admin_local_only ON passwd AS RESTRICTIVE TO admin
|
|||||||
-----------+--------+-----+-----+-----------+------------+------------+----------+-------
|
-----------+--------+-----+-----+-----------+------------+------------+----------+-------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
=> UPDATE passwd set pwhash = NULL;
|
=> UPDATE passwd SET pwhash = NULL;
|
||||||
UPDATE 0
|
UPDATE 0
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ ALTER TEXT SEARCH DICTIONARY
|
|||||||
To test the dictionary, you can try
|
To test the dictionary, you can try
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
mydb# select ts_lexize('intdict', '12345678');
|
mydb# SELECT ts_lexize('intdict', '12345678');
|
||||||
ts_lexize
|
ts_lexize
|
||||||
-----------
|
-----------
|
||||||
{123456}
|
{123456}
|
||||||
|
|||||||
@@ -317,7 +317,7 @@ DELETE FROM products;
|
|||||||
column to provide unique identifiers, <literal>RETURNING</literal> can return
|
column to provide unique identifiers, <literal>RETURNING</literal> can return
|
||||||
the ID assigned to a new row:
|
the ID assigned to a new row:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE TABLE users (firstname text, lastname text, id serial primary key);
|
CREATE TABLE users (firstname text, lastname text, id serial PRIMARY KEY);
|
||||||
|
|
||||||
INSERT INTO users (firstname, lastname) VALUES ('Joe', 'Cool') RETURNING id;
|
INSERT INTO users (firstname, lastname) VALUES ('Joe', 'Cool') RETURNING id;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|||||||
@@ -2042,7 +2042,7 @@ EXEC SQL EXECUTE mystmt INTO :v1, :v2, :v3 USING 37;
|
|||||||
EXEC SQL BEGIN DECLARE SECTION;
|
EXEC SQL BEGIN DECLARE SECTION;
|
||||||
char dbaname[128];
|
char dbaname[128];
|
||||||
char datname[128];
|
char datname[128];
|
||||||
char *stmt = "SELECT u.usename as dbaname, d.datname "
|
char *stmt = "SELECT u.usename AS dbaname, d.datname "
|
||||||
" FROM pg_database d, pg_user u "
|
" FROM pg_database d, pg_user u "
|
||||||
" WHERE d.datdba = u.usesysid";
|
" WHERE d.datdba = u.usesysid";
|
||||||
EXEC SQL END DECLARE SECTION;
|
EXEC SQL END DECLARE SECTION;
|
||||||
@@ -6685,7 +6685,7 @@ EXEC SQL CONNECT TO 'unix:postgresql://localhost/connectdb' AS main USER :user;
|
|||||||
EXEC SQL CONNECT TO :db AS :id;
|
EXEC SQL CONNECT TO :db AS :id;
|
||||||
EXEC SQL CONNECT TO :db USER connectuser USING :pw;
|
EXEC SQL CONNECT TO :db USER connectuser USING :pw;
|
||||||
EXEC SQL CONNECT TO @localhost AS main USER connectdb;
|
EXEC SQL CONNECT TO @localhost AS main USER connectdb;
|
||||||
EXEC SQL CONNECT TO REGRESSDB1 as main;
|
EXEC SQL CONNECT TO REGRESSDB1 AS main;
|
||||||
EXEC SQL CONNECT TO AS main USER connectdb;
|
EXEC SQL CONNECT TO AS main USER connectdb;
|
||||||
EXEC SQL CONNECT TO connectdb AS :id;
|
EXEC SQL CONNECT TO connectdb AS :id;
|
||||||
EXEC SQL CONNECT TO connectdb AS main USER connectuser/connectdb;
|
EXEC SQL CONNECT TO connectdb AS main USER connectuser/connectdb;
|
||||||
|
|||||||
@@ -433,7 +433,7 @@ $$
|
|||||||
---
|
---
|
||||||
DECLARE
|
DECLARE
|
||||||
table_oid oid := pg_event_trigger_table_rewrite_oid();
|
table_oid oid := pg_event_trigger_table_rewrite_oid();
|
||||||
current_hour integer := extract('hour' from current_time);
|
current_hour integer := extract('hour' FROM current_time);
|
||||||
pages integer;
|
pages integer;
|
||||||
max_pages integer := 100;
|
max_pages integer := 100;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|||||||
@@ -624,7 +624,7 @@
|
|||||||
in a query's FROM clause; see <xref linkend="queries-tablefunctions"/>.
|
in a query's FROM clause; see <xref linkend="queries-tablefunctions"/>.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>select * from unnest(ARRAY[1,2], ARRAY['foo','bar','baz']) as x(a,b)</literal>
|
<literal>SELECT * FROM unnest(ARRAY[1, 2], ARRAY['foo', 'bar', 'baz']) AS x(a, b)</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
a | b
|
a | b
|
||||||
|
|||||||
@@ -151,7 +151,7 @@
|
|||||||
of <parameter>newsubstring</parameter>.
|
of <parameter>newsubstring</parameter>.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>overlay('\x1234567890'::bytea placing '\002\003'::bytea from 2 for 3)</literal>
|
<literal>overlay('\x1234567890'::bytea PLACING '\002\003'::bytea FROM 2 FOR 3)</literal>
|
||||||
<returnvalue>\x12020390</returnvalue>
|
<returnvalue>\x12020390</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
@@ -170,7 +170,7 @@
|
|||||||
<parameter>bytes</parameter>, or zero if it's not present.
|
<parameter>bytes</parameter>, or zero if it's not present.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>position('\x5678'::bytea in '\x1234567890'::bytea)</literal>
|
<literal>position('\x5678'::bytea IN '\x1234567890'::bytea)</literal>
|
||||||
<returnvalue>3</returnvalue>
|
<returnvalue>3</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
@@ -211,7 +211,7 @@
|
|||||||
and <parameter>count</parameter>.
|
and <parameter>count</parameter>.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>substring('\x1234567890'::bytea from 3 for 2)</literal>
|
<literal>substring('\x1234567890'::bytea FROM 3 FOR 2)</literal>
|
||||||
<returnvalue>\x5678</returnvalue>
|
<returnvalue>\x5678</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
@@ -856,8 +856,8 @@
|
|||||||
significant byte first. Some examples:
|
significant byte first. Some examples:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
1234::smallint::bytea <lineannotation>\x04d2</lineannotation>
|
1234::smallint::bytea <lineannotation>\x04d2</lineannotation>
|
||||||
cast(1234 as bytea) <lineannotation>\x000004d2</lineannotation>
|
cast(1234 AS bytea) <lineannotation>\x000004d2</lineannotation>
|
||||||
cast(-1234 as bytea) <lineannotation>\xfffffb2e</lineannotation>
|
cast(-1234 AS bytea) <lineannotation>\xfffffb2e</lineannotation>
|
||||||
'\x8000'::bytea::smallint <lineannotation>-32768</lineannotation>
|
'\x8000'::bytea::smallint <lineannotation>-32768</lineannotation>
|
||||||
'\x8000'::bytea::integer <lineannotation>32768</lineannotation>
|
'\x8000'::bytea::integer <lineannotation>32768</lineannotation>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|||||||
@@ -251,7 +251,7 @@
|
|||||||
of <parameter>newsubstring</parameter>.
|
of <parameter>newsubstring</parameter>.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>overlay(B'01010101010101010' placing B'11111' from 2 for 3)</literal>
|
<literal>overlay(B'01010101010101010' PLACING B'11111' FROM 2 FOR 3)</literal>
|
||||||
<returnvalue>0111110101010101010</returnvalue>
|
<returnvalue>0111110101010101010</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
@@ -269,7 +269,7 @@
|
|||||||
within <parameter>bits</parameter>, or zero if it's not present.
|
within <parameter>bits</parameter>, or zero if it's not present.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>position(B'010' in B'000001101011')</literal>
|
<literal>position(B'010' IN B'000001101011')</literal>
|
||||||
<returnvalue>8</returnvalue>
|
<returnvalue>8</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
@@ -290,7 +290,7 @@
|
|||||||
and <parameter>count</parameter>.
|
and <parameter>count</parameter>.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>substring(B'110010111111' from 3 for 2)</literal>
|
<literal>substring(B'110010111111' FROM 3 FOR 2)</literal>
|
||||||
<returnvalue>00</returnvalue>
|
<returnvalue>00</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
@@ -348,7 +348,7 @@
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
44::bit(10) <lineannotation>0000101100</lineannotation>
|
44::bit(10) <lineannotation>0000101100</lineannotation>
|
||||||
44::bit(3) <lineannotation>100</lineannotation>
|
44::bit(3) <lineannotation>100</lineannotation>
|
||||||
cast(-44 as bit(12)) <lineannotation>111111010100</lineannotation>
|
cast(-44 AS bit(12)) <lineannotation>111111010100</lineannotation>
|
||||||
'1110'::bit(4)::integer <lineannotation>14</lineannotation>
|
'1110'::bit(4)::integer <lineannotation>14</lineannotation>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
Note that casting to just <quote>bit</quote> means casting to
|
Note that casting to just <quote>bit</quote> means casting to
|
||||||
|
|||||||
@@ -602,28 +602,28 @@
|
|||||||
<indexterm>
|
<indexterm>
|
||||||
<primary>extract</primary>
|
<primary>extract</primary>
|
||||||
</indexterm>
|
</indexterm>
|
||||||
<function>extract</function> ( <parameter>field</parameter> <literal>from</literal> <type>timestamp</type> )
|
<function>extract</function> ( <parameter>field</parameter> <literal>FROM</literal> <type>timestamp</type> )
|
||||||
<returnvalue>numeric</returnvalue>
|
<returnvalue>numeric</returnvalue>
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
Get timestamp subfield; see <xref linkend="functions-datetime-extract"/>
|
Get timestamp subfield; see <xref linkend="functions-datetime-extract"/>
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>extract(hour from timestamp '2001-02-16 20:38:40')</literal>
|
<literal>extract(hour FROM timestamp '2001-02-16 20:38:40')</literal>
|
||||||
<returnvalue>20</returnvalue>
|
<returnvalue>20</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
|
|
||||||
<row>
|
<row>
|
||||||
<entry role="func_table_entry"><para role="func_signature">
|
<entry role="func_table_entry"><para role="func_signature">
|
||||||
<function>extract</function> ( <parameter>field</parameter> <literal>from</literal> <type>interval</type> )
|
<function>extract</function> ( <parameter>field</parameter> <literal>FROM</literal> <type>interval</type> )
|
||||||
<returnvalue>numeric</returnvalue>
|
<returnvalue>numeric</returnvalue>
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
Get interval subfield; see <xref linkend="functions-datetime-extract"/>
|
Get interval subfield; see <xref linkend="functions-datetime-extract"/>
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>extract(month from interval '2 years 3 months')</literal>
|
<literal>extract(month FROM interval '2 years 3 months')</literal>
|
||||||
<returnvalue>3</returnvalue>
|
<returnvalue>3</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
@@ -1849,7 +1849,7 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
|
|||||||
value is in the named time zone.
|
value is in the named time zone.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>timestamp '2001-02-16 20:38:40' at time zone 'America/Denver'</literal>
|
<literal>timestamp '2001-02-16 20:38:40' AT TIME ZONE 'America/Denver'</literal>
|
||||||
<returnvalue>2001-02-17 03:38:40+00</returnvalue>
|
<returnvalue>2001-02-17 03:38:40+00</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
@@ -1881,7 +1881,7 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
|
|||||||
appear in that zone.
|
appear in that zone.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>timestamp with time zone '2001-02-16 20:38:40-05' at time zone 'America/Denver'</literal>
|
<literal>timestamp with time zone '2001-02-16 20:38:40-05' AT TIME ZONE 'America/Denver'</literal>
|
||||||
<returnvalue>2001-02-16 18:38:40</returnvalue>
|
<returnvalue>2001-02-16 18:38:40</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
@@ -1913,7 +1913,7 @@ SELECT date_bin('15 minutes', TIMESTAMP '2020-02-11 15:44:17', TIMESTAMP '2001-0
|
|||||||
offset for the named destination zone.
|
offset for the named destination zone.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>time with time zone '05:34:17-05' at time zone 'UTC'</literal>
|
<literal>time with time zone '05:34:17-05' AT TIME ZONE 'UTC'</literal>
|
||||||
<returnvalue>10:34:17+00</returnvalue>
|
<returnvalue>10:34:17+00</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
|
|||||||
@@ -748,9 +748,9 @@
|
|||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<function>to_char(..., 'ID')</function>'s day of the week numbering
|
<function>to_char(..., 'ID')</function>'s day of the week numbering
|
||||||
matches the <function>extract(isodow from ...)</function> function, but
|
matches the <function>extract(isodow FROM ...)</function> function, but
|
||||||
<function>to_char(..., 'D')</function>'s does not match
|
<function>to_char(..., 'D')</function>'s does not match
|
||||||
<function>extract(dow from ...)</function>'s day numbering.
|
<function>extract(dow FROM ...)</function>'s day numbering.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
|
|
||||||
|
|||||||
@@ -1962,11 +1962,11 @@ SELECT currval(pg_get_serial_sequence('sometable', 'id'));
|
|||||||
collatable data type, then an error is raised.
|
collatable data type, then an error is raised.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>collation for ('foo'::text)</literal>
|
<literal>COLLATION FOR ('foo'::text)</literal>
|
||||||
<returnvalue>"default"</returnvalue>
|
<returnvalue>"default"</returnvalue>
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>collation for ('foo' COLLATE "de_DE")</literal>
|
<literal>COLLATION FOR ('foo' COLLATE "de_DE")</literal>
|
||||||
<returnvalue>"de_DE"</returnvalue>
|
<returnvalue>"de_DE"</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
|
|||||||
@@ -981,7 +981,7 @@ array w/o UK? | t
|
|||||||
Expands the top-level JSON array into a set of JSON values.
|
Expands the top-level JSON array into a set of JSON values.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>select * from json_array_elements('[1,true, [2,false]]')</literal>
|
<literal>SELECT * FROM json_array_elements('[1,true, [2,false]]')</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
value
|
value
|
||||||
@@ -1012,7 +1012,7 @@ array w/o UK? | t
|
|||||||
Expands the top-level JSON array into a set of <type>text</type> values.
|
Expands the top-level JSON array into a set of <type>text</type> values.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>select * from json_array_elements_text('["foo", "bar"]')</literal>
|
<literal>SELECT * FROM json_array_elements_text('["foo", "bar"]')</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
value
|
value
|
||||||
@@ -1074,7 +1074,7 @@ array w/o UK? | t
|
|||||||
Expands the top-level JSON object into a set of key/value pairs.
|
Expands the top-level JSON object into a set of key/value pairs.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>select * from json_each('{"a":"foo", "b":"bar"}')</literal>
|
<literal>SELECT * FROM json_each('{"a":"foo", "b":"bar"}')</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
key | value
|
key | value
|
||||||
@@ -1110,7 +1110,7 @@ array w/o UK? | t
|
|||||||
type <type>text</type>.
|
type <type>text</type>.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>select * from json_each_text('{"a":"foo", "b":"bar"}')</literal>
|
<literal>SELECT * FROM json_each_text('{"a":"foo", "b":"bar"}')</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
key | value
|
key | value
|
||||||
@@ -1193,7 +1193,7 @@ array w/o UK? | t
|
|||||||
Returns the set of keys in the top-level JSON object.
|
Returns the set of keys in the top-level JSON object.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>select * from json_object_keys('{"f1":"abc","f2":{"f3":"a", "f4":"b"}}')</literal>
|
<literal>SELECT * FROM json_object_keys('{"f1":"abc","f2":{"f3":"a", "f4":"b"}}')</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
json_object_keys
|
json_object_keys
|
||||||
@@ -1286,11 +1286,11 @@ array w/o UK? | t
|
|||||||
calls.
|
calls.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>create type subrowtype as (d int, e text);</literal>
|
<literal>CREATE TYPE subrowtype AS (d int, e text);</literal>
|
||||||
<literal>create type myrowtype as (a int, b text[], c subrowtype);</literal>
|
<literal>CREATE TYPE myrowtype AS (a int, b text[], c subrowtype);</literal>
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>select * from json_populate_record(null::myrowtype,
|
<literal>SELECT * FROM json_populate_record(NULL::myrowtype,
|
||||||
'{"a": 1, "b": ["2", "a b"], "c": {"d": 4, "e": "a b c"}, "x": "foo"}')</literal>
|
'{"a": 1, "b": ["2", "a b"], "c": {"d": 4, "e": "a b c"}, "x": "foo"}')</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
@@ -1316,10 +1316,10 @@ array w/o UK? | t
|
|||||||
valid input, <literal>false</literal> otherwise.
|
valid input, <literal>false</literal> otherwise.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>create type jsb_char2 as (a char(2));</literal>
|
<literal>CREATE TYPE jsb_char2 AS (a char(2));</literal>
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>select jsonb_populate_record_valid(NULL::jsb_char2, '{"a": "aaa"}');</literal>
|
<literal>SELECT jsonb_populate_record_valid(NULL::jsb_char2, '{"a": "aaa"}');</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
jsonb_populate_record_valid
|
jsonb_populate_record_valid
|
||||||
@@ -1328,12 +1328,12 @@ array w/o UK? | t
|
|||||||
(1 row)
|
(1 row)
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|
||||||
<literal>select * from jsonb_populate_record(NULL::jsb_char2, '{"a": "aaa"}') q;</literal>
|
<literal>SELECT * FROM jsonb_populate_record(NULL::jsb_char2, '{"a": "aaa"}') q;</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
ERROR: value too long for type character(2)
|
ERROR: value too long for type character(2)
|
||||||
</programlisting>
|
</programlisting>
|
||||||
<literal>select jsonb_populate_record_valid(NULL::jsb_char2, '{"a": "aa"}');</literal>
|
<literal>SELECT jsonb_populate_record_valid(NULL::jsb_char2, '{"a": "aa"}');</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
jsonb_populate_record_valid
|
jsonb_populate_record_valid
|
||||||
@@ -1342,7 +1342,7 @@ ERROR: value too long for type character(2)
|
|||||||
(1 row)
|
(1 row)
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|
||||||
<literal>select * from jsonb_populate_record(NULL::jsb_char2, '{"a": "aa"}') q;</literal>
|
<literal>SELECT * FROM jsonb_populate_record(NULL::jsb_char2, '{"a": "aa"}') q;</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
a
|
a
|
||||||
@@ -1375,10 +1375,10 @@ ERROR: value too long for type character(2)
|
|||||||
for <function>json[b]_populate_record</function>.
|
for <function>json[b]_populate_record</function>.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>create type twoints as (a int, b int);</literal>
|
<literal>CREATE TYPE twoints AS (a int, b int);</literal>
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>select * from json_populate_recordset(null::twoints, '[{"a":1,"b":2}, {"a":3,"b":4}]')</literal>
|
<literal>SELECT * FROM json_populate_recordset(NULL::twoints, '[{"a":1,"b":2}, {"a":3,"b":4}]')</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
a | b
|
a | b
|
||||||
@@ -1415,10 +1415,10 @@ ERROR: value too long for type character(2)
|
|||||||
input record value, unmatched columns are always filled with nulls.
|
input record value, unmatched columns are always filled with nulls.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>create type myrowtype as (a int, b text);</literal>
|
<literal>CREATE TYPE myrowtype AS (a int, b text);</literal>
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>select * from json_to_record('{"a":1,"b":[1,2,3],"c":[1,2,3],"e":"bar","r": {"a": 123, "b": "a b c"}}') as x(a int, b text, c int[], d text, r myrowtype)</literal>
|
<literal>SELECT * FROM json_to_record('{"a":1,"b":[1,2,3],"c":[1,2,3],"e":"bar","r": {"a": 123, "b": "a b c"}}') AS x(a int, b text, c int[], d text, r myrowtype)</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
a | b | c | d | r
|
a | b | c | d | r
|
||||||
@@ -1453,7 +1453,7 @@ ERROR: value too long for type character(2)
|
|||||||
for <function>json[b]_populate_record</function>.
|
for <function>json[b]_populate_record</function>.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>select * from json_to_recordset('[{"a":1,"b":"foo"}, {"a":"2","c":"bar"}]') as x(a int, b text)</literal>
|
<literal>SELECT * FROM json_to_recordset('[{"a":1,"b":"foo"}, {"a":"2","c":"bar"}]') AS x(a int, b text)</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
a | b
|
a | b
|
||||||
@@ -1674,7 +1674,7 @@ ERROR: value too long for type character(2)
|
|||||||
for <function>jsonb_path_exists</function>.
|
for <function>jsonb_path_exists</function>.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>select * from jsonb_path_query('{"a":[1,2,3,4,5]}', '$.a[*] ? (@ >= $min && @ <= $max)', '{"min":2, "max":4}')</literal>
|
<literal>SELECT * FROM jsonb_path_query('{"a":[1,2,3,4,5]}', '$.a[*] ? (@ >= $min && @ <= $max)', '{"min":2, "max":4}')</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
@@ -1932,7 +1932,7 @@ SELECT '{
|
|||||||
<literal>.<replaceable>key</replaceable></literal> accessor
|
<literal>.<replaceable>key</replaceable></literal> accessor
|
||||||
operator to descend through surrounding JSON objects, for example:
|
operator to descend through surrounding JSON objects, for example:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', '$.track.segments');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', '$.track.segments');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
-----------------------------------------------------------&zwsp;-----------------------------------------------------------&zwsp;---------------------------------------------
|
-----------------------------------------------------------&zwsp;-----------------------------------------------------------&zwsp;---------------------------------------------
|
||||||
[{"HR": 73, "location": [47.763, 13.4034], "start time": "2018-10-14 10:05:14"}, {"HR": 135, "location": [47.706, 13.2635], "start time": "2018-10-14 10:39:21"}]
|
[{"HR": 73, "location": [47.763, 13.4034], "start time": "2018-10-14 10:05:14"}, {"HR": 135, "location": [47.706, 13.2635], "start time": "2018-10-14 10:39:21"}]
|
||||||
@@ -1945,7 +1945,7 @@ SELECT '{
|
|||||||
The following example will return the location coordinates for all
|
The following example will return the location coordinates for all
|
||||||
the available track segments:
|
the available track segments:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', '$.track.segments[*].location');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', '$.track.segments[*].location');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
-------------------
|
-------------------
|
||||||
[47.763, 13.4034]
|
[47.763, 13.4034]
|
||||||
@@ -1971,7 +1971,7 @@ SELECT '{
|
|||||||
specify the corresponding subscript in the <literal>[]</literal>
|
specify the corresponding subscript in the <literal>[]</literal>
|
||||||
accessor operator. Recall that JSON array indexes are 0-relative:
|
accessor operator. Recall that JSON array indexes are 0-relative:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', '$.track.segments[0].location');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', '$.track.segments[0].location');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
-------------------
|
-------------------
|
||||||
[47.763, 13.4034]
|
[47.763, 13.4034]
|
||||||
@@ -1985,7 +1985,7 @@ SELECT '{
|
|||||||
Each method name must be preceded by a dot. For example,
|
Each method name must be preceded by a dot. For example,
|
||||||
you can get the size of an array:
|
you can get the size of an array:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', '$.track.segments.size()');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', '$.track.segments.size()');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
------------------
|
------------------
|
||||||
2
|
2
|
||||||
@@ -2014,7 +2014,7 @@ SELECT '{
|
|||||||
produce <literal>true</literal>, <literal>false</literal>,
|
produce <literal>true</literal>, <literal>false</literal>,
|
||||||
or <literal>unknown</literal>. The <literal>unknown</literal> value
|
or <literal>unknown</literal>. The <literal>unknown</literal> value
|
||||||
plays the same role as SQL <literal>NULL</literal> and can be tested
|
plays the same role as SQL <literal>NULL</literal> and can be tested
|
||||||
for with the <literal>is unknown</literal> predicate. Further path
|
for with the <literal>IS UNKNOWN</literal> predicate. Further path
|
||||||
evaluation steps use only those items for which the filter expression
|
evaluation steps use only those items for which the filter expression
|
||||||
returned <literal>true</literal>.
|
returned <literal>true</literal>.
|
||||||
</para>
|
</para>
|
||||||
@@ -2032,7 +2032,7 @@ SELECT '{
|
|||||||
For example, suppose you would like to retrieve all heart rate values higher
|
For example, suppose you would like to retrieve all heart rate values higher
|
||||||
than 130. You can achieve this as follows:
|
than 130. You can achieve this as follows:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', '$.track.segments[*].HR ? (@ > 130)');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', '$.track.segments[*].HR ? (@ > 130)');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
------------------
|
------------------
|
||||||
135
|
135
|
||||||
@@ -2045,7 +2045,7 @@ SELECT '{
|
|||||||
filter expression is applied to the previous step, and the path used
|
filter expression is applied to the previous step, and the path used
|
||||||
in the condition is different:
|
in the condition is different:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', '$.track.segments[*] ? (@.HR > 130)."start time"');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', '$.track.segments[*] ? (@.HR > 130)."start time"');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
-----------------------
|
-----------------------
|
||||||
"2018-10-14 10:39:21"
|
"2018-10-14 10:39:21"
|
||||||
@@ -2057,7 +2057,7 @@ SELECT '{
|
|||||||
The following example selects start times of all segments that
|
The following example selects start times of all segments that
|
||||||
contain locations with relevant coordinates and high heart rate values:
|
contain locations with relevant coordinates and high heart rate values:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', '$.track.segments[*] ? (@.location[1] < 13.4) ? (@.HR > 130)."start time"');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', '$.track.segments[*] ? (@.location[1] < 13.4) ? (@.HR > 130)."start time"');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
-----------------------
|
-----------------------
|
||||||
"2018-10-14 10:39:21"
|
"2018-10-14 10:39:21"
|
||||||
@@ -2069,7 +2069,7 @@ SELECT '{
|
|||||||
The following example first filters all segments by location, and then
|
The following example first filters all segments by location, and then
|
||||||
returns high heart rate values for these segments, if available:
|
returns high heart rate values for these segments, if available:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', '$.track.segments[*] ? (@.location[1] < 13.4).HR ? (@ > 130)');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', '$.track.segments[*] ? (@.location[1] < 13.4).HR ? (@ > 130)');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
------------------
|
------------------
|
||||||
135
|
135
|
||||||
@@ -2081,7 +2081,7 @@ SELECT '{
|
|||||||
This example returns the size of the track if it contains any
|
This example returns the size of the track if it contains any
|
||||||
segments with high heart rate values, or an empty sequence otherwise:
|
segments with high heart rate values, or an empty sequence otherwise:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', '$.track ? (exists(@.segments[*] ? (@.HR > 130))).segments.size()');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', '$.track ? (exists(@.segments[*] ? (@.HR > 130))).segments.size()');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
------------------
|
------------------
|
||||||
2
|
2
|
||||||
@@ -2108,7 +2108,7 @@ SELECT '{
|
|||||||
<literal>false</literal>, or <literal>null</literal>.
|
<literal>false</literal>, or <literal>null</literal>.
|
||||||
For example, we could write this SQL-standard filter expression:
|
For example, we could write this SQL-standard filter expression:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', '$.track.segments ?(@[*].HR > 130)');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', '$.track.segments ?(@[*].HR > 130)');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
-----------------------------------------------------------&zwsp;----------------------
|
-----------------------------------------------------------&zwsp;----------------------
|
||||||
{"HR": 135, "location": [47.706, 13.2635], "start time": "2018-10-14 10:39:21"}
|
{"HR": 135, "location": [47.706, 13.2635], "start time": "2018-10-14 10:39:21"}
|
||||||
@@ -2116,7 +2116,7 @@ SELECT '{
|
|||||||
The similar predicate check expression simply
|
The similar predicate check expression simply
|
||||||
returns <literal>true</literal>, indicating that a match exists:
|
returns <literal>true</literal>, indicating that a match exists:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', '$.track.segments[*].HR > 130');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', '$.track.segments[*].HR > 130');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
------------------
|
------------------
|
||||||
true
|
true
|
||||||
@@ -2204,7 +2204,7 @@ SELECT '{
|
|||||||
abstract from the fact that it stores an array of segments
|
abstract from the fact that it stores an array of segments
|
||||||
when using lax mode:
|
when using lax mode:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', 'lax $.track.segments.location');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', 'lax $.track.segments.location');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
-------------------
|
-------------------
|
||||||
[47.763, 13.4034]
|
[47.763, 13.4034]
|
||||||
@@ -2217,13 +2217,13 @@ SELECT '{
|
|||||||
the queried JSON document, so using this path
|
the queried JSON document, so using this path
|
||||||
expression will cause an error:
|
expression will cause an error:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', 'strict $.track.segments.location');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', 'strict $.track.segments.location');</userinput>
|
||||||
ERROR: jsonpath member accessor can only be applied to an object
|
ERROR: jsonpath member accessor can only be applied to an object
|
||||||
</screen>
|
</screen>
|
||||||
To get the same result as in lax mode, you have to explicitly unwrap the
|
To get the same result as in lax mode, you have to explicitly unwrap the
|
||||||
<literal>segments</literal> array:
|
<literal>segments</literal> array:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', 'strict $.track.segments[*].location');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', 'strict $.track.segments[*].location');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
-------------------
|
-------------------
|
||||||
[47.763, 13.4034]
|
[47.763, 13.4034]
|
||||||
@@ -2236,7 +2236,7 @@ ERROR: jsonpath member accessor can only be applied to an object
|
|||||||
instance, the following query using the <literal>.**</literal> accessor
|
instance, the following query using the <literal>.**</literal> accessor
|
||||||
selects every <literal>HR</literal> value twice:
|
selects every <literal>HR</literal> value twice:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', 'lax $.**.HR');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', 'lax $.**.HR');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
------------------
|
------------------
|
||||||
73
|
73
|
||||||
@@ -2251,7 +2251,7 @@ ERROR: jsonpath member accessor can only be applied to an object
|
|||||||
the <literal>.**</literal> accessor only in strict mode. The
|
the <literal>.**</literal> accessor only in strict mode. The
|
||||||
following query selects each <literal>HR</literal> value just once:
|
following query selects each <literal>HR</literal> value just once:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', 'strict $.**.HR');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', 'strict $.**.HR');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
------------------
|
------------------
|
||||||
73
|
73
|
||||||
@@ -2263,7 +2263,7 @@ ERROR: jsonpath member accessor can only be applied to an object
|
|||||||
The unwrapping of arrays can also lead to unexpected results. Consider this
|
The unwrapping of arrays can also lead to unexpected results. Consider this
|
||||||
example, which selects all the <literal>location</literal> arrays:
|
example, which selects all the <literal>location</literal> arrays:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', 'lax $.track.segments[*].location');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', 'lax $.track.segments[*].location');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
-------------------
|
-------------------
|
||||||
[47.763, 13.4034]
|
[47.763, 13.4034]
|
||||||
@@ -2274,7 +2274,7 @@ ERROR: jsonpath member accessor can only be applied to an object
|
|||||||
causes the arrays to be unwrapped to evaluate each item, returning only the
|
causes the arrays to be unwrapped to evaluate each item, returning only the
|
||||||
items that match the expression:
|
items that match the expression:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', 'lax $.track.segments[*].location ?(@[*] > 15)');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', 'lax $.track.segments[*].location ?(@[*] > 15)');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
------------------
|
------------------
|
||||||
47.763
|
47.763
|
||||||
@@ -2284,7 +2284,7 @@ ERROR: jsonpath member accessor can only be applied to an object
|
|||||||
This despite the fact that the full arrays are selected by the path
|
This despite the fact that the full arrays are selected by the path
|
||||||
expression. Use strict mode to restore selecting the arrays:
|
expression. Use strict mode to restore selecting the arrays:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>=></prompt> <userinput>select jsonb_path_query(:'json', 'strict $.track.segments[*].location ?(@[*] > 15)');</userinput>
|
<prompt>=></prompt> <userinput>SELECT jsonb_path_query(:'json', 'strict $.track.segments[*].location ?(@[*] > 15)');</userinput>
|
||||||
jsonb_path_query
|
jsonb_path_query
|
||||||
-------------------
|
-------------------
|
||||||
[47.763, 13.4034]
|
[47.763, 13.4034]
|
||||||
@@ -3423,7 +3423,7 @@ DETAIL: Missing "]" after array dimensions.
|
|||||||
<returnvalue>2015-02-01</returnvalue>
|
<returnvalue>2015-02-01</returnvalue>
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>JSON_VALUE(jsonb '[1,2]', 'strict $[$off]' PASSING 1 as off)</literal>
|
<literal>JSON_VALUE(jsonb '[1,2]', 'strict $[$off]' PASSING 1 AS off)</literal>
|
||||||
<returnvalue>2</returnvalue>
|
<returnvalue>2</returnvalue>
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
|
|||||||
@@ -412,8 +412,8 @@ substring(<replaceable>string</replaceable>, <replaceable>pattern</replaceable>,
|
|||||||
<para>
|
<para>
|
||||||
Some examples, with <literal>#"</literal> delimiting the return string:
|
Some examples, with <literal>#"</literal> delimiting the return string:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
substring('foobar' similar '%#"o_b#"%' escape '#') <lineannotation>oob</lineannotation>
|
substring('foobar' SIMILAR '%#"o_b#"%' ESCAPE '#') <lineannotation>oob</lineannotation>
|
||||||
substring('foobar' similar '#"o_b#"%' escape '#') <lineannotation>NULL</lineannotation>
|
substring('foobar' SIMILAR '#"o_b#"%' ESCAPE '#') <lineannotation>NULL</lineannotation>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
</sect2>
|
</sect2>
|
||||||
@@ -600,8 +600,8 @@ substring('foobar' similar '#"o_b#"%' escape '#') <lineannotation>NULL</linea
|
|||||||
<para>
|
<para>
|
||||||
Some examples:
|
Some examples:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
substring('foobar' from 'o.b') <lineannotation>oob</lineannotation>
|
substring('foobar' FROM 'o.b') <lineannotation>oob</lineannotation>
|
||||||
substring('foobar' from 'o(.)b') <lineannotation>o</lineannotation>
|
substring('foobar' FROM 'o(.)b') <lineannotation>o</lineannotation>
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
|||||||
@@ -247,8 +247,8 @@ FROM (SELECT generate_subscripts(a, 1) AS s, a FROM arrays) foo;
|
|||||||
-- unnest a 2D array:
|
-- unnest a 2D array:
|
||||||
CREATE OR REPLACE FUNCTION unnest2(anyarray)
|
CREATE OR REPLACE FUNCTION unnest2(anyarray)
|
||||||
RETURNS SETOF anyelement AS $$
|
RETURNS SETOF anyelement AS $$
|
||||||
select $1[i][j]
|
SELECT $1[i][j]
|
||||||
from generate_subscripts($1,1) g1(i),
|
FROM generate_subscripts($1,1) g1(i),
|
||||||
generate_subscripts($1,2) g2(j);
|
generate_subscripts($1,2) g2(j);
|
||||||
$$ LANGUAGE sql IMMUTABLE;
|
$$ LANGUAGE sql IMMUTABLE;
|
||||||
CREATE FUNCTION
|
CREATE FUNCTION
|
||||||
|
|||||||
@@ -328,7 +328,7 @@
|
|||||||
of <parameter>newsubstring</parameter>.
|
of <parameter>newsubstring</parameter>.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>overlay('Txxxxas' placing 'hom' from 2 for 4)</literal>
|
<literal>overlay('Txxxxas' PLACING 'hom' FROM 2 FOR 4)</literal>
|
||||||
<returnvalue>Thomas</returnvalue>
|
<returnvalue>Thomas</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
@@ -347,7 +347,7 @@
|
|||||||
<parameter>string</parameter>, or zero if it's not present.
|
<parameter>string</parameter>, or zero if it's not present.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>position('om' in 'Thomas')</literal>
|
<literal>position('om' IN 'Thomas')</literal>
|
||||||
<returnvalue>3</returnvalue>
|
<returnvalue>3</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
@@ -411,15 +411,15 @@
|
|||||||
and <parameter>count</parameter>.
|
and <parameter>count</parameter>.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>substring('Thomas' from 2 for 3)</literal>
|
<literal>substring('Thomas' FROM 2 FOR 3)</literal>
|
||||||
<returnvalue>hom</returnvalue>
|
<returnvalue>hom</returnvalue>
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>substring('Thomas' from 3)</literal>
|
<literal>substring('Thomas' FROM 3)</literal>
|
||||||
<returnvalue>omas</returnvalue>
|
<returnvalue>omas</returnvalue>
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>substring('Thomas' for 2)</literal>
|
<literal>substring('Thomas' FOR 2)</literal>
|
||||||
<returnvalue>Th</returnvalue>
|
<returnvalue>Th</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
@@ -434,7 +434,7 @@
|
|||||||
<xref linkend="functions-posix-regexp"/>.
|
<xref linkend="functions-posix-regexp"/>.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>substring('Thomas' from '...$')</literal>
|
<literal>substring('Thomas' FROM '...$')</literal>
|
||||||
<returnvalue>mas</returnvalue>
|
<returnvalue>mas</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
@@ -455,7 +455,7 @@
|
|||||||
and should be considered obsolete.
|
and should be considered obsolete.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>substring('Thomas' similar '%#"o_a#"_' escape '#')</literal>
|
<literal>substring('Thomas' SIMILAR '%#"o_a#"_' ESCAPE '#')</literal>
|
||||||
<returnvalue>oma</returnvalue>
|
<returnvalue>oma</returnvalue>
|
||||||
</para></entry>
|
</para></entry>
|
||||||
</row>
|
</row>
|
||||||
|
|||||||
@@ -835,7 +835,7 @@
|
|||||||
Expands a <type>tsvector</type> into a set of rows, one per lexeme.
|
Expands a <type>tsvector</type> into a set of rows, one per lexeme.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>select * from unnest('cat:3 fat:2,4 rat:5A'::tsvector)</literal>
|
<literal>SELECT * FROM unnest('cat:3 fat:2,4 rat:5A'::tsvector)</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
lexeme | positions | weights
|
lexeme | positions | weights
|
||||||
|
|||||||
@@ -177,19 +177,19 @@ SELECT xmlconcat('<?xml version="1.1"?><foo/>', '<?xml version="1.1" standalone=
|
|||||||
<para>
|
<para>
|
||||||
Examples:
|
Examples:
|
||||||
<screen><![CDATA[
|
<screen><![CDATA[
|
||||||
SELECT xmlelement(name foo);
|
SELECT xmlelement(NAME foo);
|
||||||
|
|
||||||
xmlelement
|
xmlelement
|
||||||
------------
|
------------
|
||||||
<foo/>
|
<foo/>
|
||||||
|
|
||||||
SELECT xmlelement(name foo, xmlattributes('xyz' as bar));
|
SELECT xmlelement(NAME foo, xmlattributes('xyz' AS bar));
|
||||||
|
|
||||||
xmlelement
|
xmlelement
|
||||||
------------------
|
------------------
|
||||||
<foo bar="xyz"/>
|
<foo bar="xyz"/>
|
||||||
|
|
||||||
SELECT xmlelement(name foo, xmlattributes(current_date as bar), 'cont', 'ent');
|
SELECT xmlelement(NAME foo, xmlattributes(current_date AS bar), 'cont', 'ent');
|
||||||
|
|
||||||
xmlelement
|
xmlelement
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
@@ -204,7 +204,7 @@ SELECT xmlelement(name foo, xmlattributes(current_date as bar), 'cont', 'ent');
|
|||||||
<replaceable>HHHH</replaceable> is the character's Unicode
|
<replaceable>HHHH</replaceable> is the character's Unicode
|
||||||
codepoint in hexadecimal notation. For example:
|
codepoint in hexadecimal notation. For example:
|
||||||
<screen><![CDATA[
|
<screen><![CDATA[
|
||||||
SELECT xmlelement(name "foo$bar", xmlattributes('xyz' as "a&b"));
|
SELECT xmlelement(NAME "foo$bar", xmlattributes('xyz' AS "a&b"));
|
||||||
|
|
||||||
xmlelement
|
xmlelement
|
||||||
----------------------------------
|
----------------------------------
|
||||||
@@ -220,12 +220,12 @@ SELECT xmlelement(name "foo$bar", xmlattributes('xyz' as "a&b"));
|
|||||||
valid:
|
valid:
|
||||||
<screen>
|
<screen>
|
||||||
CREATE TABLE test (a xml, b xml);
|
CREATE TABLE test (a xml, b xml);
|
||||||
SELECT xmlelement(name test, xmlattributes(a, b)) FROM test;
|
SELECT xmlelement(NAME test, xmlattributes(a, b)) FROM test;
|
||||||
</screen>
|
</screen>
|
||||||
But these are not:
|
But these are not:
|
||||||
<screen>
|
<screen>
|
||||||
SELECT xmlelement(name test, xmlattributes('constant'), a, b) FROM test;
|
SELECT xmlelement(NAME test, xmlattributes('constant'), a, b) FROM test;
|
||||||
SELECT xmlelement(name test, xmlattributes(func(a, b))) FROM test;
|
SELECT xmlelement(NAME test, xmlattributes(func(a, b))) FROM test;
|
||||||
</screen>
|
</screen>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@@ -234,10 +234,10 @@ SELECT xmlelement(name test, xmlattributes(func(a, b))) FROM test;
|
|||||||
its data type. If the content is itself of type <type>xml</type>,
|
its data type. If the content is itself of type <type>xml</type>,
|
||||||
complex XML documents can be constructed. For example:
|
complex XML documents can be constructed. For example:
|
||||||
<screen><![CDATA[
|
<screen><![CDATA[
|
||||||
SELECT xmlelement(name foo, xmlattributes('xyz' as bar),
|
SELECT xmlelement(NAME foo, xmlattributes('xyz' AS bar),
|
||||||
xmlelement(name abc),
|
xmlelement(NAME abc),
|
||||||
xmlcomment('test'),
|
xmlcomment('test'),
|
||||||
xmlelement(name xyz));
|
xmlelement(NAME xyz));
|
||||||
|
|
||||||
xmlelement
|
xmlelement
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
|
|||||||
@@ -600,7 +600,7 @@ b
|
|||||||
Extracts an <type>hstore</type>'s keys and values as a set of records.
|
Extracts an <type>hstore</type>'s keys and values as a set of records.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
<literal>select * from each('a=>1,b=>2')</literal>
|
<literal>SELECT * FROM each('a=>1,b=>2')</literal>
|
||||||
<returnvalue></returnvalue>
|
<returnvalue></returnvalue>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
key | value
|
key | value
|
||||||
@@ -799,7 +799,7 @@ UPDATE tab SET h = h || hstore('c', '3');
|
|||||||
If multiple keys are to be added or changed in one operation,
|
If multiple keys are to be added or changed in one operation,
|
||||||
the concatenation approach is more efficient than subscripting:
|
the concatenation approach is more efficient than subscripting:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
UPDATE tab SET h = h || hstore(array['q', 'w'], array['11', '12']);
|
UPDATE tab SET h = h || hstore(ARRAY['q', 'w'], ARRAY['11', '12']);
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
|||||||
@@ -949,19 +949,19 @@ WHERE url = '/index.html' AND client_ip = inet '192.168.100.23';
|
|||||||
command to create the index would look like this:
|
command to create the index would look like this:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE INDEX orders_unbilled_index ON orders (order_nr)
|
CREATE INDEX orders_unbilled_index ON orders (order_nr)
|
||||||
WHERE billed is not true;
|
WHERE billed IS NOT TRUE;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
A possible query to use this index would be:
|
A possible query to use this index would be:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
SELECT * FROM orders WHERE billed is not true AND order_nr < 10000;
|
SELECT * FROM orders WHERE billed IS NOT TRUE AND order_nr < 10000;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
However, the index can also be used in queries that do not involve
|
However, the index can also be used in queries that do not involve
|
||||||
<structfield>order_nr</structfield> at all, e.g.:
|
<structfield>order_nr</structfield> at all, e.g.:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
SELECT * FROM orders WHERE billed is not true AND amount > 5000.00;
|
SELECT * FROM orders WHERE billed IS NOT TRUE AND amount > 5000.00;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
This is not as efficient as a partial index on the
|
This is not as efficient as a partial index on the
|
||||||
<structfield>amount</structfield> column would be, since the system has to
|
<structfield>amount</structfield> column would be, since the system has to
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ SELECT issn('1436-4522');
|
|||||||
--Casting types:
|
--Casting types:
|
||||||
-- note that you can only cast from ean13 to another type when the
|
-- note that you can only cast from ean13 to another type when the
|
||||||
-- number would be valid in the realm of the target type;
|
-- number would be valid in the realm of the target type;
|
||||||
-- thus, the following will NOT work: select isbn(ean13('0220356483481'));
|
-- thus, the following will NOT work: SELECT isbn(ean13('0220356483481'));
|
||||||
-- but these will:
|
-- but these will:
|
||||||
SELECT upc(ean13('0220356483481'));
|
SELECT upc(ean13('0220356483481'));
|
||||||
SELECT ean13(upc('220356483481'));
|
SELECT ean13(upc('220356483481'));
|
||||||
|
|||||||
@@ -10861,7 +10861,7 @@ main(int argc, char **argv)
|
|||||||
/*
|
/*
|
||||||
* Our test case here involves using a cursor, for which we must be inside
|
* Our test case here involves using a cursor, for which we must be inside
|
||||||
* a transaction block. We could do the whole thing with a single
|
* a transaction block. We could do the whole thing with a single
|
||||||
* PQexec() of "select * from pg_database", but that's too trivial to make
|
* PQexec() of "SELECT * FROM pg_database", but that's too trivial to make
|
||||||
* a good example.
|
* a good example.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -10878,7 +10878,7 @@ main(int argc, char **argv)
|
|||||||
/*
|
/*
|
||||||
* Fetch rows from pg_database, the system catalog of databases
|
* Fetch rows from pg_database, the system catalog of databases
|
||||||
*/
|
*/
|
||||||
res = PQexec(conn, "DECLARE myportal CURSOR FOR select * from pg_database");
|
res = PQexec(conn, "DECLARE myportal CURSOR FOR SELECT * FROM pg_database");
|
||||||
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "DECLARE CURSOR failed: %s", PQerrorMessage(conn));
|
fprintf(stderr, "DECLARE CURSOR failed: %s", PQerrorMessage(conn));
|
||||||
|
|||||||
@@ -1594,7 +1594,7 @@ Publications:
|
|||||||
|
|
||||||
/* sub # */ CREATE TABLE tab_gen_to_gen (a int, b int GENERATED ALWAYS AS (a * 100) STORED);
|
/* sub # */ CREATE TABLE tab_gen_to_gen (a int, b int GENERATED ALWAYS AS (a * 100) STORED);
|
||||||
/* sub # */ CREATE SUBSCRIPTION sub1 CONNECTION 'dbname=test_pub' PUBLICATION pub1;
|
/* sub # */ CREATE SUBSCRIPTION sub1 CONNECTION 'dbname=test_pub' PUBLICATION pub1;
|
||||||
/* sub # */ SELECT * from tab_gen_to_gen;
|
/* sub # */ SELECT * FROM tab_gen_to_gen;
|
||||||
a | b
|
a | b
|
||||||
---+----
|
---+----
|
||||||
1 | 100
|
1 | 100
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ postgres=# SELECT * FROM pg_logical_slot_get_changes('regression_slot', NULL, NU
|
|||||||
-----+-----+------
|
-----+-----+------
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
postgres=# CREATE TABLE data(id serial primary key, data text);
|
postgres=# CREATE TABLE data(id serial PRIMARY KEY, data text);
|
||||||
CREATE TABLE
|
CREATE TABLE
|
||||||
|
|
||||||
postgres=# -- DDL isn't replicated, so all you'll see is the transaction
|
postgres=# -- DDL isn't replicated, so all you'll see is the transaction
|
||||||
@@ -208,7 +208,7 @@ postgres=# SELECT * FROM pg_logical_slot_get_changes('regression_slot', NULL, NU
|
|||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
postgres=# COMMIT PREPARED 'test_prepared1';
|
postgres=# COMMIT PREPARED 'test_prepared1';
|
||||||
postgres=# select * from pg_logical_slot_get_changes('regression_slot', NULL, NULL);
|
postgres=# SELECT * from pg_logical_slot_get_changes('regression_slot', NULL, NULL);
|
||||||
lsn | xid | data
|
lsn | xid | data
|
||||||
------------+-----+--------------------------------------------
|
------------+-----+--------------------------------------------
|
||||||
0/0168A060 | 529 | COMMIT PREPARED 'test_prepared1', txid 529
|
0/0168A060 | 529 | COMMIT PREPARED 'test_prepared1', txid 529
|
||||||
@@ -218,7 +218,7 @@ postgres=#-- you can also rollback a prepared transaction
|
|||||||
postgres=# BEGIN;
|
postgres=# BEGIN;
|
||||||
postgres=*# INSERT INTO data(data) VALUES('6');
|
postgres=*# INSERT INTO data(data) VALUES('6');
|
||||||
postgres=*# PREPARE TRANSACTION 'test_prepared2';
|
postgres=*# PREPARE TRANSACTION 'test_prepared2';
|
||||||
postgres=# select * from pg_logical_slot_get_changes('regression_slot', NULL, NULL);
|
postgres=# SELECT * from pg_logical_slot_get_changes('regression_slot', NULL, NULL);
|
||||||
lsn | xid | data
|
lsn | xid | data
|
||||||
------------+-----+---------------------------------------------------------
|
------------+-----+---------------------------------------------------------
|
||||||
0/0168A180 | 530 | BEGIN 530
|
0/0168A180 | 530 | BEGIN 530
|
||||||
@@ -227,7 +227,7 @@ postgres=# select * from pg_logical_slot_get_changes('regression_slot', NULL, NU
|
|||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
postgres=# ROLLBACK PREPARED 'test_prepared2';
|
postgres=# ROLLBACK PREPARED 'test_prepared2';
|
||||||
postgres=# select * from pg_logical_slot_get_changes('regression_slot', NULL, NULL);
|
postgres=# SELECT * from pg_logical_slot_get_changes('regression_slot', NULL, NULL);
|
||||||
lsn | xid | data
|
lsn | xid | data
|
||||||
------------+-----+----------------------------------------------
|
------------+-----+----------------------------------------------
|
||||||
0/0168A4B8 | 530 | ROLLBACK PREPARED 'test_prepared2', txid 530
|
0/0168A4B8 | 530 | ROLLBACK PREPARED 'test_prepared2', txid 530
|
||||||
|
|||||||
@@ -818,7 +818,7 @@ ltreetest=> SELECT subpath(path,0,2)||'Space'||subpath(path,2) FROM test WHER
|
|||||||
at a specified position in a path:
|
at a specified position in a path:
|
||||||
<screen>
|
<screen>
|
||||||
CREATE FUNCTION ins_label(ltree, int, text) RETURNS ltree
|
CREATE FUNCTION ins_label(ltree, int, text) RETURNS ltree
|
||||||
AS 'select subpath($1,0,$2) || $3 || subpath($1,$2);'
|
AS 'SELECT subpath($1, 0, $2) || $3 || subpath($1, $2);'
|
||||||
LANGUAGE SQL IMMUTABLE;
|
LANGUAGE SQL IMMUTABLE;
|
||||||
|
|
||||||
ltreetest=> SELECT ins_label(path,2,'Space') FROM test WHERE path <@ 'Top.Science.Astronomy';
|
ltreetest=> SELECT ins_label(path,2,'Space') FROM test WHERE path <@ 'Top.Science.Astronomy';
|
||||||
|
|||||||
@@ -614,8 +614,8 @@
|
|||||||
examine this information is to execute queries such as:
|
examine this information is to execute queries such as:
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
SELECT c.oid::regclass as table_name,
|
SELECT c.oid::regclass AS table_name,
|
||||||
greatest(age(c.relfrozenxid),age(t.relfrozenxid)) as age
|
greatest(age(c.relfrozenxid), age(t.relfrozenxid)) AS age
|
||||||
FROM pg_class c
|
FROM pg_class c
|
||||||
LEFT JOIN pg_class t ON c.reltoastrelid = t.oid
|
LEFT JOIN pg_class t ON c.reltoastrelid = t.oid
|
||||||
WHERE c.relkind IN ('r', 'm');
|
WHERE c.relkind IN ('r', 'm');
|
||||||
|
|||||||
@@ -1137,7 +1137,7 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
|
|||||||
Here are examples of how wait events can be viewed:
|
Here are examples of how wait events can be viewed:
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event is NOT NULL;
|
SELECT pid, wait_event_type, wait_event FROM pg_stat_activity WHERE wait_event IS NOT NULL;
|
||||||
pid | wait_event_type | wait_event
|
pid | wait_event_type | wait_event
|
||||||
------+-----------------+------------
|
------+-----------------+------------
|
||||||
2540 | Lock | relation
|
2540 | Lock | relation
|
||||||
@@ -1150,7 +1150,7 @@ SELECT a.pid, a.wait_event, w.description
|
|||||||
FROM pg_stat_activity a JOIN
|
FROM pg_stat_activity a JOIN
|
||||||
pg_wait_events w ON (a.wait_event_type = w.type AND
|
pg_wait_events w ON (a.wait_event_type = w.type AND
|
||||||
a.wait_event = w.name)
|
a.wait_event = w.name)
|
||||||
WHERE a.wait_event is NOT NULL and a.state = 'active';
|
WHERE a.wait_event IS NOT NULL AND a.state = 'active';
|
||||||
-[ RECORD 1 ]------------------------------------------------------&zwsp;------------
|
-[ RECORD 1 ]------------------------------------------------------&zwsp;------------
|
||||||
pid | 686674
|
pid | 686674
|
||||||
wait_event | WALInitSync
|
wait_event | WALInitSync
|
||||||
|
|||||||
@@ -932,8 +932,8 @@ test=# SELECT * FROM hash_bitmap_info('con_hash_index', 2052);
|
|||||||
<screen>
|
<screen>
|
||||||
test=# SELECT magic, version, ntuples, ffactor, bsize, bmsize, bmshift,
|
test=# SELECT magic, version, ntuples, ffactor, bsize, bmsize, bmshift,
|
||||||
test-# maxbucket, highmask, lowmask, ovflpoint, firstfree, nmaps, procid,
|
test-# maxbucket, highmask, lowmask, ovflpoint, firstfree, nmaps, procid,
|
||||||
test-# regexp_replace(spares::text, '(,0)*}', '}') as spares,
|
test-# regexp_replace(spares::text, '(,0)*}', '}') AS spares,
|
||||||
test-# regexp_replace(mapp::text, '(,0)*}', '}') as mapp
|
test-# regexp_replace(mapp::text, '(,0)*}', '}') AS mapp
|
||||||
test-# FROM hash_metapage_info(get_raw_page('con_hash_index', 0));
|
test-# FROM hash_metapage_info(get_raw_page('con_hash_index', 0));
|
||||||
-[ RECORD 1 ]-------------------------------------------------&zwsp;------------------------------
|
-[ RECORD 1 ]-------------------------------------------------&zwsp;------------------------------
|
||||||
magic | 105121344
|
magic | 105121344
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ digest(data bytea, type text) returns bytea
|
|||||||
If you want the digest as a hexadecimal string, use
|
If you want the digest as a hexadecimal string, use
|
||||||
<function>encode()</function> on the result. For example:
|
<function>encode()</function> on the result. For example:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE OR REPLACE FUNCTION sha1(bytea) returns text AS $$
|
CREATE OR REPLACE FUNCTION sha1(bytea) RETURNS text AS $$
|
||||||
SELECT encode(digest($1, 'sha1'), 'hex')
|
SELECT encode(digest($1, 'sha1'), 'hex')
|
||||||
$$ LANGUAGE SQL STRICT IMMUTABLE;
|
$$ LANGUAGE SQL STRICT IMMUTABLE;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|||||||
@@ -377,7 +377,7 @@ pending_tuples | 0
|
|||||||
<function>pgstathashindex</function> returns a record showing information
|
<function>pgstathashindex</function> returns a record showing information
|
||||||
about a HASH index. For example:
|
about a HASH index. For example:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
test=> select * from pgstathashindex('con_hash_index');
|
test=> SELECT * FROM pgstathashindex('con_hash_index');
|
||||||
-[ RECORD 1 ]--+-----------------
|
-[ RECORD 1 ]--+-----------------
|
||||||
version | 4
|
version | 4
|
||||||
bucket_pages | 33081
|
bucket_pages | 33081
|
||||||
|
|||||||
@@ -34,17 +34,17 @@
|
|||||||
intended use of this function is to forcibly remove tuples that are not
|
intended use of this function is to forcibly remove tuples that are not
|
||||||
otherwise accessible. For example:
|
otherwise accessible. For example:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
test=> select * from t1 where ctid = '(0, 1)';
|
test=> SELECT * FROM t1 WHERE ctid = '(0, 1)';
|
||||||
ERROR: could not access status of transaction 4007513275
|
ERROR: could not access status of transaction 4007513275
|
||||||
DETAIL: Could not open file "pg_xact/0EED": No such file or directory.
|
DETAIL: Could not open file "pg_xact/0EED": No such file or directory.
|
||||||
|
|
||||||
test=# select heap_force_kill('t1'::regclass, ARRAY['(0, 1)']::tid[]);
|
test=# SELECT heap_force_kill('t1'::regclass, ARRAY['(0, 1)']::tid[]);
|
||||||
heap_force_kill
|
heap_force_kill
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
test=# select * from t1 where ctid = '(0, 1)';
|
test=# SELECT * FROM t1 WHERE ctid = '(0, 1)';
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
</programlisting>
|
</programlisting>
|
||||||
@@ -70,19 +70,19 @@ test=> vacuum t1;
|
|||||||
ERROR: found xmin 507 from before relfrozenxid 515
|
ERROR: found xmin 507 from before relfrozenxid 515
|
||||||
CONTEXT: while scanning block 0 of relation "public.t1"
|
CONTEXT: while scanning block 0 of relation "public.t1"
|
||||||
|
|
||||||
test=# select ctid from t1 where xmin = 507;
|
test=# SELECT ctid FROM t1 WHERE xmin = 507;
|
||||||
ctid
|
ctid
|
||||||
-------
|
-------
|
||||||
(0,3)
|
(0,3)
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
test=# select heap_force_freeze('t1'::regclass, ARRAY['(0, 3)']::tid[]);
|
test=# SELECT heap_force_freeze('t1'::regclass, ARRAY['(0, 3)']::tid[]);
|
||||||
heap_force_freeze
|
heap_force_freeze
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
test=# select ctid from t1 where xmin = 2;
|
test=# SELECT ctid FROM t1 WHERE xmin = 2;
|
||||||
ctid
|
ctid
|
||||||
-------
|
-------
|
||||||
(0,3)
|
(0,3)
|
||||||
|
|||||||
@@ -635,7 +635,7 @@ EXPLAIN (ANALYZE, TIMING OFF, BUFFERS OFF) SELECT * FROM t WHERE a = 1 AND b = 1
|
|||||||
<function>pg_mcv_list_items</function> set-returning function.
|
<function>pg_mcv_list_items</function> set-returning function.
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
SELECT m.* FROM pg_statistic_ext join pg_statistic_ext_data on (oid = stxoid),
|
SELECT m.* FROM pg_statistic_ext JOIN pg_statistic_ext_data ON (oid = stxoid),
|
||||||
pg_mcv_list_items(stxdmcv) m WHERE stxname = 'stts2';
|
pg_mcv_list_items(stxdmcv) m WHERE stxname = 'stts2';
|
||||||
index | values | nulls | frequency | base_frequency
|
index | values | nulls | frequency | base_frequency
|
||||||
-------+----------+-------+-----------+----------------
|
-------+----------+-------+-----------+----------------
|
||||||
|
|||||||
@@ -229,12 +229,12 @@ $$ LANGUAGE plperl;
|
|||||||
references to Perl arrays. Here is an example:
|
references to Perl arrays. Here is an example:
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE OR REPLACE function returns_array()
|
CREATE OR REPLACE FUNCTION returns_array()
|
||||||
RETURNS text[][] AS $$
|
RETURNS text[][] AS $$
|
||||||
return [['a"b','c,d'],['e\\f','g']];
|
return [['a"b','c,d'],['e\\f','g']];
|
||||||
$$ LANGUAGE plperl;
|
$$ LANGUAGE plperl;
|
||||||
|
|
||||||
select returns_array();
|
SELECT returns_array();
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@@ -512,7 +512,7 @@ INSERT INTO test (i, v) VALUES (3, 'third line');
|
|||||||
INSERT INTO test (i, v) VALUES (4, 'immortal');
|
INSERT INTO test (i, v) VALUES (4, 'immortal');
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION test_munge() RETURNS SETOF test AS $$
|
CREATE OR REPLACE FUNCTION test_munge() RETURNS SETOF test AS $$
|
||||||
my $rv = spi_exec_query('select i, v from test;');
|
my $rv = spi_exec_query('SELECT i, v FROM test;');
|
||||||
my $status = $rv->{status};
|
my $status = $rv->{status};
|
||||||
my $nrows = $rv->{processed};
|
my $nrows = $rv->{processed};
|
||||||
foreach my $rn (0 .. $nrows - 1) {
|
foreach my $rn (0 .. $nrows - 1) {
|
||||||
@@ -588,7 +588,7 @@ CREATE OR REPLACE FUNCTION lotsa_md5 (INTEGER) RETURNS SETOF foo_type AS $$
|
|||||||
return;
|
return;
|
||||||
$$ LANGUAGE plperlu;
|
$$ LANGUAGE plperlu;
|
||||||
|
|
||||||
SELECT * from lotsa_md5(500);
|
SELECT * FROM lotsa_md5(500);
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
|||||||
@@ -1023,7 +1023,7 @@ IF count(*) > 0 FROM my_table THEN ...
|
|||||||
tax := subtotal * 0.06;
|
tax := subtotal * 0.06;
|
||||||
my_record.user_id := 20;
|
my_record.user_id := 20;
|
||||||
my_array[j] := 20;
|
my_array[j] := 20;
|
||||||
my_array[1:3] := array[1,2,3];
|
my_array[1:3] := ARRAY[1, 2, 3];
|
||||||
complex_array[n].realpart = 12.3;
|
complex_array[n].realpart = 12.3;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
@@ -1037,7 +1037,7 @@ complex_array[n].realpart = 12.3;
|
|||||||
within a <application>PL/pgSQL</application> function just by writing
|
within a <application>PL/pgSQL</application> function just by writing
|
||||||
the command. For example, you could create and fill a table by writing
|
the command. For example, you could create and fill a table by writing
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE TABLE mytable (id int primary key, data text);
|
CREATE TABLE mytable (id int PRIMARY KEY, data text);
|
||||||
INSERT INTO mytable VALUES (1,'one'), (2,'two');
|
INSERT INTO mytable VALUES (1,'one'), (2,'two');
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
@@ -5294,24 +5294,24 @@ a_output := a_output || $$ AND name LIKE 'foobar'$$
|
|||||||
<xref linkend="plpgsql-porting-ex2"/>.
|
<xref linkend="plpgsql-porting-ex2"/>.
|
||||||
For example:
|
For example:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
a_output := a_output || '' if v_'' ||
|
a_output := a_output || '' IF v_'' ||
|
||||||
referrer_keys.kind || '' like ''''''''''
|
referrer_keys.kind || '' LIKE ''''''''''
|
||||||
|| referrer_keys.key_string || ''''''''''
|
|| referrer_keys.key_string || ''''''''''
|
||||||
then return '''''' || referrer_keys.referrer_type
|
THEN RETURN '''''' || referrer_keys.referrer_type
|
||||||
|| ''''''; end if;'';
|
|| ''''''; END IF;'';
|
||||||
</programlisting>
|
</programlisting>
|
||||||
The value of <literal>a_output</literal> would then be:
|
The value of <literal>a_output</literal> would then be:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
if v_... like ''...'' then return ''...''; end if;
|
IF v_... LIKE ''...'' THEN RETURN ''...''; END IF;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
In the dollar-quoting approach, this becomes:
|
In the dollar-quoting approach, this becomes:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
a_output := a_output || $$ if v_$$ || referrer_keys.kind || $$ like '$$
|
a_output := a_output || $$ IF v_$$ || referrer_keys.kind || $$ LIKE '$$
|
||||||
|| referrer_keys.key_string || $$'
|
|| referrer_keys.key_string || $$'
|
||||||
then return '$$ || referrer_keys.referrer_type
|
THEN RETURN '$$ || referrer_keys.referrer_type
|
||||||
|| $$'; end if;$$;
|
|| $$'; END IF;$$;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
where we assume we only need to put single quote marks into
|
where we assume we only need to put single quote marks into
|
||||||
<literal>a_output</literal>, because it will be re-quoted before use.
|
<literal>a_output</literal>, because it will be re-quoted before use.
|
||||||
|
|||||||
@@ -1065,7 +1065,7 @@ $$ LANGUAGE plpython3u;
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE FUNCTION count_odd_iterator() RETURNS integer AS $$
|
CREATE FUNCTION count_odd_iterator() RETURNS integer AS $$
|
||||||
odd = 0
|
odd = 0
|
||||||
for row in plpy.cursor("select num from largetable"):
|
for row in plpy.cursor("SELECT num FROM largetable"):
|
||||||
if row['num'] % 2:
|
if row['num'] % 2:
|
||||||
odd += 1
|
odd += 1
|
||||||
return odd
|
return odd
|
||||||
@@ -1073,7 +1073,7 @@ $$ LANGUAGE plpython3u;
|
|||||||
|
|
||||||
CREATE FUNCTION count_odd_fetch(batch_size integer) RETURNS integer AS $$
|
CREATE FUNCTION count_odd_fetch(batch_size integer) RETURNS integer AS $$
|
||||||
odd = 0
|
odd = 0
|
||||||
cursor = plpy.cursor("select num from largetable")
|
cursor = plpy.cursor("SELECT num FROM largetable")
|
||||||
while True:
|
while True:
|
||||||
rows = cursor.fetch(batch_size)
|
rows = cursor.fetch(batch_size)
|
||||||
if not rows:
|
if not rows:
|
||||||
@@ -1086,7 +1086,7 @@ $$ LANGUAGE plpython3u;
|
|||||||
|
|
||||||
CREATE FUNCTION count_odd_prepared() RETURNS integer AS $$
|
CREATE FUNCTION count_odd_prepared() RETURNS integer AS $$
|
||||||
odd = 0
|
odd = 0
|
||||||
plan = plpy.prepare("select num from largetable where num % $1 <> 0", ["integer"])
|
plan = plpy.prepare("SELECT num FROM largetable WHERE num % $1 <> 0", ["integer"])
|
||||||
rows = list(plpy.cursor(plan, [2])) # or: = list(plan.cursor([2]))
|
rows = list(plpy.cursor(plan, [2])) # or: = list(plan.cursor([2]))
|
||||||
|
|
||||||
return len(rows)
|
return len(rows)
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ $$ LANGUAGE pltcl;
|
|||||||
column names. Here is an example:
|
column names. Here is an example:
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE FUNCTION square_cube(in int, out squared int, out cubed int) AS $$
|
CREATE FUNCTION square_cube(IN int, OUT squared int, OUT cubed int) AS $$
|
||||||
return [list squared [expr {$1 * $1}] cubed [expr {$1 * $1 * $1}]]
|
return [list squared [expr {$1 * $1}] cubed [expr {$1 * $1 * $1}]]
|
||||||
$$ LANGUAGE pltcl;
|
$$ LANGUAGE pltcl;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|||||||
@@ -2232,7 +2232,7 @@ WITH RECURSIVE included_parts(sub_part, part, quantity) AS (
|
|||||||
FROM included_parts pr, parts p
|
FROM included_parts pr, parts p
|
||||||
WHERE p.part = pr.sub_part
|
WHERE p.part = pr.sub_part
|
||||||
)
|
)
|
||||||
SELECT sub_part, SUM(quantity) as total_quantity
|
SELECT sub_part, SUM(quantity) AS total_quantity
|
||||||
FROM included_parts
|
FROM included_parts
|
||||||
GROUP BY sub_part
|
GROUP BY sub_part
|
||||||
</programlisting>
|
</programlisting>
|
||||||
@@ -2603,7 +2603,7 @@ WHERE w2.key = 123;
|
|||||||
undesirable is
|
undesirable is
|
||||||
<programlisting>
|
<programlisting>
|
||||||
WITH w AS (
|
WITH w AS (
|
||||||
SELECT key, very_expensive_function(val) as f FROM some_table
|
SELECT key, very_expensive_function(val) AS f FROM some_table
|
||||||
)
|
)
|
||||||
SELECT * FROM w AS w1 JOIN w AS w2 ON w1.f = w2.f;
|
SELECT * FROM w AS w1 JOIN w AS w2 ON w1.f = w2.f;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|||||||
@@ -1642,7 +1642,7 @@ ALTER TABLE measurements
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
ALTER TABLE transactions
|
ALTER TABLE transactions
|
||||||
ADD COLUMN status varchar(30) DEFAULT 'old',
|
ADD COLUMN status varchar(30) DEFAULT 'old',
|
||||||
ALTER COLUMN status SET default 'current';
|
ALTER COLUMN status SET DEFAULT 'current';
|
||||||
</programlisting>
|
</programlisting>
|
||||||
Existing rows will be filled with <literal>old</literal>, but then
|
Existing rows will be filled with <literal>old</literal>, but then
|
||||||
the default for subsequent commands will be <literal>current</literal>.
|
the default for subsequent commands will be <literal>current</literal>.
|
||||||
|
|||||||
@@ -649,7 +649,7 @@ END
|
|||||||
parameters. Thus for example these declarations conflict:
|
parameters. Thus for example these declarations conflict:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE FUNCTION foo(int) ...
|
CREATE FUNCTION foo(int) ...
|
||||||
CREATE FUNCTION foo(int, out text) ...
|
CREATE FUNCTION foo(int, OUT text) ...
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@@ -709,7 +709,7 @@ CREATE FUNCTION foo(int, int default 42) ...
|
|||||||
Add two integers using an SQL function:
|
Add two integers using an SQL function:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE FUNCTION add(integer, integer) RETURNS integer
|
CREATE FUNCTION add(integer, integer) RETURNS integer
|
||||||
AS 'select $1 + $2;'
|
AS 'SELECT $1 + $2;'
|
||||||
LANGUAGE SQL
|
LANGUAGE SQL
|
||||||
IMMUTABLE
|
IMMUTABLE
|
||||||
RETURNS NULL ON NULL INPUT;
|
RETURNS NULL ON NULL INPUT;
|
||||||
@@ -740,7 +740,7 @@ $$ LANGUAGE plpgsql;
|
|||||||
<para>
|
<para>
|
||||||
Return a record containing multiple output parameters:
|
Return a record containing multiple output parameters:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE FUNCTION dup(in int, out f1 int, out f2 text)
|
CREATE FUNCTION dup(IN int, OUT f1 int, OUT f2 text)
|
||||||
AS $$ SELECT $1, CAST($1 AS text) || ' is text' $$
|
AS $$ SELECT $1, CAST($1 AS text) || ' is text' $$
|
||||||
LANGUAGE SQL;
|
LANGUAGE SQL;
|
||||||
|
|
||||||
|
|||||||
@@ -2257,7 +2257,7 @@ CREATE TABLE employees OF employee_type (
|
|||||||
Create a range partitioned table:
|
Create a range partitioned table:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE TABLE measurement (
|
CREATE TABLE measurement (
|
||||||
logdate date not null,
|
logdate date NOT NULL,
|
||||||
peaktemp int,
|
peaktemp int,
|
||||||
unitsales int
|
unitsales int
|
||||||
) PARTITION BY RANGE (logdate);
|
) PARTITION BY RANGE (logdate);
|
||||||
@@ -2267,7 +2267,7 @@ CREATE TABLE measurement (
|
|||||||
Create a range partitioned table with multiple columns in the partition key:
|
Create a range partitioned table with multiple columns in the partition key:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE TABLE measurement_year_month (
|
CREATE TABLE measurement_year_month (
|
||||||
logdate date not null,
|
logdate date NOT NULL,
|
||||||
peaktemp int,
|
peaktemp int,
|
||||||
unitsales int
|
unitsales int
|
||||||
) PARTITION BY RANGE (EXTRACT(YEAR FROM logdate), EXTRACT(MONTH FROM logdate));
|
) PARTITION BY RANGE (EXTRACT(YEAR FROM logdate), EXTRACT(MONTH FROM logdate));
|
||||||
@@ -2277,8 +2277,8 @@ CREATE TABLE measurement_year_month (
|
|||||||
Create a list partitioned table:
|
Create a list partitioned table:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE TABLE cities (
|
CREATE TABLE cities (
|
||||||
city_id bigserial not null,
|
city_id bigserial NOT NULL,
|
||||||
name text not null,
|
name text NOT NULL,
|
||||||
population bigint
|
population bigint
|
||||||
) PARTITION BY LIST (left(lower(name), 1));
|
) PARTITION BY LIST (left(lower(name), 1));
|
||||||
</programlisting></para>
|
</programlisting></para>
|
||||||
@@ -2287,8 +2287,8 @@ CREATE TABLE cities (
|
|||||||
Create a hash partitioned table:
|
Create a hash partitioned table:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE TABLE orders (
|
CREATE TABLE orders (
|
||||||
order_id bigint not null,
|
order_id bigint NOT NULL,
|
||||||
cust_id bigint not null,
|
cust_id bigint NOT NULL,
|
||||||
status text
|
status text
|
||||||
) PARTITION BY HASH (order_id);
|
) PARTITION BY HASH (order_id);
|
||||||
</programlisting></para>
|
</programlisting></para>
|
||||||
|
|||||||
@@ -372,10 +372,10 @@ PostgreSQL documentation
|
|||||||
a role, named <literal>rewind_user</literal> here:
|
a role, named <literal>rewind_user</literal> here:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE USER rewind_user LOGIN;
|
CREATE USER rewind_user LOGIN;
|
||||||
GRANT EXECUTE ON function pg_catalog.pg_ls_dir(text, boolean, boolean) TO rewind_user;
|
GRANT EXECUTE ON FUNCTION pg_catalog.pg_ls_dir(text, boolean, boolean) TO rewind_user;
|
||||||
GRANT EXECUTE ON function pg_catalog.pg_stat_file(text, boolean) TO rewind_user;
|
GRANT EXECUTE ON FUNCTION pg_catalog.pg_stat_file(text, boolean) TO rewind_user;
|
||||||
GRANT EXECUTE ON function pg_catalog.pg_read_binary_file(text) TO rewind_user;
|
GRANT EXECUTE ON FUNCTION pg_catalog.pg_read_binary_file(text) TO rewind_user;
|
||||||
GRANT EXECUTE ON function pg_catalog.pg_read_binary_file(text, bigint, bigint, boolean) TO rewind_user;
|
GRANT EXECUTE ON FUNCTION pg_catalog.pg_read_binary_file(text, bigint, bigint, boolean) TO rewind_user;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
|||||||
@@ -2531,7 +2531,7 @@ Tue Oct 26 21:40:57 CEST 1999
|
|||||||
statement to be executed. For example, to create an index on each
|
statement to be executed. For example, to create an index on each
|
||||||
column of <structname>my_table</structname>:
|
column of <structname>my_table</structname>:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
=> <userinput>SELECT format('create index on my_table(%I)', attname)</userinput>
|
=> <userinput>SELECT format('CREATE INDEX ON my_table (%I)', attname)</userinput>
|
||||||
-> <userinput>FROM pg_attribute</userinput>
|
-> <userinput>FROM pg_attribute</userinput>
|
||||||
-> <userinput>WHERE attrelid = 'my_table'::regclass AND attnum > 0</userinput>
|
-> <userinput>WHERE attrelid = 'my_table'::regclass AND attnum > 0</userinput>
|
||||||
-> <userinput>ORDER BY attnum</userinput>
|
-> <userinput>ORDER BY attnum</userinput>
|
||||||
@@ -2766,8 +2766,8 @@ hello 10
|
|||||||
-- check for the existence of two separate records in the database and store
|
-- check for the existence of two separate records in the database and store
|
||||||
-- the results in separate psql variables
|
-- the results in separate psql variables
|
||||||
SELECT
|
SELECT
|
||||||
EXISTS(SELECT 1 FROM customer WHERE customer_id = 123) as is_customer,
|
EXISTS (SELECT 1 FROM customer WHERE customer_id = 123) AS is_customer,
|
||||||
EXISTS(SELECT 1 FROM employee WHERE employee_id = 456) as is_employee
|
EXISTS (SELECT 1 FROM employee WHERE employee_id = 456) AS is_employee
|
||||||
\gset
|
\gset
|
||||||
\if :is_customer
|
\if :is_customer
|
||||||
SELECT * FROM customer WHERE customer_id = 123;
|
SELECT * FROM customer WHERE customer_id = 123;
|
||||||
@@ -4023,7 +4023,7 @@ SELECT 1 \bind \sendpipeline
|
|||||||
server as soon as it reaches the command-ending semicolon, even if
|
server as soon as it reaches the command-ending semicolon, even if
|
||||||
more input remains on the current line. Thus for example entering
|
more input remains on the current line. Thus for example entering
|
||||||
<programlisting>
|
<programlisting>
|
||||||
select 1; select 2; select 3;
|
SELECT 1; SELECT 2; SELECT 3;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
will result in the three SQL commands being individually sent to
|
will result in the three SQL commands being individually sent to
|
||||||
the server, with each one's results being displayed before
|
the server, with each one's results being displayed before
|
||||||
@@ -4032,7 +4032,7 @@ select 1; select 2; select 3;
|
|||||||
command before it and the one after are effectively combined and
|
command before it and the one after are effectively combined and
|
||||||
sent to the server in one request. So for example
|
sent to the server in one request. So for example
|
||||||
<programlisting>
|
<programlisting>
|
||||||
select 1\; select 2\; select 3;
|
SELECT 1\; SELECT 2\; SELECT 3;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
results in sending the three SQL commands to the server in a single
|
results in sending the three SQL commands to the server in a single
|
||||||
request, when the non-backslashed semicolon is reached.
|
request, when the non-backslashed semicolon is reached.
|
||||||
@@ -5581,7 +5581,7 @@ PSQL_EDITOR_LINENUMBER_ARG='--line '
|
|||||||
input. Notice the changing prompt:
|
input. Notice the changing prompt:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
testdb=> <userinput>CREATE TABLE my_table (</userinput>
|
testdb=> <userinput>CREATE TABLE my_table (</userinput>
|
||||||
testdb(> <userinput> first integer not null default 0,</userinput>
|
testdb(> <userinput> first integer NOT NULL DEFAULT 0,</userinput>
|
||||||
testdb(> <userinput> second text)</userinput>
|
testdb(> <userinput> second text)</userinput>
|
||||||
testdb-> <userinput>;</userinput>
|
testdb-> <userinput>;</userinput>
|
||||||
CREATE TABLE
|
CREATE TABLE
|
||||||
@@ -5770,8 +5770,8 @@ testdb=> <userinput>\crosstabview first second</userinput>
|
|||||||
This second example shows a multiplication table with rows sorted in reverse
|
This second example shows a multiplication table with rows sorted in reverse
|
||||||
numerical order and columns with an independent, ascending numerical order.
|
numerical order and columns with an independent, ascending numerical order.
|
||||||
<programlisting>
|
<programlisting>
|
||||||
testdb=> <userinput>SELECT t1.first as "A", t2.first+100 AS "B", t1.first*(t2.first+100) as "AxB",</userinput>
|
testdb=> <userinput>SELECT t1.first AS "A", t2.first+100 AS "B", t1.first*(t2.first+100) AS "AxB",</userinput>
|
||||||
testdb-> <userinput>row_number() over(order by t2.first) AS ord</userinput>
|
testdb-> <userinput>row_number() OVER (ORDER BY t2.first) AS ord</userinput>
|
||||||
testdb-> <userinput>FROM my_table t1 CROSS JOIN my_table t2 ORDER BY 1 DESC</userinput>
|
testdb-> <userinput>FROM my_table t1 CROSS JOIN my_table t2 ORDER BY 1 DESC</userinput>
|
||||||
testdb-> <userinput>\crosstabview "A" "B" "AxB" ord</userinput>
|
testdb-> <userinput>\crosstabview "A" "B" "AxB" ord</userinput>
|
||||||
A | 101 | 102 | 103 | 104
|
A | 101 | 102 | 103 | 104
|
||||||
|
|||||||
@@ -1927,7 +1927,7 @@ SELECT * FROM unnest(ARRAY['a','b','c','d','e','f']) WITH ORDINALITY;
|
|||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
WITH t AS (
|
WITH t AS (
|
||||||
SELECT random() as x FROM generate_series(1, 3)
|
SELECT random() AS x FROM generate_series(1, 3)
|
||||||
)
|
)
|
||||||
SELECT * FROM t
|
SELECT * FROM t
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
|||||||
@@ -968,7 +968,7 @@ CREATE MATERIALIZED VIEW sales_summary AS
|
|||||||
SELECT
|
SELECT
|
||||||
seller_no,
|
seller_no,
|
||||||
invoice_date,
|
invoice_date,
|
||||||
sum(invoice_amt)::numeric(13,2) as sales_amt
|
sum(invoice_amt)::numeric(13,2) AS sales_amt
|
||||||
FROM invoice
|
FROM invoice
|
||||||
WHERE invoice_date < CURRENT_DATE
|
WHERE invoice_date < CURRENT_DATE
|
||||||
GROUP BY
|
GROUP BY
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
when you fetch it? Watch:
|
when you fetch it? Watch:
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
test=> select 6.50 :: float8 as "pH";
|
test=> SELECT 6.50::float8 AS "pH";
|
||||||
pH
|
pH
|
||||||
---
|
---
|
||||||
6.5
|
6.5
|
||||||
@@ -72,7 +72,7 @@ test=> select 6.50 :: float8 as "pH";
|
|||||||
Check this out:
|
Check this out:
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
test=> select '6.25 .. 6.50'::seg as "pH";
|
test=> SELECT '6.25 .. 6.50'::seg AS "pH";
|
||||||
pH
|
pH
|
||||||
------------
|
------------
|
||||||
6.25 .. 6.50
|
6.25 .. 6.50
|
||||||
@@ -377,7 +377,7 @@ test=> select '6.25 .. 6.50'::seg as "pH";
|
|||||||
boundary if the resulting interval includes a power of ten:
|
boundary if the resulting interval includes a power of ten:
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
postgres=> select '10(+-)1'::seg as seg;
|
postgres=> SELECT '10(+-)1'::seg AS seg;
|
||||||
seg
|
seg
|
||||||
---------
|
---------
|
||||||
9.0 .. 11 -- should be: 9 .. 11
|
9.0 .. 11 -- should be: 9 .. 11
|
||||||
|
|||||||
@@ -613,7 +613,7 @@ postgres=# SELECT cid, cname, show_credit(cid) FROM customer;
|
|||||||
the original one. For example:
|
the original one. For example:
|
||||||
</para>
|
</para>
|
||||||
<screen>
|
<screen>
|
||||||
regression=# select sepgsql_getcon();
|
regression=# SELECT sepgsql_getcon();
|
||||||
sepgsql_getcon
|
sepgsql_getcon
|
||||||
-------------------------------------------------------
|
-------------------------------------------------------
|
||||||
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
|
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
|
||||||
|
|||||||
@@ -293,10 +293,10 @@ INSERT INTO ct(rowid, attribute, value) VALUES('test2','att4','val8');
|
|||||||
|
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM crosstab(
|
FROM crosstab(
|
||||||
'select rowid, attribute, value
|
'SELECT rowid, attribute, value
|
||||||
from ct
|
FROM ct
|
||||||
where attribute = ''att2'' or attribute = ''att3''
|
WHERE attribute = ''att2'' OR attribute = ''att3''
|
||||||
order by 1,2')
|
ORDER BY 1, 2')
|
||||||
AS ct(row_name text, category_1 text, category_2 text, category_3 text);
|
AS ct(row_name text, category_1 text, category_2 text, category_3 text);
|
||||||
|
|
||||||
row_name | category_1 | category_2 | category_3
|
row_name | category_1 | category_2 | category_3
|
||||||
@@ -371,10 +371,10 @@ CREATE TYPE tablefunc_crosstab_N AS (
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM crosstab3(
|
FROM crosstab3(
|
||||||
'select rowid, attribute, value
|
'SELECT rowid, attribute, value
|
||||||
from ct
|
FROM ct
|
||||||
where attribute = ''att2'' or attribute = ''att3''
|
WHERE attribute = ''att2'' OR attribute = ''att3''
|
||||||
order by 1,2');
|
ORDER BY 1, 2');
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@@ -407,7 +407,7 @@ CREATE TYPE my_crosstab_float8_5_cols AS (
|
|||||||
);
|
);
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION crosstab_float8_5_cols(text)
|
CREATE OR REPLACE FUNCTION crosstab_float8_5_cols(text)
|
||||||
RETURNS setof my_crosstab_float8_5_cols
|
RETURNS SETOF my_crosstab_float8_5_cols
|
||||||
AS '$libdir/tablefunc','crosstab' LANGUAGE C STABLE STRICT;
|
AS '$libdir/tablefunc','crosstab' LANGUAGE C STABLE STRICT;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
@@ -426,7 +426,7 @@ CREATE OR REPLACE FUNCTION crosstab_float8_5_cols(
|
|||||||
OUT my_category_3 float8,
|
OUT my_category_3 float8,
|
||||||
OUT my_category_4 float8,
|
OUT my_category_4 float8,
|
||||||
OUT my_category_5 float8)
|
OUT my_category_5 float8)
|
||||||
RETURNS setof record
|
RETURNS SETOF record
|
||||||
AS '$libdir/tablefunc','crosstab' LANGUAGE C STABLE STRICT;
|
AS '$libdir/tablefunc','crosstab' LANGUAGE C STABLE STRICT;
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</para>
|
</para>
|
||||||
@@ -572,18 +572,18 @@ row_name extra cat1 cat2 cat3 cat4
|
|||||||
<para>
|
<para>
|
||||||
Here are two complete examples:
|
Here are two complete examples:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
create table sales(year int, month int, qty int);
|
CREATE TABLE sales (year int, month int, qty int);
|
||||||
insert into sales values(2007, 1, 1000);
|
INSERT INTO sales VALUES (2007, 1, 1000);
|
||||||
insert into sales values(2007, 2, 1500);
|
INSERT INTO sales VALUES (2007, 2, 1500);
|
||||||
insert into sales values(2007, 7, 500);
|
INSERT INTO sales VALUES (2007, 7, 500);
|
||||||
insert into sales values(2007, 11, 1500);
|
INSERT INTO sales VALUES (2007, 11, 1500);
|
||||||
insert into sales values(2007, 12, 2000);
|
INSERT INTO sales VALUES (2007, 12, 2000);
|
||||||
insert into sales values(2008, 1, 1000);
|
INSERT INTO sales VALUES (2008, 1, 1000);
|
||||||
|
|
||||||
select * from crosstab(
|
SELECT * FROM crosstab(
|
||||||
'select year, month, qty from sales order by 1',
|
'SELECT year, month, qty FROM sales ORDER BY 1',
|
||||||
'select m from generate_series(1,12) m'
|
'SELECT m FROM generate_series(1, 12) m'
|
||||||
) as (
|
) AS (
|
||||||
year int,
|
year int,
|
||||||
"Jan" int,
|
"Jan" int,
|
||||||
"Feb" int,
|
"Feb" int,
|
||||||
|
|||||||
@@ -43,32 +43,32 @@
|
|||||||
A brief example of using the extension follows.
|
A brief example of using the extension follows.
|
||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
test=# create table tcndata
|
test=# CREATE TABLE tcndata
|
||||||
test-# (
|
test-# (
|
||||||
test(# a int not null,
|
test(# a int NOT NULL,
|
||||||
test(# b date not null,
|
test(# b date NOT NULL,
|
||||||
test(# c text,
|
test(# c text,
|
||||||
test(# primary key (a, b)
|
test(# PRIMARY KEY (a, b)
|
||||||
test(# );
|
test(# );
|
||||||
CREATE TABLE
|
CREATE TABLE
|
||||||
test=# create trigger tcndata_tcn_trigger
|
test=# CREATE TRIGGER tcndata_tcn_trigger
|
||||||
test-# after insert or update or delete on tcndata
|
test-# AFTER INSERT OR UPDATE OR DELETE ON tcndata
|
||||||
test-# for each row execute function triggered_change_notification();
|
test-# FOR EACH ROW EXECUTE FUNCTION triggered_change_notification();
|
||||||
CREATE TRIGGER
|
CREATE TRIGGER
|
||||||
test=# listen tcn;
|
test=# LISTEN tcn;
|
||||||
LISTEN
|
LISTEN
|
||||||
test=# insert into tcndata values (1, date '2012-12-22', 'one'),
|
test=# INSERT INTO tcndata VALUES (1, date '2012-12-22', 'one'),
|
||||||
test-# (1, date '2012-12-23', 'another'),
|
test-# (1, date '2012-12-23', 'another'),
|
||||||
test-# (2, date '2012-12-23', 'two');
|
test-# (2, date '2012-12-23', 'two');
|
||||||
INSERT 0 3
|
INSERT 0 3
|
||||||
Asynchronous notification "tcn" with payload ""tcndata",I,"a"='1',"b"='2012-12-22'" received from server process with PID 22770.
|
Asynchronous notification "tcn" with payload ""tcndata",I,"a"='1',"b"='2012-12-22'" received from server process with PID 22770.
|
||||||
Asynchronous notification "tcn" with payload ""tcndata",I,"a"='1',"b"='2012-12-23'" received from server process with PID 22770.
|
Asynchronous notification "tcn" with payload ""tcndata",I,"a"='1',"b"='2012-12-23'" received from server process with PID 22770.
|
||||||
Asynchronous notification "tcn" with payload ""tcndata",I,"a"='2',"b"='2012-12-23'" received from server process with PID 22770.
|
Asynchronous notification "tcn" with payload ""tcndata",I,"a"='2',"b"='2012-12-23'" received from server process with PID 22770.
|
||||||
test=# update tcndata set c = 'uno' where a = 1;
|
test=# UPDATE tcndata SET c = 'uno' WHERE a = 1;
|
||||||
UPDATE 2
|
UPDATE 2
|
||||||
Asynchronous notification "tcn" with payload ""tcndata",U,"a"='1',"b"='2012-12-22'" received from server process with PID 22770.
|
Asynchronous notification "tcn" with payload ""tcndata",U,"a"='1',"b"='2012-12-22'" received from server process with PID 22770.
|
||||||
Asynchronous notification "tcn" with payload ""tcndata",U,"a"='1',"b"='2012-12-23'" received from server process with PID 22770.
|
Asynchronous notification "tcn" with payload ""tcndata",U,"a"='1',"b"='2012-12-23'" received from server process with PID 22770.
|
||||||
test=# delete from tcndata where a = 1 and b = date '2012-12-22';
|
test=# DELETE FROM tcndata WHERE a = 1 AND b = date '2012-12-22';
|
||||||
DELETE 1
|
DELETE 1
|
||||||
Asynchronous notification "tcn" with payload ""tcndata",D,"a"='1',"b"='2012-12-22'" received from server process with PID 22770.
|
Asynchronous notification "tcn" with payload ""tcndata",D,"a"='1',"b"='2012-12-22'" received from server process with PID 22770.
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|||||||
@@ -1974,12 +1974,12 @@ SELECT title, body FROM messages WHERE tsv @@ to_tsquery('title & body');
|
|||||||
|
|
||||||
<programlisting>
|
<programlisting>
|
||||||
CREATE FUNCTION messages_trigger() RETURNS trigger AS $$
|
CREATE FUNCTION messages_trigger() RETURNS trigger AS $$
|
||||||
begin
|
BEGIN
|
||||||
new.tsv :=
|
new.tsv :=
|
||||||
setweight(to_tsvector('pg_catalog.english', coalesce(new.title,'')), 'A') ||
|
setweight(to_tsvector('pg_catalog.english', coalesce(new.title,'')), 'A') ||
|
||||||
setweight(to_tsvector('pg_catalog.english', coalesce(new.body,'')), 'D');
|
setweight(to_tsvector('pg_catalog.english', coalesce(new.body,'')), 'D');
|
||||||
return new;
|
RETURN new;
|
||||||
end
|
END
|
||||||
$$ LANGUAGE plpgsql;
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE
|
CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE
|
||||||
|
|||||||
@@ -490,7 +490,7 @@ SELECT ~ CAST('20' AS int8) AS "negation";
|
|||||||
Here is another example of resolving an operator with one known and one
|
Here is another example of resolving an operator with one known and one
|
||||||
unknown input:
|
unknown input:
|
||||||
<screen>
|
<screen>
|
||||||
SELECT array[1,2] <@ '{1,2,3}' as "is subset";
|
SELECT ARRAY[1, 2] <@ '{1,2,3}' AS "is subset";
|
||||||
|
|
||||||
is subset
|
is subset
|
||||||
-----------
|
-----------
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ mydb=# ALTER TEXT SEARCH DICTIONARY unaccent (RULES='my_rules');
|
|||||||
<para>
|
<para>
|
||||||
To test the dictionary, you can try:
|
To test the dictionary, you can try:
|
||||||
<programlisting>
|
<programlisting>
|
||||||
mydb=# select ts_lexize('unaccent','Hôtel');
|
mydb=# SELECT ts_lexize('unaccent', 'Hôtel');
|
||||||
ts_lexize
|
ts_lexize
|
||||||
-----------
|
-----------
|
||||||
{Hotel}
|
{Hotel}
|
||||||
@@ -160,19 +160,19 @@ mydb=# CREATE TEXT SEARCH CONFIGURATION fr ( COPY = french );
|
|||||||
mydb=# ALTER TEXT SEARCH CONFIGURATION fr
|
mydb=# ALTER TEXT SEARCH CONFIGURATION fr
|
||||||
ALTER MAPPING FOR hword, hword_part, word
|
ALTER MAPPING FOR hword, hword_part, word
|
||||||
WITH unaccent, french_stem;
|
WITH unaccent, french_stem;
|
||||||
mydb=# select to_tsvector('fr','Hôtels de la Mer');
|
mydb=# SELECT to_tsvector('fr', 'Hôtels de la Mer');
|
||||||
to_tsvector
|
to_tsvector
|
||||||
-------------------
|
-------------------
|
||||||
'hotel':1 'mer':4
|
'hotel':1 'mer':4
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
mydb=# select to_tsvector('fr','Hôtel de la Mer') @@ to_tsquery('fr','Hotels');
|
mydb=# SELECT to_tsvector('fr', 'Hôtel de la Mer') @@ to_tsquery('fr', 'Hotels');
|
||||||
?column?
|
?column?
|
||||||
----------
|
----------
|
||||||
t
|
t
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
mydb=# select ts_headline('fr','Hôtel de la Mer',to_tsquery('fr','Hotels'));
|
mydb=# SELECT ts_headline('fr', 'Hôtel de la Mer', to_tsquery('fr', 'Hotels'));
|
||||||
ts_headline
|
ts_headline
|
||||||
------------------------
|
------------------------
|
||||||
<b>Hôtel</b> de la Mer
|
<b>Hôtel</b> de la Mer
|
||||||
|
|||||||
@@ -1409,7 +1409,7 @@ DETAIL: A result of type anyelement requires at least one input of type anyelem
|
|||||||
For example:
|
For example:
|
||||||
<screen>
|
<screen>
|
||||||
CREATE FUNCTION dup (f1 anyelement, OUT f2 anyelement, OUT f3 anyarray)
|
CREATE FUNCTION dup (f1 anyelement, OUT f2 anyelement, OUT f3 anyarray)
|
||||||
AS 'select $1, array[$1,$1]' LANGUAGE SQL;
|
AS 'SELECT $1, ARRAY[$1, $1]' LANGUAGE SQL;
|
||||||
|
|
||||||
SELECT * FROM dup(22);
|
SELECT * FROM dup(22);
|
||||||
f2 | f3
|
f2 | f3
|
||||||
|
|||||||
Reference in New Issue
Block a user