sql

72 items tagged with "sql"

72 Articles

Articles

Snowflake - Flatten nested JSON array

Snowflake provides a number of JSON related functions to convert string (varchar) to JSON object and extract JSON values from the object or flatten nested array, etc. The code snippet shows an example of flattening the following JSON string using lateral flatten: ``json { "a":"a", "b":[ { "c":"c1", "d":[ 1, 2, 3, 4, 5, 6, 7 ] }, { "c":"c2", "d":[ 10, 20, 30, 40, 50, 60, 70 ] } ] } ``

2023-06-14
Code Snippets & Tips

Hive - Retrieve Current User

This code snippet provides example of retrieving current user via current_user() function in HQL (Hive QL) code. Output: `` 0: jdbc:hive2://> select currentuser();OK+----------+| c0 |+----------+| kontext |+----------+ ``

2022-08-20
Code Snippets & Tips

Hive SQL - Merge Statement on ACID Tables

Hive supports standard ANSI SQL MERGE statement from version 2.2. However it can be only be applied to tables that support ACID transactions. To learn more about ACID support in Hive, refer to article: Hive ACID Inserts, Updates and Deletes with ORC. Sample table This code snippet merges into a sample table named testdb.crudtable. It has two records before the merge. !20220819124209-image.png The staging table was created using the following statements: `` create table crudtablestg (id int, value string, op string); insert into crudtablestg values (1,'AA','U'),(2,'B','D'),(3,'C', 'I'); ` It has one additional column named op to indicate the delta changes: U - updates D - deletes I - inserts (i.e. new records) Syntax ` MERGE INTO AS T USING AS S ON WHEN MATCHED [AND ] THEN UPDATE SET WHEN MATCHED [AND ] THEN DELETE WHEN NOT MATCHED [AND ] THEN INSERT VALUES `` Output After the merge, record 1 is updated; record 2 is deleted and record 3 is inserted into the table.

2022-08-19
Code Snippets & Tips

Hive ACID Inserts, Updates and Deletes with ORC

2022-08-17
Hadoop, Hive & HBase

Hive SQL - Union data with UNION ALL and UNION DISTINCT

2022-07-23
Code Snippets & Tips

Hive SQL - Analytics with GROUP BY and GROUPING SETS, Cubes, Rollups

2022-07-23
Hadoop, Hive & HBase

Hive SQL - Data Sampling using TABLESAMPLE

2022-07-23
Code Snippets & Tips

Extract Values from XML Column in Hive Tables

2022-07-23
Hadoop, Hive & HBase

Hive SQL - Cluster By and Distribute By

2022-07-10
Hadoop, Hive & HBase

Hive SQL - Differences between Order By and Sort By

2022-07-10
Hadoop, Hive & HBase

Hive SQL - Aggregate Functions Overview with Examples

2022-07-10
Hadoop, Hive & HBase

List Tables in Hive Database

2022-07-08
Code Snippets & Tips

Create Partitioned Hive Table

2021-12-23
Code Snippets & Tips

PostgreSQL: Create and List User

2021-09-24
Code Snippets & Tips

BigQuery - Convert Bytes to BASE64 or HEX String

2021-09-18
Code Snippets & Tips

BigQuery MD5, SHA1, SHA256, SHA512 Hash Functions

2021-09-18
Code Snippets & Tips

Teradata: FIRST_VALUE and LAST_VALUE Funtions

2021-08-13
Teradata

Teradata: PIVOT and UNPIVOT Clause

2021-08-13
Teradata

Teradata Role Access on Databases

2021-06-22
Code Snippets & Tips

BigQuery - First/Last Day of Month

2021-05-17
Code Snippets & Tips

BigQuery SQL - WITH Clause

2021-03-13
Code Snippets & Tips

BigQuery SQL - SELECT * EXCEPT Clause

2021-03-13
Code Snippets & Tips

BigQuery SQL - Retrieve DISTINCT Values

2021-03-13
Code Snippets & Tips

BigQuery SQL - UNION ALL

2021-03-13
Code Snippets & Tips

BigQuery - Generate Unique Values

2021-03-13
Google Cloud Platform

BigQuery SQL - COALESCE and IFNULL Functions

2021-03-13
Code Snippets & Tips

Teradata SQL - First Day of a Month

2021-02-04
Code Snippets & Tips

Teradata - Update with Joins to Another Table

2020-12-13
Teradata

Spark SQL - Convert String to Date

2020-10-23
Spark & PySpark

Calculate MD5 in Teradata

2020-09-21
Teradata

Create Procedure with Dynamic Return Result in Teradata

2020-09-21
Teradata

Convert TimeStamp to Date in Teradata

2020-09-21
Teradata

Teradata RANDOM Number

2020-09-20
Teradata

Create Multiset Temporary Table in Teradata

This article demonstrates how to create volatile table in a Teradata procedure, perform DML actions (INSERT, DELETE, UPDATE) against it and then return the result set dynamically from the temporary table in the procedure.

2020-09-20
Teradata

Teradata ISNULL Alternatives

2020-09-08
Teradata

Teradata RPAD - Right Padding

2020-09-07
Teradata

Teradata LPAD - Left Padding

2020-09-07
Teradata

Extract XML Data via SQL Functions in Teradata

2020-08-31
Teradata

Extract JSON Data via SQL Functions in Teradata

2020-08-31
Teradata

Select First Row in Each GROUP BY Group in Teradata

2020-08-26
Teradata

Create Temporary Table - Hive SQL

2020-08-25
Hadoop, Hive & HBase

Create Table as SELECT - Hive SQL

2020-08-25
Hadoop, Hive & HBase

Create Bucketed Sorted Table - Hive SQL

2020-08-25
Hadoop, Hive & HBase

Create Partitioned Table - Hive SQL

2020-08-25
Hadoop, Hive & HBase

Create Table Stored as CSV, TSV, JSON Format - Hive SQL

2020-08-25
Hadoop, Hive & HBase

Create Table with Parquet, Orc, Avro - Hive SQL

2020-08-25
Hadoop, Hive & HBase

Create, Drop, and Truncate Table - Hive SQL

2020-08-24
Hadoop, Hive & HBase

Create, Drop, Alter and Use Database - Hive SQL

2020-08-24
Hadoop, Hive & HBase

Teradata SQL - Round Numbers to Hundreds or Thousands

2020-07-26
Code Snippets & Tips

Teradata SQL - Get Rid of Spaces from String

2020-07-26
Code Snippets & Tips

Teradata SQL LIKE: Contains, Starts With, Ends With Functions

This page shows you how to use LIKE

2020-07-26
Code Snippets & Tips

Trim Leading or/and Trailing Zeros in Teradata

This page shows how to trim or remove leading or/and trailing zeros using Teradata SQL.

2020-07-26
Code Snippets & Tips

Truncate table in Teradata

2020-04-22
Code Snippets & Tips

Teradata SQL - Use OREPLACE to Replace or Remove Characters

2020-04-04
Code Snippets & Tips

Teradata SUBSTRING / SUBSTR and REGEXP_SUBSTR Functions

2020-03-15
Code Snippets & Tips

Teradata SQL - COALESCE and NULLIF Functions

2020-03-15
Code Snippets & Tips

Teradata SQL - TRYCAST / TRY_CAST Function

2020-03-15
Code Snippets & Tips

Teradata SQL - LEAD and LAG OLAP Functions

2020-03-15
Code Snippets & Tips

Teradata SQL - DATEADD Function Alternative for ADD / Subtract Days or Months

2020-03-15
Code Snippets & Tips

Teradata SQL - WITH - Use a reference of a CTE to another CTE

2020-03-15
Teradata

Read and parse JSON in SQL / Teradata

JSON is commonly used in modern applications for data storage and transfers. Pretty much all programming languages provide APIs to parse JSON.

2019-11-18
Code Snippets & Tips

Select top N records in SQL / Teradata

In different databases, the syntax of selecting top N records are slightly different. They may also differ from ISO standards.

2019-11-18
Code Snippets & Tips

Calculate time difference in SQL / Teradata

This code snippet shows how to calculate time differences.

2019-11-18
Code Snippets & Tips

Convert varchar to date in SQL / Teradata

This code snippet shows how to convert string to date in Teradata.

2019-11-18
Code Snippets & Tips

Select from dual in SQL / Hive

In Oracle database, you can select from dual table if you only want to return a one row result set. In many other databases, the query engine supports select directly from constant values without specifying a table name.

2019-11-18
Code Snippets & Tips

Select top N records in SQL / Hive

In different databases, the syntax of selecting top N records are slightly different. They may also differ from ISO standards.

2019-11-18
Code Snippets & Tips

Teradata SQL Tricks for SQL Server/Oracle Developers

For many SQL Server or Oracle developers, you may encounter some inconveniences when writing SQL queries. For example, how to select from dummy table or local defined variables. This page summarize the equivalents in Teradata SQL.

2017-10-15
Teradata

Querying Teradata and SQL Server - Tutorial 2 Filtering and Sorting

2015-05-04
Teradata

Querying Teradata and SQL Server - Tutorial 1: The SELECT Statement

2015-05-03
Teradata

Useful T-SQLs (Part I)

2013-09-02
SQL Server

使用SQL Server 自带功能简化SQL

2013-06-01
SQL Server

Access中的Inner join, Left join, Right join 嵌套连接查询语法

2009-11-06
.NET Programming