首页 > 其他分享 >DuckDB - Study Notes 6

DuckDB - Study Notes 6

时间:2025-01-14 21:44:22浏览次数:1  
标签:Solace No movie Study DuckDB Time release Notes SELECT

 

 

DuckDB’s nested data types: LIST, MAP, and STRUCT.

 

D SELECT [7,8,9] AS list_int;
┌───────────┐
│ list_int  │
│  int32[]  │
├───────────┤
│ [7, 8, 9] │
└───────────┘

 

D SELECT [
      'Quantum of Solace',
      'Skyfall',
      'Spectre',
      'No Time to Die'] AS list_string;
┌───────────────────────────────────────────────────────┐
│                      list_string                      │
│                       varchar[]                       │
├───────────────────────────────────────────────────────┤
│ [Quantum of Solace, Skyfall, Spectre, No Time to Die] │
└───────────────────────────────────────────────────────┘

 

LIST can be empty (with zero elements) and is essentially unbounded, allowing for any number of elements. However, note that every element within LIST must have the same data type. You cannot mix INTEGER and VARCHAR values in a LIST data type, for example.

 

D CREATE OR REPLACE TABLE movies AS
  SELECT MAP(
      [
          'Quantum of Solace',
          'Skyfall',
          'Spectre',
          'No Time to Die'
      ],
      [2008, 2012, 2015, 2021]
  ) AS movie_release_map;

 

D SELECT movie_release_map
  FROM movies;
┌───────────────────────────────────────────────────────────────────────────┐
│                             movie_release_map                             │
│                           map(varchar, integer)                           │
├───────────────────────────────────────────────────────────────────────────┤
│ {Quantum of Solace=2008, Skyfall=2012, Spectre=2015, No Time to Die=2021} │
└───────────────────────────────────────────────────────────────────────────┘

 

D SELECT movie_release_map['Quantum of Solace']
  FROM movies;
┌────────────────────────────────────────┐
│ movie_release_map['Quantum of Solace'] │
│                int32[]                 │
├────────────────────────────────────────┤
│ [2008]                                 │
└────────────────────────────────────────┘

 

D SELECT movie_release_map['Quantum of Solace'][1]
  FROM movies;
┌───────────────────────────────────────────┐
│ movie_release_map['Quantum of Solace'][1] │
│                   int32                   │
├───────────────────────────────────────────┤
│                                      2008 │
└───────────────────────────────────────────┘

 

D SELECT { movie: 'No Time to Die',
      release_year: 2021,
      box_office: 771.2
  } AS struct_movie;
┌──────────────────────────────────────────────────────────────────────┐
│                             struct_movie                             │
│ struct(movie varchar, release_year integer, box_office decimal(4,1)) │
├──────────────────────────────────────────────────────────────────────┤
│ {'movie': No Time to Die, 'release_year': 2021, 'box_office': 771.2} │
└──────────────────────────────────────────────────────────────────────┘

 

 

 

SELECT 'apple' AS fruit
UNION
SELECT 'banana' AS fruit
UNION
SELECT 'cherry' AS fruit;


SELECT ARRAY[1, 2, 3] AS nums
UNION
SELECT ARRAY[4, 5, 6] AS nums;

 

D CREATE OR REPLACE TABLE film_actors AS
  SELECT *
  FROM read_csv('film_actors.csv');
D SELECT *
  FROM film_actors
  LIMIT 5;
┌─────────────────────────────┬─────────────────┬─────────────────┐
│          film_name          │   actor_name    │ character_name  │
│           varchar           │     varchar     │     varchar     │
├─────────────────────────────┼─────────────────┼─────────────────┤
│ James Bond - No Time to Die │ Daniel Craig    │ James Bond      │
│ James Bond - No Time to Die │ Ana de Armas    │ Paloma          │
│ James Bond - Spectre        │ Daniel Craig    │ James Bond      │
│ James Bond - Spectre        │ Léa Seydoux     │ Madeleine Swann │
│ James Bond - Spectre        │ Christoph Waltz │ Blofeld         │
└─────────────────────────────┴─────────────────┴─────────────────┘

 

 

A particularly useful pattern that DuckDB supports is aggregating column-wise row groups into LIST instances that contain the contents of each group as a single value. This functionality is enabled through DuckDB’s list aggregate function.

 

标签:Solace,No,movie,Study,DuckDB,Time,release,Notes,SELECT
From: https://www.cnblogs.com/zhangzhihui/p/18671752

相关文章

  • DuckDB - Study Notes 5
     DSELECT*FROMduckdb_extensions();┌──────────────────┬─────────┬───────────┬──────────────┬───┬───────────────────┬───────────────────┬───────......
  • DuckDB:星号(*)表达式完整指南
    本文介绍DuckDB星号的用法,尤其是与其他数据库不同的用法,掌握它可以快速帮你选择和转换列。常规用法首先我们介绍星号表达式的常规用法,这与其他数据库功能一样。#选择from子句中所有列SELECT*FROMtable_name;#计算表中的行数,DuckDB支持省略*号SELECTcount(......
  • 安装 php 开发环境(基于 php study)
    目录安装 php 开发环境(基于 phpstudy)创建简单博客示例代码下载 phpstudy:可以从官网(xp.cn)下载,也可以在内网(如提到的 6.100)下载,或者使用已提供的安装包。安装过程:双击安装包,若电脑有 D 盘且无特殊需求,默认安装路径为 D:\phpstudy;若没有 D 盘,则需将路径......
  • DuckDB - Study Notes 4
         blockrangeindex,BRIN   adaptiveradixtree,ART Todownloadthenecessarydatasetforthisproject,pleasefollowtheseinstructions:1.Gotohttps://www.kaggle.com/datasets/mohamedbakhet/amazon-books-reviews.2.ClickontheDown......
  • DuckDB - Study Notes 3
        DataWrangling CREATEORREPLACETABLEweb_log_text(raw_textVARCHAR); COPYweb_log_textFROM'access.log'(DELIM''); SELECTregexp_extract(raw_text,'^[0-9\.]*')ASclient_ipFROMweb_log_textLIM......
  • @Notes:将整数转为excel对应的列标
    /**@Notes:将整数转为excel对应的列标@Functionint_to_chr@param$index@param$start@returnstring@Authorgxk@Date2024/10/16@Time17:53*/functionint_to_chr($index,$start=65){$str='';if($index>=26){weibow.com$les=$index%26;$index......
  • DDR Study - LPDDR4 BRC RBC QoS
    参考来源:LPDRAM4/4XPerformanceTweaksBankrotation/interleaving基于DRAM的BANK-ROW-COLUMN结构,以及访问同一Bank内不同Row时需要的Pre-Charge+Active行为,对两种Address组成进行分析:Bank-Row-ColumnAddressScheme(BRC)这种结构下,MSB是CS+BankGroup,LSB是Colu......
  • notes for linear algebra
    Diagonalization$1\le\dim(E_{\lambda})\le$multiplicityof\(\lambda\).Assume\(T\)splits,itisdiagonalizableiff$\dim(E_{\lambda})=$multiplicityof\(\lambda\)forall\(\lambda\).Cayley-HamiltonTheoremLemma1.Let\(W\)be......
  • Notes.js的安装和配置
    一、安装1、下载https://nodejs.org/en/download/2、安装  3、测试打开cmd查看node和npm版本node-vnpm-v 二、环境配置1、找到安装目录,新建node_cache和node_global文件夹 2、以管理员权限打开cmd输入npmconfigsetprefix"D:\nodejs\node_gl......
  • PHPstorm和PHPstudy配置运行教程
    先下载好PHPstudy以及PHPstorm解压安装1、打开PHPstudy,开启Apache服务创建站点(打开浏览器输入localhost,表示创建成功)2、打开phpstorm,未添加解释器浏览器运行输出则会显示502BadGateway3、添加解释器,点击右上角file,设置,点击PHP接着添加CLL解释器跳转至以下界面,添......