diff --git a/README.md b/README.md index 6a595ee..62bc3b3 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ smart people at [Hashrocket](http://hashrocket.com/). - [Truncate All Rows](postgres/truncate-all-rows.md) - [Truncate Tables With Dependents](postgres/truncate-tables-with-dependents.md) - [Turning Timing On](postgres/turning-timing-on.md) +- [Two Ways To Compute Factorial](postgres/two-ways-to-compute-factorial.md) - [Types By Category](postgres/types-by-category.md) - [Use A psqlrc File For Common Settings](postgres/use-a-psqlrc-file-for-common-settings.md) - [Use Argument Indexes](postgres/use-argument-indexes.md) diff --git a/postgres/two-ways-to-compute-factorial.md b/postgres/two-ways-to-compute-factorial.md new file mode 100644 index 0000000..10b98dc --- /dev/null +++ b/postgres/two-ways-to-compute-factorial.md @@ -0,0 +1,25 @@ +# Two Ways To Compute Factorial + +In PostgreSQL, there are two ways to compute the factorial of a number. +There is a prefix operator and a postfix operator. The prefix operator is +`!!` and can be used like so: + +```sql +> select 5!; + ?column? +---------- + 120 +``` + +The postfix operator is `!` and can be used like so: + +```sql +> select !!5; + ?column? +---------- + 120 +``` + +See the [arithmetic function +docs](http://stackoverflow.com/questions/7866353/git-list-all-available-commands) +for more details.