Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit090dd22

Browse files
author
Thomas G. Lockhart
committed
Implement SQL99 OVERLAY(). Allows substitution of a substring in a string.
Implement SQL99 SIMILAR TO as a synonym for our existing operator "~".Implement SQL99 regular expression SUBSTRING(string FROM pat FOR escape). Extend the definition to make the FOR clause optional. Define textregexsubstr() to actually implement this feature.Update the regression test to include these new string features. All tests pass.Rename the regular expression support routines from "pg95_xxx" to "pg_xxx".Define CREATE CHARACTER SET in the parser per SQL99. No implementation yet.
1 parent469cb65 commit090dd22

File tree

4 files changed

+1800
-1692
lines changed

4 files changed

+1800
-1692
lines changed

‎doc/src/sgml/advanced.sgml

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/advanced.sgml,v 1.27 2002/02/12 22:25:15 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/advanced.sgml,v 1.28 2002/06/11 15:32:32 thomas Exp $
33
-->
44

55
<chapter id="tutorial-advanced">
@@ -46,14 +46,14 @@ $Header: /cvsroot/pgsql/doc/src/sgml/advanced.sgml,v 1.27 2002/02/12 22:25:15 mo
4646
<firstterm>view</firstterm> over the query, which gives a name to
4747
the query that you can refer to like an ordinary table.
4848

49-
<programlisting>
49+
<programlisting>
5050
CREATE VIEW myview AS
5151
SELECT city, temp_lo, temp_hi, prcp, date, location
5252
FROM weather, cities
5353
WHERE city = name;
5454

5555
SELECT * FROM myview;
56-
</programlisting>
56+
</programlisting>
5757
</para>
5858

5959
<para>
@@ -101,32 +101,30 @@ SELECT * FROM myview;
101101
<para>
102102
The new declaration of the tables would look like this:
103103

104-
<programlisting>
104+
<programlisting>
105105
CREATE TABLE cities (
106-
cityvarchar(80) primary key,
107-
locationpoint
106+
cityvarchar(80) primary key,
107+
locationpoint
108108
);
109109

110110
CREATE TABLE weather (
111-
cityvarchar(80) references cities,
112-
temp_loint,
113-
temp_hiint,
114-
prcpreal,
115-
datedate
111+
cityvarchar(80) references cities,
112+
temp_loint,
113+
temp_hiint,
114+
prcpreal,
115+
datedate
116116
);
117-
118-
</programlisting>
117+
</programlisting>
119118

120119
Now try inserting an invalid record:
121120

122-
<programlisting>
121+
<programlisting>
123122
INSERT INTO weather VALUES ('Berkeley', 45, 53, 0.0, '1994-11-28');
124-
</programlisting>
123+
</programlisting>
125124

126-
<screen>
125+
<screen>
127126
ERROR: &lt;unnamed&gt; referential integrity violation - key referenced from weather not found in cities
128-
</screen>
129-
127+
</screen>
130128
</para>
131129

132130
<para>
@@ -162,7 +160,8 @@ ERROR: &lt;unnamed&gt; referential integrity violation - key referenced from we
162160
Suppose that we want to record a payment of $100.00 from Alice's account
163161
to Bob's account. Simplifying outrageously, the SQL commands for this
164162
might look like
165-
<programlisting>
163+
164+
<programlisting>
166165
UPDATE accounts SET balance = balance - 100.00
167166
WHERE name = 'Alice';
168167
UPDATE branches SET balance = balance - 100.00
@@ -171,7 +170,10 @@ UPDATE accounts SET balance = balance + 100.00
171170
WHERE name = 'Bob';
172171
UPDATE branches SET balance = balance + 100.00
173172
WHERE name = (SELECT branch_name FROM accounts WHERE name = 'Bob');
174-
</programlisting>
173+
</programlisting>
174+
</para>
175+
176+
<para>
175177
The details of these commands are not important here; the important
176178
point is that there are several separate updates involved to accomplish
177179
this rather simple operation. Our bank's officers will want to be
@@ -219,13 +221,17 @@ UPDATE branches SET balance = balance + 100.00
219221
the SQL commands of the transaction with
220222
<command>BEGIN</> and <command>COMMIT</> commands. So our banking
221223
transaction would actually look like
222-
<programlisting>
224+
225+
<programlisting>
223226
BEGIN;
224227
UPDATE accounts SET balance = balance - 100.00
225228
WHERE name = 'Alice';
226229
-- etc etc
227230
COMMIT;
228-
</programlisting>
231+
</programlisting>
232+
</para>
233+
234+
<para>
229235
If, partway through the transaction, we decide we don't want to
230236
commit (perhaps we just noticed that Alice's balance went negative),
231237
we can issue the command <command>ROLLBACK</> instead of
@@ -272,25 +278,25 @@ COMMIT;
272278
implicitly when you list all cities. If you're really clever you
273279
might invent some scheme like this:
274280

275-
<programlisting>
281+
<programlisting>
276282
CREATE TABLE capitals (
277-
name text,
278-
population real,
279-
altitude int, -- (in ft)
280-
state char(2)
283+
name text,
284+
population real,
285+
altitude int, -- (in ft)
286+
state char(2)
281287
);
282288

283289
CREATE TABLE non_capitals (
284-
name text,
285-
population real,
286-
altitude int -- (in ft)
290+
name text,
291+
population real,
292+
altitude int -- (in ft)
287293
);
288294

289295
CREATE VIEW cities AS
290-
SELECT name, population, altitude FROM capitals
291-
UNION
292-
SELECT name, population, altitude FROM non_capitals;
293-
</programlisting>
296+
SELECT name, population, altitude FROM capitals
297+
UNION
298+
SELECT name, population, altitude FROM non_capitals;
299+
</programlisting>
294300

295301
This works OK as far as querying goes, but it gets ugly when you
296302
need to update several rows, to name one thing.
@@ -299,18 +305,20 @@ CREATE VIEW cities AS
299305
<para>
300306
A better solution is this:
301307

302-
<programlisting>
308+
<programlisting>
303309
CREATE TABLE cities (
304-
name text,
305-
population real,
306-
altitude int -- (in ft)
310+
name text,
311+
population real,
312+
altitude int -- (in ft)
307313
);
308314

309315
CREATE TABLE capitals (
310-
state char(2)
316+
state char(2)
311317
) INHERITS (cities);
312-
</programlisting>
318+
</programlisting>
319+
</para>
313320

321+
<para>
314322
In this case, a row of <classname>capitals</classname>
315323
<firstterm>inherits</firstterm> all columns (<structfield>name</>,
316324
<structfield>population</>, and <structfield>altitude</>) from its
@@ -328,42 +336,42 @@ CREATE TABLE capitals (
328336
including state capitals, that are located at an altitude
329337
over 500 ft.:
330338

331-
<programlisting>
339+
<programlisting>
332340
SELECT name, altitude
333-
FROM cities
334-
WHERE altitude &gt; 500;
335-
</programlisting>
341+
FROM cities
342+
WHERE altitude &gt; 500;
343+
</programlisting>
336344

337345
which returns:
338346

339-
<screen>
347+
<screen>
340348
name | altitude
341349
-----------+----------
342350
Las Vegas | 2174
343351
Mariposa | 1953
344352
Madison | 845
345353
(3 rows)
346-
</screen>
354+
</screen>
347355
</para>
348356

349357
<para>
350358
On the other hand, the following query finds
351359
all the cities that are not state capitals and
352360
are situated at an altitude of 500 ft. or higher:
353361

354-
<programlisting>
362+
<programlisting>
355363
SELECT name, altitude
356364
FROM ONLY cities
357365
WHERE altitude &gt; 500;
358-
</programlisting>
366+
</programlisting>
359367

360368
<screen>
361369
name | altitude
362370
-----------+----------
363371
Las Vegas | 2174
364372
Mariposa | 1953
365373
(2 rows)
366-
</screen>
374+
</screen>
367375
</para>
368376

369377
<para>
@@ -397,7 +405,6 @@ SELECT name, altitude
397405
site</ulink> for links to more resources.
398406
</para>
399407
</sect1>
400-
401408
</chapter>
402409

403410
<!-- Keep this comment at the end of the file

‎doc/src/sgml/datatype.sgml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.92 2002/05/03 04:11:07 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/datatype.sgml,v 1.93 2002/06/11 15:32:32 thomas Exp $
33
-->
44

55
<chapter id="datatype">
@@ -2637,7 +2637,8 @@ SELECT * FROM test1 WHERE a;
26372637
The <type>inet</type> type holds an IP host address, and
26382638
optionally the identity of the subnet it is in, all in one field.
26392639
The subnet identity is represented by the number of bits in the
2640-
network part of the address (the <quote>netmask</quote>). If the netmask is 32,
2640+
network part of the address (the <quote>netmask</quote>). If the
2641+
netmask is 32,
26412642
then the value does not indicate a subnet, only a single host.
26422643
Note that if you want to accept networks only, you should use the
26432644
<type>cidr</type> type rather than <type>inet</type>.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp