Jed Rembold
Monday, November 11, 2024
What would the output of the below query look like?
SELECT regexp_split_to_table(
'01-13-2021, 04-24-2022', '[,-]\s*') AS rev;
| rev |
|---|
| 01 |
| 13 |
| 2021 |
| 04 |
| 24 |
| 2022 |
| rev |
|---|
| 01-13-2021 |
| 04-24-2022 |
| rev |
|---|
| 01 |
| 13 |
| 2021, 04 |
| 24 |
| 2022 |
| rev |
|---|
| 01 |
| 13 |
| 2021 |
| “” |
| 04 |
| 24 |
| 2022 |
The file here contains the
SQL commands to generate and populate a simple table
alice which hold the raw chapter contents of
the book: Alice in Wonderland. You will need to set up your own
tsvector column and index. With your
neighbors, see if you can use the data to answer the following:
Unlike the tablefunc extension,
PostGIS does not generally come with plain
Postgres by default
The PostGIS extension will bring in a lot of extra functions and
data types, so you might consider creating a new database to contain GIS
type data (maybe analysis_gis)
Adding the extension to the database is the same as with other extensions:
CREATE EXTENSION postgis;| Type | Format | Comments |
|---|---|---|
Point |
'POINT (-74.9 42.7)' |
No comma separating, and longitude comes first! |
LineString |
'LINESTRING (-74.9 42.7, -75.1 42.7)' |
Comma separates coordinate pairs |
Polygon |
'POLYGON((74 42, 75 42, 76 43, 74 42))' |
Double parentheses, initial point repeated to close |
MultiPoint |
'MULTIPOINT(75 42, 74 43)' |
Comma separates coordinate pairs |
MultiLineString |
'MULTILINESTRING((76 43, 77 43), (78 43, 77 43))' |
Parentheses group individual lines |
MultiPolygon |
'MULTIPOLYGON(((74 43, 75 44, 74 45, 74 43), (81 40, 81 39, 82 39, 81 40)))' |
Still double parentheses to start and end, with 3rd parentheses grouping polygons |
spatial_ref_sys table, so you can query to
find necessary SRIDsgeography
geometry
Two main methods of creating geography or geometry types:
ST_GeomFromText(WKT, SRID) creates a
geometry object to hold the spatial object given by the WKT with the
optional given SRID
ST_GeogFromText(WKT, SRID) creates a
geography object to hold the spatial object given by the WKT with the
optional given SRID
If you look at the output of one of these data types, it is not human-readable
SELECT ST_GeogFromText('POINT(-75 42)');
>> 0101000020E61000000000000000C052C00000000000004540
SELECT ST_GeomFromText('POINT(-75 42)', 4326);ST_MakePoint(|||long|||, |||lat|||, [|||z|||,|||m|||])
will create a geometric point with optional 3rd or 4th dimensions as
wellST_MakeLine(|||point1|||, |||point2|||)
will create a line from the first point to the second. There is an array
option as well.ST_MakePolygon(|||geometry_linestring|||, [|||cutout_linestring|||])
will create a geometric polygon using the provided linestring with
optional cutoutsST_SetSRID(|||object|||, |||SRID|||) will
attach the given SRID metadata to the objectCREATE INDEX |||index_name|||
ON |||table|||
USING GIST (|||column|||);
ST_DWithin(|||point1|||, |||point2|||, |||distance|||)
returns a True or False depending on whether the two points are within
the given distance from one another
ST_Distance(|||point1|||, |||point2|||)
computes the distance between the two points