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

brsnik/boolif-postgresql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

21 Commits

Repository files navigation

Using CASE's is great however when there are too many conditions it can get uber complicated, this solves a very specific problem I've encountered.

Input

boolif(value: true, expected: true, output: 'It works!', fallback: '')

Variable Type Required Description
value boolean Yes Boolean value from the database.
expected boolean Yes The expected boolean value in order to return the output.
output varchar Yes Will be returned when value and expected are a match.
fallback varchar Optional Will return NULL unless set to a specific fallback when value and expected do not match.

Installation

By default it will be added to the public schema.

Usage

With default fallback:

  • SELECT boolif(true, true, 'It works!'); returns 'It works!'
  • SELECT boolif(false, true, 'It works!'); returns NULL

With custom fallback:

  • SELECT boolif(true, true, 'It works!', 'Oh yeah!'); returns 'It works!'
  • SELECT boolif(false, true, 'It works!', 'Oh yeah!'); returns 'Oh yeah!'

About

A PostgreSQL function that returns a custom value if two booleans match.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /