postgresql中常用小语法2
postgresql中常用小语法2 postgresql中常用小语法 http://www.2cto.com/database/201305/210793.html 1. PG 中测试可能需要循环插入N多数据 这时候写function等就比较麻烦 我们可以用 generate_series 来 example: mrapp=# create table test_series(id int)
postgresql中常用小语法2
postgresql中常用小语法
http://www.2cto.com/database/201305/210793.html
1. PG 中测试可能需要循环插入N多数据 这时候写function等就比较麻烦 我们可以用 generate_series 来
example:
mrapp=# create table test_series(id int) ;
CREATE TABLE
mrapp=# insert into test_series(id) select generate_series(1,100000);
INSERT 0 100000
mrapp=# select count(1) from test_series;
count
--------
100000
(1 行记录)
2. postgresql 中比较两个字符串中重叠的数量
我们先将array转换为行数据 然后和另一个转换过的array进行去重 然后再拼为数组即可
example:
mrapp=# select unnest(array[1,2,4]);
unnest
--------
1
2
4
(3 行记录)
mrapp=# select unnest(array[1,2,4]) intersect select unnest(array[2,3,4]);
unnest
--------
2
4
(2 行记录)
mrapp=# select array(select unnest(array[1,2,4]) intersect select unnest(array[2
,3,4]));
array
-------
{2,4}
(1 行记录)
3. postgresql 列转数组
可以用array_agg 函数来处理
example :
mrapp=# select 1 as a union select 2 as a union select 3 as a;
a
---
1
2
3
(3 行记录)
mrapp=# select array_agg(t.a) from (select 1 as a union select 2 as a union sele
ct 3 as a) as t;
array_agg
-----------
{1,2,3}
(1 行记录)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

MySQL and PostgreSQL: Best Practices in Web Development Introduction: In the modern world of web development, databases are an essential component. When choosing a database, common choices are MySQL and PostgreSQL. This article will cover best practices for using MySQL and PostgreSQL in web development and provide some code examples. 1. Applicable scenarios MySQL is suitable for most web applications, especially those that require high performance, scalability and ease of use.

MySQL and PostgreSQL: Performance Comparison and Optimization Tips When developing web applications, the database is an indispensable component. When choosing a database management system, MySQL and PostgreSQL are two common choices. They are both open source relational database management systems (RDBMS), but there are some differences in performance and optimization. This article will compare the performance of MySQL and PostgreSQL and provide some optimization tips. Performance comparison comparing two database management

Explore the Canvas framework: To understand what are the commonly used Canvas frameworks, specific code examples are required. Introduction: Canvas is a drawing API provided in HTML5, through which we can achieve rich graphics and animation effects. In order to improve the efficiency and convenience of drawing, many developers have developed different Canvas frameworks. This article will introduce some commonly used Canvas frameworks and provide specific code examples to help readers gain a deeper understanding of how to use these frameworks. 1. EaselJS framework Ea

Spring is an open source framework that provides many annotations to simplify and enhance Java development. This article will explain commonly used Spring annotations in detail and provide specific code examples. @Autowired: Autowired @Autowired annotation can be used to automatically wire beans in the Spring container. When we use the @Autowired annotation where dependencies are required, Spring will find matching beans in the container and automatically inject them. The sample code is as follows: @Auto

Learn the database functions in the Go language and implement the addition, deletion, modification, and query operations of PostgreSQL data. In modern software development, the database is an indispensable part. As a powerful programming language, Go language provides a wealth of database operation functions and toolkits, which can easily implement addition, deletion, modification and query operations of the database. This article will introduce how to learn database functions in Go language and use PostgreSQL database for actual operations. Step 1: Install the database driver in Go language for each database

Lambda expression is an anonymous function without a name, and its syntax is: (parameter_list)->expression. They feature anonymity, diversity, currying, and closure. In practical applications, Lambda expressions can be used to define functions concisely, such as the summation function sum_lambda=lambdax,y:x+y, and apply the map() function to the list to perform the summation operation.

Go language is a fast and efficient programming language suitable for building web services and back-end applications. PostgreSQL is an open source relational database management system that promises to provide higher reliability, scalability and data security. In this article, we’ll take a deep dive into using PostgreSQL with Go and provide some practical code examples and tips. Installing and setting up PostgreSQL First, we need to install and set up PostgreSQL. Can be found on the official website

MySQL and PostgreSQL: Data Security and Backup Strategies Introduction: In modern society, data has become an indispensable part of business and personal life. For database management systems, data security and backup strategies are crucial, both to protect data from loss or damage and to ensure the reliability and integrity of recovered data. This article will focus on the data security and backup strategies of two mainstream relational database systems, MySQL and PostgreSQL. 1. Data security: (1) User rights
