Vitaly Platonov

TILSeptember 04, 2019by Vitaly Platonov

Postgres. Search Array type columns

Say we have a table with a column of an array type. At some point, we want to be able to select records with a specific value(s) which the array column may have.

Here are three ways to do different kinds of searches.

1) Use ANY operator when searching with one value:


SELECT * FROM mytable WHERE 'first_type' = ANY(types_column);

2) Go with the "contains" operator (“@>”) when you look for a specific set of values (the order of values doesn’t matter):


SELECT * FROM mytable WHERE types_column @> '{"first_type", "second_type"}';

The values “first_type” and “second_type" must be in the types_column column for a record to be selected.

3) Whenever you need to search any values that a column may have - use the "overlap" operator (“&&”)


SELECT * FROM mytable WHERE types_column && '{"first_type", "second_type"}';

One of the values “first_type” or “second_type" must be in the types_column column for a record to be selected.

TILFebruary 20, 2019by Vitaly Platonov

Elixir code formatting in IDE (with Atom set up example)

Today I learned that Elixir has a great feature that allows you to format your code.

Here are a few reasons you may want to do that (borrowed from The Go Blog):

  • easier to write: never worry about minor formatting concerns,

  • easier to read: when all code looks the same you need not mentally convert others' formatting style into something you can understand.

  • easier to maintain: diffs show only the real changes.

  • uncontroversial: never have a debate about spacing or brace position ever again

In fact, you actually want to format your Elixir code as you make it, meaning there is no need to format all of your project's code every time.

The following bash command does it well on a single file:

cd $projectPath && mix format $filePath

Where: $projectPath - full path to your project's root directory; $filePath - full path to a file you're saving

My IDE of choice happened to be Atom and I'll talk briefly on setting it up.

The Process Palette package so far is the best for this task.

My Shell Command field (with variables) in Process Palette looks the following cd {projectPath} && mix format {fileAbsPath}