Skip to content

Instantly share code, notes, and snippets.

@patrickemuller
Created March 29, 2017 17:35
Show Gist options
  • Save patrickemuller/26bba09d66bd093bdc953323a6ba1ede to your computer and use it in GitHub Desktop.
Save patrickemuller/26bba09d66bd093bdc953323a6ba1ede to your computer and use it in GitHub Desktop.
How to use Conditional-Functions inside SELECT with PGSQL
SELECT id, name, CASE
WHEN aasm_state = 10 AND imported = false THEN true
ELSE false
END
AS available
FROM businesses
LIMIT 5;
/* Line 2 is your conditional */
/* NOTE: will be F or T depending on your conditional */
/*
id | name | available
----+------------------+-----------
38 | Teste | f
62 | Dog Palace | t
71 | Pet Samary`s | f
68 | Hora do Pet | t
69 | Pet shop do Marx | f
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment