Download Complete Leveling Up with SQL: Advanced Techniques for Transforming Data into Insights Mark Simon PDF for All Chapters
Download Complete Leveling Up with SQL: Advanced Techniques for Transforming Data into Insights Mark Simon PDF for All Chapters
https://ebookmass.com
https://ebookmass.com/product/leveling-up-with-
sql-advanced-techniques-for-transforming-data-
into-insights-mark-simon/
https://ebookmass.com/product/getting-started-with-sql-and-databases-
managing-and-manipulating-data-with-sql-mark-simon/
testbankdeal.com
https://ebookmass.com/product/getting-started-with-sql-and-databases-
managing-and-manipulating-data-with-sql-1st-edition-mark-simon/
testbankdeal.com
https://ebookmass.com/product/magical-midlife-awakening-leveling-up-
book-10-k-f-breene/
testbankdeal.com
https://ebookmass.com/product/data-universe-organizational-insights-
with-python-embracing-data-driven-decision-making-van-der-post/
testbankdeal.com
https://ebookmass.com/product/insights-from-data-with-r-an-
introduction-for-the-life-and-environmental-sciences-owen-l-petchey/
testbankdeal.com
Mark Simon
Leveling Up with SQL: Advanced Techniques for Transforming Data into Insights
Mark Simon
Ivanhoe VIC, VIC, Australia
Introduction������������������������������������������������������������������������������������������������������������xix
v
Table of Contents
vi
Table of Contents
One-to-One Relationships����������������������������������������������������������������������������������������������������������� 72
One-to-Maybe Relationships������������������������������������������������������������������������������������������������� 72
Multiple Values���������������������������������������������������������������������������������������������������������������������������� 76
Many-to-Many Relationships������������������������������������������������������������������������������������������������ 77
Joining Many-to-Many Tables����������������������������������������������������������������������������������������������� 82
Summarizing Multiple Values������������������������������������������������������������������������������������������������ 84
Combining the Joins�������������������������������������������������������������������������������������������������������������� 86
Many-to-Many Relationships Happen All the Time���������������������������������������������������������������� 90
Another Many-to-Many Example������������������������������������������������������������������������������������������������ 90
Inserting into Related Tables������������������������������������������������������������������������������������������������������� 93
Adding a Book and an Author������������������������������������������������������������������������������������������������ 94
Adding a New Sale���������������������������������������������������������������������������������������������������������������� 98
Review�������������������������������������������������������������������������������������������������������������������������������������� 102
Types of Relationships��������������������������������������������������������������������������������������������������������� 103
Joining Tables���������������������������������������������������������������������������������������������������������������������� 103
Views����������������������������������������������������������������������������������������������������������������������������������� 104
Inserting into Related Tables����������������������������������������������������������������������������������������������� 104
Summary���������������������������������������������������������������������������������������������������������������������������������� 104
Coming Up��������������������������������������������������������������������������������������������������������������������������������� 104
vii
Table of Contents
viii
Table of Contents
ix
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
Table of Contents
x
Table of Contents
xi
Table of Contents
Summary���������������������������������������������������������������������������������������������������������������������������������� 364
Simple CTEs������������������������������������������������������������������������������������������������������������������������� 364
Parameter Names���������������������������������������������������������������������������������������������������������������� 365
Multiple CTEs����������������������������������������������������������������������������������������������������������������������� 365
Recursive CTEs�������������������������������������������������������������������������������������������������������������������� 365
Coming Up��������������������������������������������������������������������������������������������������������������������������������� 365
Chapter 10: More Techniques: Triggers, Pivot Tables, and Variables������������������� 367
Understanding Triggers������������������������������������������������������������������������������������������������������������� 368
Some Trigger Basics������������������������������������������������������������������������������������������������������������ 369
Preparing the Data to Be Archived�������������������������������������������������������������������������������������� 370
Creating the Trigger������������������������������������������������������������������������������������������������������������� 372
Pros and Cons of Triggers���������������������������������������������������������������������������������������������������� 380
Pivoting Data����������������������������������������������������������������������������������������������������������������������������� 381
Pivoting the Data����������������������������������������������������������������������������������������������������������������� 382
Manually Pivoting Data�������������������������������������������������������������������������������������������������������� 384
Using the Pivot Feature (MSSQL, Oracle)����������������������������������������������������������������������������� 389
Working with SQL Variables������������������������������������������������������������������������������������������������������ 394
Code Blocks������������������������������������������������������������������������������������������������������������������������� 395
Updated Code to Add a Sale������������������������������������������������������������������������������������������������ 396
Review�������������������������������������������������������������������������������������������������������������������������������������� 404
Triggers�������������������������������������������������������������������������������������������������������������������������������� 404
Pivot Tables�������������������������������������������������������������������������������������������������������������������������� 405
SQL Variables����������������������������������������������������������������������������������������������������������������������� 405
Summary���������������������������������������������������������������������������������������������������������������������������������� 406
Index��������������������������������������������������������������������������������������������������������������������� 443
xii
About the Author
Mark Simon has been involved in training and education
since the beginning of his career. He started as a teacher
of mathematics, but quickly pivoted into IT consultancy
and training because computers are much easier to work
with than high school students. He has worked with and
trained in several programming and coding languages and
currently focuses mainly on web development and database
languages. When not involved in work, you will generally
find him listening to or playing music, reading, or just
wandering about.
xiii
About the Technical Reviewer
Aaditya Pokkunuri is an experienced senior cloud database
engineer with a demonstrated history of working in the
information technology and services industry with 13 years
of experience.
He is skilled in performance tuning, MS SQL Database
Server Administration, SSIS, SSRS, PowerBI, and SQL
development.
He possesses in-depth knowledge of replication,
clustering, SQL Server high availability options, and ITIL
processes.
His expertise lies in Windows administration tasks, Active Directory, and Microsoft
Azure technologies.
He also has extensive knowledge of MySQL, MariaDB, and MySQL Aurora database
engines.
He has expertise in AWS Cloud and is an AWS Solution Architect Associate and AWS
Database Specialty.
Aaditya is a strong information technology professional with a Bachelor of Technology
in Computer Science and Engineering from Sastra University, Tamil Nadu.
xv
Acknowledgments
The sample data includes information about books and authors from Goodreads
(www.goodreads.com/), particularly from their lists of classical literature over the past
centuries. Additional author information was obtained, of course, from Wikipedia
(www.wikipedia.org/).
The author makes no guarantees about whether the information was correct or even
copied correctly. Certainly, the list of books should not in any way be interpreted as an
endorsement or even an indication of personal taste. After all, it’s just sample data.
xvii
Introduction
In the early 1970s, a new design for managing databases was being developed based on
the original work of E. F. Codd. The underlying model was known as the relational model
and described a way of collecting data and accessing and manipulating data using
mathematical principles.
Over the decade, the SQL language was developed, and, though it doesn’t follow the
relational model completely, it attempts to make the database accessible using a simple
language.
The SQL language has been improved, enhanced, and further developed over the
years, and in the late 1980s, the language was developed into a standard of both ANSI
(the American National Standards Institute) and ISO (the International Organization for
Standardization, and, that’s right, it doesn’t spell ISO).
The takeaways from this very brief history are
• SQL is a developing language, and there are new features and new
techniques being added all the time.
The second half of the third point is worth stressing. Nobody quite sticks to the SQL
standards. There are many reasons for this, some good, some bad. But you’ll probably
find that the various dialects of SQL are about 80–90% compatible, and the rest we’ll fill
you in on as we go.
In this book, you’ll learn about using SQL to a level which goes beyond the basics.
Some things you’ll learn about are newer features in SQL; some are older features that
you may not have known about. We’ll look at a few non-standard features, and we’ll also
look at using features that you already know about, but in more powerful ways.
This book is not for the raw beginner—we assume you have some knowledge and
experience in SQL. If you are a raw beginner, then you will get more from my previous
xix
Introduction
book, Getting Started with SQL and Databases;1 you can then return to this book full of
confidence and enthusiasm with a good solid grounding in SQL.
If you have the knowledge and experience, the first chapter will give you a quick
overview of the sort of knowledge you should have.
The first chapter will go into the details of getting your DBMS software and sample
database ready. It will also give you an overview of the story behind the sample database.
Notes
While you’re writing SQL to work with the data, there’s a piece of software at the other
end responding to the SQL. That software is referred to generically as a database server,
and, more specifically, as a DataBase Management System, or DBMS to its friends. We’ll
be using that term throughout the book.
The DBMSs we’ll be covering are PostgreSQL, MariaDB, MySQL, Microsoft SQL
Server, SQLite, and Oracle. We’ll assume that you’re working with reasonably current
versions of the DBMSs.
Chapter 1 will go into more details on setting up your DBMS, as well as downloading
and installing the sample database.
Source Code
All source code used in this book can be downloaded from github.com/apress/
leveling-up-sql.
1
https://link.springer.com/book/978148429494.
xx
CHAPTER 1
Getting Ready
If you’re reading this book, you’ll already know some SQL, either through previous study
or through bitter experience, or, more likely, a little of both. In the process, there may be
a few bits that you’ve missed, or forgotten, or couldn’t see the point.
We’ll assume that you’re comfortable enough with SQL to get the basic things
done, which mostly involves fetching data from one or more tables. You may even have
manipulated some of that data or even the tables themselves.
We won’t assume that you consider yourself an expert in all of this. Have a look in
the section “What You Probably Know Already” to check the sort of experience we think
you already have. If there are some areas you’re not completely sure about, don’t panic.
Each chapter will include some of the background concepts which should take you to
the next level.
If all of this is a bit new to you, perhaps we can recommend an introductory book. It’s
called Getting Started with SQL and Databases by Mark Simon, and you can learn more
about it at https://link.springer.com/book/10.1007/978-1-4842-9493-2.
• BookWorks will then procure the books and ship them to customers
at some point.
1
© Mark Simon 2023
M. Simon, Leveling Up with SQL, https://doi.org/10.1007/978-1-4842-9685-1_1
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
Chapter 1 Getting Ready
To manage all of this, the database tables look something like Figure 1-1.
In real life, there’s more to the story. For example, we haven’t included payment or
shipping methods, and we haven’t included login credentials. There’s no stock either,
although we’ll presume that the books are ordered on demand.
But there’s enough in this database for us to work with as we develop and improve
our SQL skills.
2
Chapter 1 Getting Ready
Setting Up
You can sit in a comfortable chair with a glass of your favorite refreshment and a box of
nice chocolates and read this book from cover to cover. However, you’ll get more from
this book if you join in on the samples.
• PostgreSQL
• MariaDB/MySQL
• SQLite
• Oracle
PostgreSQL, MariaDB/MySQL, and SQLite are all free. Microsoft SQL Server and
Oracle are paid products, but have free versions.
MariaDB is a spin-off of MySQL, which is why they’re treated together. They are
almost identical in features, but you’ll find a few places where they’re not identical.
3
Random documents with unrelated
content Scribd suggests to you:
of which I had never entertained the slightest hope, my joyful
emotions at the bare idea, could only be equalled by my surprise at
such an intimation. It immediately struck me that the latter was the
result of preconcertion between Governor King and Mr. Marsden,
and that it was at the bottom, his Excellency’s wish to render me this
essential service. The sequel proved that my conjectures were not
unfounded, for it afterwards appeared that Governor King having an
incredible number of public documents lying in a state of great
confusion, and most of which he wanted copied prior to delivering
them up, it was indispensably necessary that he should have an
expeditious and experienced clerk, to transcribe and arrange such
papers, during his voyage home; and it seems he knew of no person
more eligible for such an employment than myself. I replied to Mr.
Marsden, with a warmth and earnestness which convinced him how
happy such an arrangement would make me, and assured him of my
everlasting gratitude towards himself and the late Governor for their
consideration; earnestly pressing Mr. Marsden to a speedy
“consummation” of what I so “devoutly wished.” The anxiety of mind
produced in me by this conversation may be conceived by the
reader, if he reflects upon the situation in which I was then placed;
for, though it was my chief and ardent wish to return to my native
land as soon as I became free, yet as I had no apparent prospect of
realizing money enough to pay my passage, and the hardships
incidental to working for it, would expose me to the most trying
severities, such an opportunity as the one I now contemplated, could
not be too highly appreciated, or too eagerly embraced.
CHAPTER XVII.
The Buffalo being ready for Sea, I receive an Intimation from Mr. Marsden, that the
late Governor has obtained a Remission of my unexpired Time, and consents
to take me home as his Clerk.—I wait on his Excellency accordingly, and
receive orders to go on board.—We set sail.
The process of fitting out and victualling the Buffalo, with other
causes, delayed the Governor’s departure for some weeks after the
appointed time. At length I received, about the first of February, in a
note from Mr. Marsden, (who with his family, had removed to Sydney,
in readiness for embarkation,) the agreeable tidings that Governor
King had consented to take me on board the Buffalo, in the capacity
of his private clerk, and had obtained the sanction of Governor Bligh
for my departure from the colony. Mr. Marsden concluded with
advising me to wait on Governor King without delay, for the purpose
of receiving his commands. I immediately hastened to Sydney, and
waited on his Excellency; who after some conversation, told me that
the Buffalo’s complement being already full, it was not in his power to
put me on the ship’s books[45], but that he would give me a passage,
and himself supply me with provisions. He then inquired if I was
incumbered with any debts; and, on my answering that I owed to
individuals about twenty pounds, and to Government, for various
articles from the stores, about fifteen pounds, his Excellency advised
me to take measures for settling these accompts, and, having so
done, to repair on board with the least possible delay. I now returned
to Parramatta, (having first given the usual notice of my departure for
publication in the Sydney Gazette,) and applied with diligence to the
settlement of my affairs. I was not displeased at the Governor’s
intimation respecting not putting me on the Buffalo’s books, because,
had he so done, it being war time, I might have found a difficulty in
getting clear of her on our arrival in England: on the other hand, by
going home as a passenger, although I should forego the advantage
of pay, for the time occupied in our voyage, yet I should be at liberty
to quit the ship the moment we anchored. I was not altogether so
easy with respect to my debts, as I feared my utmost means were
inadequate to their liquidation. ’Tis true, I had a watch, some good
clothes, and other effects, which altogether might suffice to
discharge my private debts, but then I should much distress myself
by the deprival of these useful articles. As to my Government debt, I
had a secret hope that the generosity of Governor King (which was
often conspicuous when his privy purse was not encroached upon,)
would induce him to assist me in surmounting that difficulty.
I lost not a moment in settling my business at Parramatta, and
returning to Sydney with all my worldly goods, I waited on my
principal creditor, with whom I managed to square the yards on
tolerably easy terms. I was obliged, however, to dispose of nearly all
my personal effects, before I could satisfy the private demands upon
me, retaining only a very limited stock of indispensable articles for
my voyage, and one genteel suit of clothes for the purpose of attiring
myself on quitting the ship, together with an English half-guinea to
bear my expenses from Portsmouth to London. Having taken these
measures, I embarked with my chest and bedding on the 5th of
February, Governor King and Mr. Marsden with their respective
families, being already on board. His Excellency hearing of my
arrival, sent for me to his cabin, and questioned me on the subject of
my debts. I informed him, that I had discharged every claim upon
me, except the sum I owed to the Crown, and confessed my inability
to liquidate that account, without some extension of his Excellency’s
kind assistance. The Governor after some moments’ reflection, wrote
a short memorandum, which he ordered me to take to Mr.
Commissary Palmer, to whom it was addressed. I accordingly went
on shore, and proceeding to the Commissary’s office, delivered the
note, which Mr. Palmer having read, handed to one of his clerks,
directing him to comply with the tenor of it, which was to the following
effect:—“James Vaux (the bearer) having behaved well in the
different situations of store-keeper’s, secretary’s, and magistrate’s
clerk, I think the small sum he stands indebted to Government ought
to be remitted him.” (Signed) “P. G. K.” The clerk having turned to my
account in the ledger, gave me credit therein, to the amount of my
debt, by an item worded as follows:—“By remuneration for services
as clerk, &c.” This point being adjusted, I now found myself perfectly
disembarrassed, and free to depart the country. With a joyful heart, I
took leave of my old acquaintances and fellow-clerks, with some of
whom I spent a convivial evening, and the next day I finally
embarked, all things being now in readiness, and the ship only
waiting the auspicious breeze. On the 10th of February, 1807, was
the happy day. At an early hour the ship was crowded with visiters,
comprising most of the principal officers of the colony, with their
ladies and friends, as well as many respectable inhabitants, all
anxious to testify their heartfelt respect towards a departing
Governor, whose general conduct had gained him universal esteem,
and who had, during a government of six years, united the
tenderness of a parent with the authority of a chief. The vessel was
surrounded with boats, some of which brought various friends of the
ship’s company, passengers, &c., who came to take a last farewell;
others contained spectators of both sexes, attracted by curiosity to
witness the interesting scene, as well as to shew their loyalty and
good wishes by joining in the parting cheers, with which the air
resounded as we cleared the heads of the harbour, to which distance
most of the boats accompanied us. About three o’clock P. M. the
breeze freshening, we quickly gained a good offing, and by half past
four a sudden squall, attended with rain and mist, obscured from us
all view of the land, which we beheld no more.
CHAPTER XVIII.
Receive a free Pardon from the hands of Captain (late Governor) King.—Account
of our Passage Home.—Suffer a great deal from the want of Provisions.—
Leaky State of the Ship.—Double Cape Horn.—Fall in with an English Frigate,
bound to the River Plate.—Arrive at Rio de Janeiro.
The morning after our sailing, Captain King, (as I shall in future
style him,) called me into his cabin, and presented me with a free
pardon, which, as he rightly observed, was merely a matter of form,
as it was probable we should not arrive in England before the
expiration of my time. This instrument, though only made out a few
days before, was ante-dated the 12th of August, 1806, being the day
before Governor Bligh assumed the command, and was
consequently the last official document, to which Governor King had
affixed his signature, and the last public act of his government.
In about a week, we made the island of New Zealand, at which it
was captain King’s intention to have touched, having some live pigs,
brought from Port Jackson, for the purpose of presenting to the
native chiefs, two of whom had lately visited, and resided for some
months in New South Wales; but this kind idea was frustrated by a
squall of wind, which took us aback while in sight of the island, and
night coming on, it was not considered prudent to approach the land;
we therefore hauled our wind, and shaped our course to the
southward.
Captain King had given orders to the ship’s steward, that I should
receive his (Captain King’s) own ration of provisions, on which I was
to subsist as well as I could. This quota (according to the usual
allowance of the navy,) would have been amply sufficient, but by
some unaccountable want of management, the Buffalo,
notwithstanding the length of time occupied in preparation, was at
last sent to sea with a very limited supply of provisions; nor was what
she really had of the kind or quality invariably allowed in the King’s
service; the consequence was, that on the very day of our sailing, all
hands were put upon half-allowance of bread, (that is, half a pound
per day,) and the other half of rice: this latter grain was also
substituted on banyan days for pease and for oatmeal: of cheese
and butter we were also destitute; so that we had not a prospect of
much good living before us. Of the rice, the crew soon became so
much tired, that they ceased to draw any from the purser, leaving it
in his hands, to be compensated for at the end of our voyage. The
salt-meat was also barely adequate to the computed length of our
passage to Rio de Janeiro, the first port at which we could hope for a
further supply. The reader will allow that half a pound of bread was
little enough for a man’s daily ration, (being just two biscuits) but ere
we had been six weeks at sea, it was found necessary to reduce the
allowance to one-third of a pound; and, in a few weeks more, it was
lowered to one quarter, that is, a biscuit a day! The necessity of
these reductions arose from a discovery that the rats, cockroaches,
and other vermin, with which the ship was infested, had made a
most destructive devastation in the bread-room, besides which, a
leak in the side had admitted so much salt-water, that a great many
bags of biscuit were totally spoiled, thereby adding to our distress,
which was before sufficiently great. Even the small portion of bread
we did receive, was scarcely eatable, most of it being very old
stores, and full of maggots, and what was baked in the colony being
of a very coarse quality, and every biscuit more or less excavated by
the vermin before-mentioned. The Buffalo, as I have before shewn,
was detained several months, for the purpose of being properly
victualled, and after all, the purser had been obliged to take a
quantity of wheat in casks, for consumption in some shape or other,
as it was found inexpedient to wait longer for a further supply of
biscuit. This wheat, when the crew were tired of rice, was boiled in
lieu of pease, and served out at dinner-time, but it was so
unpalatable a mess, that I, among many others, could never
stomach it, being thrown into the coppers, dust and all, boiled in
stinking water, and when taken up, it was nearly as hard as when
first put in, and much inferior to the food of pigs in England. The
ship’s company at length were convinced of their folly, in suffering
such a mode of cookery, or rather waste, for very few could eat it;
and, there being luckily a steel-mill on board, it was ordered to be put
up in the after gun-room, and every mess in the ship, in its turn,
ground the next day’s portion of wheat over night, and sifting the
meal, produced a bag of tolerable flour, of which the cook composed
a certain food for breakfast, known among sailors by the name of
skilligolee, being, in plain English, paste, similar to that used by the
sons of Crispin, only not quite of so thick a consistence: however, it
was much preferable to the hog-wash before-mentioned, and, with a
little sugar, served as an apology for a meal.
I have before observed, that I drew Captain King’s ration of
provisions, but he withheld the daily allowance of spirits, forming part
of the said ration, which he himself received, and deposited in his
private liquor-case. It is, however, probable that his lady, who was a
rigid economist, was the suggester of this practice. By way of
composition, this good lady gave directions that I should receive a
dram every day from her own steward. This trifling indulgence by the
by, was not ordered me, until the severity of the climate compelled
me to give a hint on the subject, and after about three week’s
continuance it was put a stop to, on pretence of the stock becoming
low. Upon the whole, I suffered a great deal from the scantiness, as
well as the quality of my allowance, and the want of certain comforts
to which I had been accustomed, particularly during the severe
weather which we encountered in our voyage round Cape Horn. It
soon appeared that I was not to eat the bread of idleness; I was
employed from morning till night in copying and arranging Captain
King’s papers, of which he had several large trunks full. I had also
the tuition of his daughter Miss King, who was about twelve years of
age, and performed the same duty towards Mr. Marsden’s two
children, as well as a native boy about fourteen, who had been
brought up in the family of Mr. Marsden. This youth had received the
rudiments of a good education, and discovered a most susceptible
genius. He could read and write tolerably well, was perfectly docile,
and well-behaved, and would doubtless have been an object of
general admiration, and reflected the highest credit on his humane
benefactors had he ever reached England, but unhappily during our
stay at Rio Janeiro, he absconded from the house of his protectors,
in consequence of some chastisement for misconduct, and,
notwithstanding every exertion was used, he could not be recovered
before the ship’s departure.
To add to our sufferings from the dearth of provisions, we had not
been a month at sea, before the ship was discovered to be in a very
leaky state, and these leaks increased so rapidly, that she at length
made above five feet water in the well, every four hours.
As we approached the higher latitudes, the climate became every
day more intensely cold, and we had continual tempestuous gales
for several weeks, but fortunately they were from the right quarter, so
that we were in general before the wind, and, considering that our
ship was a very heavy sailer, made a pretty rapid progress.
On the 10th of March, having reached a certain degree of
longitude, I witnessed the remarkable circumstance of gaining a day,
the consequence of circumnavigating the globe. The effect was, that
the following day, as well as this, was called in the ship’s log, the
10th of March, so that we had actually two Tuesdays in one week!
This was a favourable circumstance in one respect to myself and the
ship’s company, for as Tuesday is a sumptuous day in point of
allowance in the navy, beef and pudding being the prescribed fare
for dinner, we by this accident feasted two days together; whereas
had it occurred on a Monday, Wednesday, or Friday, two successive
banyan (or starvation) days would have been our dismal portion. On
our arrival in England our account of time after this alteration,
corresponded exactly with the almanack for the year.
On the 15th of March, we rounded Cape Horn, passing within five
miles of that inhospitable shore. This point of the American
continent, is situated in fifty-six degrees of south latitude, and had we
passed it in the winter season, instead of the autumn, the cold would
have been hardly bearable; as it was, it had the effect of destroying
almost every natural production of New South Wales, with some very
fine specimens of which our ship was at first literally crowded, so as
to resemble Noah’s Ark. There were kangaroos, black swans, a
noble emu, and cockatoos, parrots, and smaller birds without
number; all of which, except one cockatoo, which was carefully
nursed by its mistress, and half a dozen swans, fell victims to the
severity of the weather. The latter birds, indeed, being natives of Van
Diemen’s Land, which is a colder climate than Port Jackson, were of
a hardy nature, and survived our long and tedious voyage. On their
arrival in England, they were sent by Captain King as a present to
the Royal Menagerie in Kew-gardens.
In our passage round Cape Horn, we had frequent storms of
snow; a native of New Zealand, who had been for some time on
board the Buffalo, and was a very active intelligent fellow, expressed
the utmost surprise on observing a phenomenon, which in the happy
clime of his nativity is never experienced, and in the first emotions of
his admiration, exclaimed, “Look, look, white rain, white rain!” This
man would have been an object of curiosity in England, for he had a
very handsome person, and was punctured or tattooed in a most
fanciful and extraordinary manner from head to foot, including his
face, which was covered with ornamental devices; but unhappily he
contracted the small-pox, which, notwithstanding all possible
attention, carried him off before we arrived at the Brazils.
I must not omit a remarkable and awful phenomenon, which
occurred during this part of our passage. In the middle of a
tempestuous night, a sudden concussion was heard, resembling the
report of a cannon close to us; it alarmed three parts of the people
who were below asleep, as well as the watch on deck; and the
general opinion was at first, that a ship was close aboard us. Every
one hurried upon deck, when the cause was found to have been,
what is called a Fire-ball, which had been probably attracted by the
spindle at the mast-head, for it made a rapid descent down the main-
mast, exploded at the break of the quarter-deck; the concussion had
knocked down a quarter-master who stood near the binnacle, and
two men who were at the wheel. The former was for some minutes
insensible, but happily they were no further injured than by the fright.
Captain King was instantly on deck with his usual promptness, and
fearing the effects of the fire, gave orders to cover the magazine-
scuttle with wet-swabs; then to sound the pump-well, for some were
in dread of the ball having gone through the ship’s bottom: however,
it appeared the ship made only the usual quantity of water, and that
no real injury was sustained. Another night, as we were scudding
before a heavy gale of wind, and a tremendous sea rolling after us,
we had the misfortune to be pooped, as the phrase is, by a wave or
sea striking our stern, which stove in the cabin-windows, and rushing
impetuously through the cabin, and along the main-deck, bore down
all before it. Luckily no farther damage was done than breaking the
windows, which rendered it necessary to put up the dead-lights
during the remainder of the passage.
When within a day or two’s sail of the River Plate, as we were
running down the coast of Brazil, we fell in with a frigate, which, on
hailing, we found to be His Majesty’s ship Thisbe, bound to Buenos
Ayres, having on board, General Whitelocke and his staff. This
officer was going to conduct the attack upon the city above
mentioned, as well as upon Monte Video, both belonging to the
Spaniards. A formidable expedition had been fitted out in England for
the service, and a numerous army was already collected in the River
Plate, waiting the arrival of General Whitelocke. Captain King
complimented this officer with a visit on board the Thisbe, which the
latter returned. On arriving abreast of the River Plate, the Thisbe
parted from us, steering for the entrance of that river, and we
continued our course along-shore. In a few days we came in sight of
Rio de Janeiro, but were becalmed for two days in sight of the port.
At length, on the 22d of May, we entered that beautiful harbour, after
a most hazardous and blowing passage of fifteen weeks. It was
remarkable that on the day before we got in, the last biscuit was
issued to the ship’s company, and the last cask of salt-meat we
possessed, was broached; so that had our passage been longer
protracted, we must have endured still greater privations.
CHAPTER XIX.
Account of my Adventures at San Sebastian.—Form acquaintance with a
Portuguese Family.—Their Affection for me.—Overtures made to induce my
Stay in South America;—The Ship being repaired and victualled, we re-
embark and sail for Europe.