Skip to content

Instantly share code, notes, and snippets.

@dnedrow
Created February 23, 2022 03:14
Show Gist options
  • Select an option

  • Save dnedrow/2843e77d1b45aae35fa654f030fef550 to your computer and use it in GitHub Desktop.

Select an option

Save dnedrow/2843e77d1b45aae35fa654f030fef550 to your computer and use it in GitHub Desktop.
How to get leading digits when retrieving data from PostgreSQL
with sample_numbers (nr) as (
values (1),(11),(100)
)
select to_char(nr, 'fm000')
from sample_numbers;
/*
Example output:
to_char
---------
001
011
100
(3 rows)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment