Better null display psql

  • March 29, 2018

I’ve been frustating recently to differenciate NULL and empty strings in postgresql when requeting manually with psql

Turns out there’s an easy way to change that.

Just use

\pset null 'Ø'

and now

 id |          email          |  first  | last
----+-------------------------+---------+-------
  1 | your-email@example.com  | Foo     | Bar
  2 | first-is-null@foo.com   |         |

will be

 id |          email          |  first  | last
----+-------------------------+---------+-------
  1 | your-email@example.com  | Foo     | Bar
  2 | first-is-null@foo.com   | Ø       |

Read More

check start time before end time in postgresql

  • August 10, 2016
Something that a lot of people coming from MySQL does not know about real SQL database is the possibility to have ‘advanced’ constraints A very simple one here, but quite common I have my table Event with a start_time and end_time and of course I want to be sure that it can’t be possible to have a start_time that happens after its end_time. in MySQL outside of creating triggers you will most of the time have no other way than to do this check in your application code, and of course either it will not be put directly. Read More

get http status code in bash script wit curl

  • July 29, 2016
A simple piece of bash to know if your service is up or not response=$( curl YOUR_URL \ --write-out %{http_code} \ --silent \ --output /dev/null \ ) test "$response" -ge 200 && test "$response" -le 299 You can replace the test by whatever suits you of course Read More

some reading for better understanding of postgresql

  • April 16, 2016

Today nothing big, just that I have a couple of links open on my firefox, that I plan to read when I have sometimes to learn more about postgresql, So here we are:

Read More

alembic use sql statement instead of sqlalchemy

  • April 3, 2016

I know it’s pretty popular to use the wonderful sqlalchemy ORM for python, especially combined with alembic, but sometimes you just want to type plain SQL request.

And actually it’s pretty easy, after creating your migrations just do:

Read More

python alembic with environment variables

  • April 3, 2016

At my job we’re currently using alembic to manage our database migrations (i.e adding a new table / index etc.)

The tool is pretty mature and has been here for a while, so it covers a lot of advanced case (like handling several databases, having a tree of migrations etc.) while still being simple for simple case

The only not straighforward thing I found was that it’s not easy to integrate with 12Factor-apps, i.e my code is running in a lot of differents environments (vagrant+docker on my local machine, the QA environments, the pre-production, production etc.)

Read More

how to sum all numbers in file in bash

  • March 20, 2016

I have a file, with one number by line, how to get the sum

paste -s -d+  myfile_with_numbers | bc 

and if you have a csv, delimited by , and for which the number is on the 2nd field:

cut -d,  my_file.csv -f 2 | paste -s -d+  | bc 

Read More

murmur hash v3 in MySQL utf8 compatible

  • March 20, 2016

Murmur hash v3 in MySQL utf8 compatible

These days for performance purpose, I needed to replace some autoincrement Id by a hash calculated one, in order to have a determinist way to retrieve from an object, it’s record in database, and easily recognize duplicate.

For that I have chosen the murmur hash v3 function

For new records, I could use the python module (leveraging C code) mmh3

But as I needed to update million of existing record, I couldn’t possibly imagine doing that by calling a python script.

Read More

bug in Vagrant with Virtualbox sharefolder

  • August 23, 2015

The problem: serving static files

The problem will affect you if you try to serve static files from your vagrant folder if you use the default from virtualbox

For example you got your nginx or apache to serve css files and when you update them, they don’t get updated, and sometimes they even come out with some garbage bytes at the end of it

Read More

create a rest api with symfony2 Part 2: Entity, DB Migration, CRUD

  • May 24, 2015

Update 23 November 2015: Corrected some typo, and updated bundles versions for Doctrine

In the first part we’ve seen how to create the base of a symfony2 project used to generate a REST Api.

In this part we’re going to see

  • How to use the basics of JMSSerializer to serialize Entity objects
  • How to link our API with a database
  • How to create migration files to easily manage our datase over time and colleagues
  • and how to generate a full CRUD (create/read/update/delete) with form checking

Read More