쭈니아빠 블로그
close
프로필 배경
프로필 로고

쭈니아빠 블로그

    • 분류 전체보기 (87)
      • Development (70)
        • C# (10)
        • WPF (4)
        • ASP.Net (11)
        • Javascript & TypeScript (4)
        • HTML & CSS (1)
        • NodeJs (1)
        • NextJS (1)
        • Angular (1)
        • Python (6)
        • Linux (1)
        • SQL (6)
        • Windows (7)
        • Visual Studio Code (1)
        • Unity (2)
        • Cocos2d-x (3)
        • Flutter (1)
        • Utility Apps (7)
        • Docker (1)
        • LeetCode (1)
      • 일상 (7)
        • 이런 저런 이야기 (2)
        • 노트북 (1)
        • 주변기기 (2)
      • 이글루스 블로그 기록들 (9)
        • 기록 보관소 (8)
        • 오래된 도구들 (1)
  • mode_edit_outline글작성
  • settings환경설정
  • 홈
  • 태그
  • 방명록
[PostgreSQL] Temporary 테이블 만들기

[PostgreSQL] Temporary 테이블 만들기

복잡한 SQL 쿼리를 한 문장에 담아서 작성하다보면 Nested Select 쿼리를 쓰게 되고 그 결과 값들이 다시 Join 하는 케이스가 많이 발생합니다. 그런데 문제는 Nested Select 쿼리의 cost가 높아서 얼마 안되는 레코드 수에도 쿼리 실행 속도가 말도안되게 느려지는 문제가 발생합니다. 그래서 이런 nested select 쿼리를 피하기 위해 temporary table을 생성 후 중간 쿼리 결과를 이곳에 담아 놓고 이 임시 테이블들 간에 join을 해서 최종 결과를 뽑으면 훨씬 빠른 속도로 원하는 데이터를 추출 할 수 있습니다. PostgreSQL에서는 아래와 같은 방법으로 Temporary 테이블을 생성 할 수 있습니다. create temp table temp_test ( "Id"..

  • format_list_bulleted Development/SQL
  • · 2023. 3. 31.
  • textsms
[PostgreSQL] SQL Error [22023]: 오류: 스칼라형에서는 json_array_elements 호출 할 수 없음. json의 null값 제거 방법

[PostgreSQL] SQL Error [22023]: 오류: 스칼라형에서는 json_array_elements 호출 할 수 없음. json의 null값 제거 방법

json/jsonb 타입의 컬럼의 json 컨텐츠에서 array 값을 가지는 특정 property를 행으로 가져올 때 from 절에 json_array_elements 혹은 jsonb_array_elements 함수를 사용합니다. select * from json_array_elements(('{ "Cities": [ "Seoul", "Busan", "Daegu" ]}'::json) -> 'Cities') 하지만 만일 Cities가 null 일 경우 해당 쿼리를 실행하면 scalar type 값에 json_array_elements를 호출 할 수 없다는 오류를 뿜어냅니다. select * from json_array_elements(('{ "Cities": null }'::json) -> 'Cities'..

  • format_list_bulleted 카테고리 없음
  • · 2023. 3. 27.
  • textsms
[PostgreSql] json_array_elements() 함수로 json string을 행으로 가져오기

[PostgreSql] json_array_elements() 함수로 json string을 행으로 가져오기

json_array_elements() 함수를 사용하면 json 타입의 컬럼에서 json 내의 배열 property의 값을 행으로 가져올 수 있습니다. with test as (select '{"array": [ "v1", "v2", "v3", "v4", "v5" ]}'::json json) select j.* from test, json_array_elements(json -> 'array') j

  • format_list_bulleted Development/SQL
  • · 2023. 1. 13.
  • textsms
[PostgreSql] split_part(), string_to_array(), unnest() 함수로 컬럼의 문자열 분리하기

[PostgreSql] split_part(), string_to_array(), unnest() 함수로 컬럼의 문자열 분리하기

1. 구분자로 문자열을 분리한 다음 각각의 컬럼으로 나누기 with test as (select '서울,대구,부산,대전,인천,광주' cities) select split_part(cities, ',', 1) "1", split_part(cities, ',', 2) "2", split_part(cities, ',', 3) "3", split_part(cities, ',', 4) "4", split_part(cities, ',', 5) "5", split_part(cities, ',', 6) "6" from test 2. 문자열 분리 후 배열로 가져오기 with test as (select '서울,대구,부산,대전,인천,광주' cities) select string_to_array(cities, ',') fr..

  • format_list_bulleted Development/SQL
  • · 2023. 1. 13.
  • textsms

[PostgreSql] JSON type 컬럼 Query 방법

공식 문서 참조 : https://www.postgresql.org/docs/9.3/functions-json.html OperatorRight Operand TypeDescriptionExample -> int Get JSON array element '[1,2,3]'::json->2 -> text Get JSON object field '{"a":1,"b":2}'::json->'b' ->> int Get JSON array element as text '[1,2,3]'::json->>2 ->> text Get JSON object field as text '{"a":1,"b":2}'::json->>'b' #> array of text Get JSON object at specified path '{"..

  • format_list_bulleted Development/SQL
  • · 2023. 1. 4.
  • textsms
  • 1
공지사항
전체 카테고리
  • 분류 전체보기 (87)
    • Development (70)
      • C# (10)
      • WPF (4)
      • ASP.Net (11)
      • Javascript & TypeScript (4)
      • HTML & CSS (1)
      • NodeJs (1)
      • NextJS (1)
      • Angular (1)
      • Python (6)
      • Linux (1)
      • SQL (6)
      • Windows (7)
      • Visual Studio Code (1)
      • Unity (2)
      • Cocos2d-x (3)
      • Flutter (1)
      • Utility Apps (7)
      • Docker (1)
      • LeetCode (1)
    • 일상 (7)
      • 이런 저런 이야기 (2)
      • 노트북 (1)
      • 주변기기 (2)
    • 이글루스 블로그 기록들 (9)
      • 기록 보관소 (8)
      • 오래된 도구들 (1)
최근 글
인기 글
최근 댓글
태그
  • #asp.net core
  • #C#
  • #CommunityToolkit.Mvvm
  • #PostgreSQL
  • #ObservableObject
  • #mvvm
  • #wpf
  • #ASP.NET
  • #.net6
  • #asp.net core 6
전체 방문자
오늘
어제
전체
Copyright © 쭈미로운 생활 All rights reserved.
Designed by JJuum

티스토리툴바