From 643bf5029f75d32890344332e4923607843874a0 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 15 Apr 2016 22:01:39 -0500 Subject: [PATCH] Add Show All Versions Of An Operator as a postgres til --- README.md | 1 + postgres/show-all-versions-of-an-operator.md | 36 ++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 postgres/show-all-versions-of-an-operator.md diff --git a/README.md b/README.md index c23bb41..0c929d1 100644 --- a/README.md +++ b/README.md @@ -218,6 +218,7 @@ _392 TILs and counting..._ - [Set Inclusion With hstore](postgres/set-inclusion-with-hstore.md) - [Set A Seed For The Random Number Generator](postgres/set-a-seed-for-the-random-number-generator.md) - [Sets With The Values Command](postgres/sets-with-the-values-command.md) +- [Show All Versions Of An Operator](postgres/show-all-versions-of-an-operator.md) - [Sleeping](postgres/sleeping.md) - [Special Math Operators](postgres/special-math-operators.md) - [Storing Emails With citext](postgres/storing-emails-with-citext.md) diff --git a/postgres/show-all-versions-of-an-operator.md b/postgres/show-all-versions-of-an-operator.md new file mode 100644 index 0000000..2fd93e6 --- /dev/null +++ b/postgres/show-all-versions-of-an-operator.md @@ -0,0 +1,36 @@ +# Show All Versions Of An Operator + +We may be familiar with PostgreSQL's containment operator (`@>`). Maybe +we've used it with an array before, so we understand the general idea. But +now we are curious about what are the other types with which this +containment operator can be used. + +We can quickly find out the answer with the `\do` command in `psql`: + +```sql +\do @> + List of operators + Schema | Name | Left arg type | Right arg type | Result type | Description +------------+------+---------------+----------------+-------------+------------- + pg_catalog | @> | aclitem[] | aclitem | boolean | contains + pg_catalog | @> | anyarray | anyarray | boolean | contains + pg_catalog | @> | anyrange | anyelement | boolean | contains + pg_catalog | @> | anyrange | anyrange | boolean | contains + pg_catalog | @> | box | box | boolean | contains + pg_catalog | @> | box | point | boolean | contains + pg_catalog | @> | circle | circle | boolean | contains + pg_catalog | @> | circle | point | boolean | contains + pg_catalog | @> | jsonb | jsonb | boolean | contains + pg_catalog | @> | path | point | boolean | contains + pg_catalog | @> | polygon | point | boolean | contains + pg_catalog | @> | polygon | polygon | boolean | contains + pg_catalog | @> | tsquery | tsquery | boolean | contains +``` + +The `Left arg type` and `Right arg type` columns tell us what we need to +know. + +This `\do` command can be used with any operator for a similar set of +information. + +h/t Bruce Momjian