Skip to content

[new]: country_code_to_flag(country_code) #199

@rasmusengelbrecht

Description

@rasmusengelbrecht

Check the idea has not already been suggested

Edit the title above with self-explanatory function name and argument names

  • The function name and the argument names I entered in the title above seems self explanatory to me.

BigFunction Description as it would appear in the documentation

Converts a 2-letter ISO country code to a flag emoji

Examples of (arguments, expected output) as they would appear in the documentation

type: function_sql
author: "Rasmus Engelbrecht Sommer"
description: |-
  Converts a 2-letter ISO country code to a flag emoji
arguments:
  - name: country_code
    type: string
output:
  name: country_code_to_flag
  type: string
examples:
  - description: "with US country code"
    arguments:
      - "US"
    output: "🇺🇸"
  - description: "with DK country code"
    arguments:
      - "DK"
    output: "🇩🇰"
  - description: "with DE country code"
    arguments:
      - "DE"
    output: "🇩🇪"
  - description: "with lowercase country code"
    arguments:
      - "fr"
    output: "🇫🇷"
  - description: "with NULL input"
    arguments:
      - null
    output: null
  - description: "with empty string"
    arguments:
      - ""
    output: null
  - description: "with single character"
    arguments:
      - "A"
    output: null
code: |
  CASE
    WHEN country_code IS NULL OR LENGTH(TRIM(country_code)) != 2 THEN NULL
    ELSE CONCAT(
      CHR(127397 + TO_CODE_POINTS(SUBSTR(UPPER(TRIM(country_code)), 1, 1))[OFFSET(0)]),
      CHR(127397 + TO_CODE_POINTS(SUBSTR(UPPER(TRIM(country_code)), 2, 1))[OFFSET(0)])
    )
  END 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions