RSS

Posts in 2020

  • PostgreSQL mini cookbook: Automating processes

    Last Update: in PostgreSQL

    PostgreSQL mini cookbook: Automating processes, those tricks back to 2001 and still works today. 😉

    Enabling plpgsql You want to write functions and build triggers in Postgres’ scripting language plpgsql. PL/pgSQL is a loadable procedural language for the PostgreSQL database system. The design goals of PL/pgSQL were to create a loadable …

    Read more

  • PostgreSQL mini cookbook: advanced query tricks

    Last Update: in PostgreSQL

    PostgreSQL mini cookbook: advanced query tricks, those tricks back to 2001 and still works today. 😉

    Having a dynamic field value without a lookup table You want a “calculated” column returned from a select but joining to a lookup table is either not practical or not desirable. Solution Use the CASE...WHEN...ELSE...END structure or write …

    Read more

  • PostgreSQL mini cookbook: aggregate query tricks

    Last Update: in PostgreSQL

    PostgreSQL mini cookbook: PostgreSQL aggregate query tricks, those tricks back to 2001 and still works today. 😉

    Sum a field You want to calculate the total number of payments per customer, staff. Solution Use SUM() and GROUP BY: SELECT a, b, sum(c) FROM t GROUP BY a ,b; Example: # SELECT * FROM payment; payment_id | customer_id | staff_id | rental_id | amount …

    Read more

  • PostgreSQL mini cookbook: basic query tricks

    Last Update: in PostgreSQL

    PostgreSQL mini cookbook: PostgreSQL basic query tricks, those tricks back to 2001 and still works today. 😉

    Case insensitive searches You want to check equality or do a regular expression search but ignoring case Solution Either use lower() on the field and the value being compared or use the ILIKE or ˜˜* regular expression operators. Discussion If you …

    Read more

  • Python unicode string lowercase and caseless match

    in Python

    str.lower() and str.casefold()

    str.lower() and str.casefold() Starting with Python 3.0, strings are stored as Unicode. Python defined to two functions str.lower() and str.casefold() can be used to convert string to lowercase: str.lower() Return a copy of the string with all the …

    Read more

  • psql 101

    Last Update: in PostgreSQL

    psql is a terminal-based front-end to PostgreSQL. It enables you to type in queries interactively, issue them to PostgreSQL, and see the query results. Alternatively, input can be from a file.

    psql shell command List exist databases $ psql --list List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges ------------------------+-------+----------+-------------+-------------+------------------- dvdrental | dbch | UTF8 …

    Read more

  • Azure function Did not find any initialized language workers

    Last Update: in Azure

    Azure function app random response 500 Internal error to client. log indicate Azure function: Did not find any initialized language workers.

    Symptom We deployed a very simple Azure function with nodejs runtime, on an Linux container. However after deployment, the service is not stable stable, it goes up and down, server random response 500 Internal error to client. From Azure’s log, …

    Read more

  • Add git commit date as last update date in hugo page

    Last Update: in Hugo

    Hugo page template: Use .GitInfo or .Page.Lastmod as last update date in hugo page

    Use .GitInfo or .Page.Lastmod Hugo have build-in support to get the last Git revision information for every content file through Page.Lastmod or .GitInfo variable. Page.Lastmod is fetched from .GitInfo.AuthorDate. To enable Hugo get git commit info, …

    Read more

  • Add git commit to docker image tag in Azure pipeline

    Last Update: in Azure

    Add git commit to docker image tag in Azure pipeline

    Problem I have Azure devops pipeline to build docker image from source. I want the docker image have the source code revision info like git commit hash. I tried to use Build.SourceVersion as a docker image tag, Build.SourceVersion : The latest …

    Read more

  • Pass var in Azure pipeline

    Last Update: in Azure

    Use variable to pass data in Azure devops pipelines

    I have an Azure devops pipeline and want to pass some data between different tasks. One way to do is use environment var. Variables give you a convenient way to get key bits of data into various parts of the pipeline. As the name suggests, the value …

    Read more