PostgreSQL-Query tricks

PostgreSQL-Query tricks

You need those users which entered their name and it is not null. Note that NULL in SQL means no data is provided, So NULL does not means empty string, 0 or anything else. NULL is no data.

select id, first_name from main.user where first_name like '%';        

In other words the following query is the equivalent of former query:

select id, first_name from main.user where first_name is not null;        

TBH I do not have any idea which one is better but I guess the second one is better from performance point of view:

No alt text provided for this image

=======================

Do not use * wild card in the select statement

It is not a good practice, especially for prod apps. BTW TBH I done it in my past. But now I do not do that.

=======================

How PostgreSQL saves timezone when you said that save with UTC?

  • UTC = 00:00 timezone

No alt text provided for this image

=======================

order by

  • ASC means from small to big
  • DESC means from big to small

=======================

To be continued ...

要查看或添加评论,请登录

Mohammad Jawad barati的更多文章

  • Write test for nanostores

    Write test for nanostores

    why I wrote this post in the first place? Lack of tut and doc around this awesome library that makes our lives easier…

    1 条评论
  • My very own Linux cheat sheet

    My very own Linux cheat sheet

    HAL: Hardware Abstraction Layer do abstract hardwares for us /sys is where we can see what is connected to the system…

    1 条评论
  • ?????? ???? ?? ?????

    ?????? ???? ?? ?????

    ?? ???? ????: ???? ???? 43 ???? ?? (????? ?? ??????) ?? ??? ???? ???? ? ??????? ?????. ??? ??? ??????? ??? 56 ???? ??…

    2 条评论
  • Angular Material UI

    Angular Material UI

    IMO you need to know 3 things before reading this article: Authentication and Authorization in Angular. Whether you…

  • Create Angular project

    Create Angular project

    First please note that the following instructions are totally biased and is my favorite way of doing it. BTW if you…

  • Learn Angular fundamentals.

    Learn Angular fundamentals.

    Note that I am still a backend developer who is dealing with frontend stuff BTW it is not so hard. IMO Angular is much…

  • NestJS task scheduler

    NestJS task scheduler

    To tackle queue issues in NestJS we use @nestjs/schedule. With this package we can define declarative cron jobs.

  • OTP code in Node.js

    OTP code in Node.js

    Send a time-based OTP code - define TTL for the code Keep the symetric keys very safe Use approved cryptographic…

  • Refresh Token + Logout functionality in Node.js

    Refresh Token + Logout functionality in Node.js

    Here is how I implement refresh token in Node.js.

  • My journey in gPRC

    My journey in gPRC

    I am just fooling around gPRC. Please do not count this article as complete right now.

社区洞察

其他会员也浏览了