데이터 베이스 MySQL 튜토리얼 postgresql中常用小语法

postgresql中常用小语法

Jun 07, 2016 pm 02:58 PM
postgresql 일반적으로 사용되는 문법

postgresql中常用小语法 1. PG中 类型转换 有时候在postgresql中需要对值的类型进行转换,pg中提供的方法 example : select 33:: integer example2: select case(33 as integer) 2. pg中的行号 (类似于oracle中的 rownum) example : select row_number() o

postgresql中常用小语法

 

1. PG中 类型转换

 

    有时候在postgresql中需要对值的类型进行转换,pg中提供的方法

 

 example :  select '33':: integer

 

 example2: select case('33' as integer)

 

2. pg中的行号 (类似于oracle中的 rownum)

 

  example : select row_number() over() , * from XXXX

 

3. pg 中查询中的列转数组

 

example :  select array_agg(AAAAA)  FROM XXXXX

 

4. pg 中字符串函数 :

 

函数:string || string 

说明:String concatenation 字符串连接操作

例子:'Post' || 'greSQL' = PostgreSQL

 

函数:string || non-string or non-string || string

说明:String concatenation with one non-string input 字符串与非字符串类型进行连接操作

例子:'Value: ' || 42 = Value: 42

 

函数:bit_length(string)

说明:Number of bits in string 计算字符串的位数

例子:bit_length('jose') = 32

 

函数:char_length(string) or character_length(string)

说明:Number of characters in string 计算字符串中字符个数

例子:char_length('jose') = 4

 

函数:lower(string)

说明:Convert string to lower case 转换字符串为小写

例子:bit_length('jose') = 32

 

函数:octet_length(string)

说明:Number of bytes in string 计算字符串的字节数

例子:octet_length('jose') = 4

 

函数:overlay(string placing string from int [for int])

说明:Replace substring 替换字符串中任意长度的子字串为新字符串

例子:overlay('Txxxxas' placing 'hom' from 2 for 4) = 4

 

函数:position(substring in string)

说明:Location of specified substring 子串在一字符串中的位置

例子:position('om' in 'Thomas') = 3

 

函数:substring(string [from int] [for int])

说明:Extract substring 截取任意长度的子字符串

例子:substring('Thomas' from 2 for 3) = hom

 

函数:substring(string from pattern)

说明:Extract substring matching POSIX regular expression. See Section 9.7 for more information on pattern matching. 利用正则表达式对一字符串进行任意长度的字串的截取

例子:substring('Thomas' from '...$') = mas

 

函数:substring(string from pattern for escape)

说明:Extract substring matching SQL regular expression. See Section 9.7 for more information on pattern matching. 利于正则表达式对某类字符进行删除,以得到子字符串

例子:trim(both 'x' from 'xTomxx') = Tom

 

函数:trim([leading | trailing | both] [characters] from string)

说明:Remove the longest string containing only the characters (a space by default) from the start/end/both ends of the string 去除尽可能长开始,结束或者两边的某类字符,默认为去除空白字符,当然可以自己指定,可同时指定多个要删除的字符串

例子:trim(both 'x' from 'xTomxx') = Tom

 

函数:upper(string)

说明:Convert string to uppercase 将字符串转换为大写

例子:upper('tom') = TOM

 

函数:ascii(string)

说明:ASCII code of the first character of the argument. For UTF8 returns the Unicode code point of the character. For other multibyte encodings. the argument must be a strictly ASCII character. 得到某一个字符的Assii值

例子:ascii('x') = 120

 

函数:btrim(string text [, characters text])

说明:Remove the longest string consisting only of characters in characters (a space by default) from the start and end of string 去除字符串两边的所有指定的字符,可同时指定多个字符

例子:btrim('xyxtrimyyx', 'xy') = trim

 

 

函数:chr(int)

说明:Character with the given code. For UTF8 the argument is treated as a Unicode code point. For other multibyte encodings the argument must designate a strictly ASCII character. The NULL (0) character is not allowed because text data types cannot store such bytes. 得到某ACSII值对应的字符

例子:chr(65) = A

 

 

函数:convert(string bytea, src_encoding name, dest_encoding name)

说明:Convert string to dest_encoding. The original encoding is specified by src_encoding. The string must be valid in this encoding. Conversions can be defined by CREATE CONVERSION. Also there are some predefined conversions. See Table 9-7 for available conversions. 转换字符串编码,指定源编码与目标编码

例子:convert('text_in_utf8', 'UTF8', 'LATIN1') = text_in_utf8 represented in ISO 8859-1 encoding

 

 

函数:convert_from(string bytea, src_encoding name)

说明:Convert string to the database encoding. The original encoding is specified by src_encoding. The string must be valid in this encoding. 转换字符串编码,自己要指定源编码,目标编码默认为数据库指定编码,

例子:convert_from('text_in_utf8', 'UTF8') = text_in_utf8 represented in the current database encoding

 

 

函数:convert_to(string text, dest_encoding name)

说明:Convert string to dest_encoding.转换字符串编码,源编码默认为数据库指定编码,自己要指定目标编码,

例子:convert_to('some text', 'UTF8') = some text represented in the UTF8 encoding

 

 

函数:decode(string text, type text)

说明:Decode binary data from string previously encoded with encode. Parameter type is same as in encode. 对字符串按指定的类型进行解码

例子:decode('MTIzAAE=', 'base64') = 123\000\001

 

 

函数:encode(data bytea, type text)

说明:Encode binary data to different representation. Supported types are: base64, hex, escape. Escape merely outputs null bytes as \000 and doubles backslashes. 与decode相反,对字符串按指定类型进行编码

例子:encode(E'123\\000\\001', 'base64') = MTIzAAE=

 

 

函数:initcap(string)

说明:Convert the first letter of each word to uppercase and the rest to lowercase. Words are sequences of alphanumeric characters separated by non-alphanumeric characters. 将字符串所有的单词进行格式化,首字母大写,其它为小写

例子:initcap('hi THOMAS') = Hi Thomas

 

 

函数:length(string)

说明:Number of characters in string 讲算字符串长度

例子:length('jose') = 4

 

 

函数:length(stringbytea, encoding name )

说明:Number of characters in string in the given encoding. The string must be valid in this encoding. 计算字符串长度,指定字符串使用的编码

例子:length('jose', 'UTF8') = 4

 

 

函数:lpad(string text, length int [, fill text])

说明:Fill up the string to length length by prepending the characters fill (a space by default). If the string is already longer than length then it is truncated (on the right). 对字符串左边进行某类字符自动填充,即不足某一长度,则在左边自动补上指定的字符串,直至达到指定长度,可同时指定多个自动填充的字符

例子:lpad('hi', 5, 'xy') = xyxhi

 

 

函数:ltrim(string text [, characters text])

说明:Remove the longest string containing only characters from characters (a space by default) from the start of string 删除字符串左边某一些的字符,可以时指定多个要删除的字符

例子:trim

 

 

函数:md5(string)

说明:Calculates the MD5 hash of string, returning the result in hexadecimal 将字符串进行md5编码

例子:md5('abc') = 900150983cd24fb0 d6963f7d28e17f72

 

 

函数:pg_client_encoding()

说明:Current client encoding name 得到pg客户端编码

例子:pg_client_encoding() = SQL_ASCII

 

 

函数:quote_ident(string text)

说明:Return the given string suitably quoted to be used as an identifier in an SQL statement string. Quotes are added only if necessary (i.e., if the string contains non-identifier characters or would be case-folded). Embedded quotes are properly doubled. 对某一字符串加上两引号

例子:quote_ident('Foo bar') = "Foo bar"

 

 

函数:quote_literal(string text)

说明:Return the given string suitably quoted to be used as a string literal in an SQL statement string. Embedded single-quotes and backslashes are properly doubled. 对字符串里两边加上单引号,如果字符串里面出现sql编码的单个单引号,则会被表达成两个单引号

例子:quote_literal('O\'Reilly') = 'O''Reilly'

 

 

函数:quote_literal(value anyelement)

说明:Coerce the given value to text and then quote it as a literal. Embedded single-quotes and backslashes are properly doubled. 将一数值转换为字符串,并为其两边加上单引号,如果数值中间出现了单引号,也会被表示成两个单引号

例子:quote_literal(42.5) = '42.5'

 

 

函数:regexp_matches(string text, pattern text [, flags text])

说明:Return all captured substrings resulting from matching a POSIX regular expression against the string. See Section 9.7.3 for more information. 对字符串按正则表达式进行匹配,如果存在则会在结果数组中表示出来

例子:regexp_matches('foobarbequebaz', '(bar)(beque)') = {bar,beque}

 

 

函数:regexp_replace(string text, pattern text, replacement text [, flags text])

说明:Replace substring(s) matching a POSIX regular expression. See Section 9.7.3 for more information. 利用正则表达式对字符串进行替换

例子:regexp_replace('Thomas', '.[mN]a.', 'M') = ThM

 

 

函数:regexp_split_to_array(string text, pattern text [, flags text ])

说明:Split string using a POSIX regular expression as the delimiter. See Section 9.7.3 for more information. 利用正则表达式将字符串分割成数组

例子:regexp_split_to_array('hello world', E'\\s+') = {hello,world}

 

 

函数:regexp_split_to_table(string text, pattern text [, flags text])

说明:Split string using a POSIX regular expression as the delimiter. See Section 9.7.3 for more information. 利用正则表达式将字符串分割成表格

例子:regexp_split_to_table('hello world', E'\\s+') =

hello

world

(2 rows)

 

 

函数:repeat(string text, number int)

说明:Repeat string the specified number of times 重复字符串一指定次数

例子:repeat('Pg', 4) = PgPgPgPg

 

 

函数:replace(string text, from text, to text)

说明:Replace all occurrences in string of substring from with substring to 将字符的某一子串替换成另一子串

例子:('abcdefabcdef', 'cd', 'XX') = abXXefabXXef

 

 

函数:rpad(string text, length int [, fill text])

说明:Fill up the string to length length by appending the characters fill (a space by default). If the string is already longer than length then it is truncated. 对字符串进行填充,填充内容为指定的字符串

例子:rpad('hi', 5, 'xy') = hixyx

 

 

函数:rtrim(string text [, characters text])

说明:Remove the longest string containing only characters from characters (a space by default) from the end of string

去除字符串右边指定的字符

例子:rtrim('trimxxxx', 'x') = trim

 

 

函数:split_part(string text, delimiter text, field int)

说明:Split string on delimiter and return the given field (counting from one)  对字符串按指定子串进行分割,并返回指定的数值位置的值

例子:split_part(mailto:'abc~@~def~@~ghi', mailto:'~@~', 2) = def

 

函数:strpos(string, substring)

说明:Location of specified substring (same as position(substring in string), but note the reversed argument order) 指定字符串在目标字符串的位置

例子:strpos('high', 'ig') = 2

 

函数:substr(string, from [, count])

说明:Extract substring (same as substring(string from from for count)) 截取子串

例子:substr('alphabet', 3, 2) = ph

 

函数:to_ascii(string text [, encoding text])

说明:Convert string to ASCII from another encoding (only supports conversion from LATIN1, LATIN2, LATIN9, and WIN1250 encodings) 将字符串转换成ascii编码字符串

例子:to_ascii('Karel') = Karel

 

函数:to_hex(number int or bigint)

说明:Convert number to its equivalent hexadecimal representation  对数值进行十六进制编码

例子:to_hex(2147483647) = 7fffffff

 

函数:translate(string text, from text, to text)

说明:Any character in string that matches a character in the from set is replaced by the corresponding character in the to set 将字符串中某些匹配的字符替换成指定字符串,目标字符与源字符都可以同时指定多个

例子:translate('12345', '14', 'ax') = a23x5

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

인기 기사

R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25 : Myrise에서 모든 것을 잠금 해제하는 방법
4 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

MySQL 및 PostgreSQL: 웹 개발 모범 사례 MySQL 및 PostgreSQL: 웹 개발 모범 사례 Jul 14, 2023 pm 02:34 PM

MySQL 및 PostgreSQL: 웹 개발 모범 사례 소개: 현대 웹 개발 세계에서 데이터베이스는 필수 구성 요소입니다. 데이터베이스를 선택할 때 일반적인 선택은 MySQL과 PostgreSQL입니다. 이 문서에서는 웹 개발에 MySQL 및 PostgreSQL을 사용하는 모범 사례를 다루고 몇 가지 코드 예제를 제공합니다. 1. 적용 가능한 시나리오 MySQL은 대부분의 웹 애플리케이션, 특히 고성능, 확장성 및 사용 용이성을 요구하는 애플리케이션에 적합합니다.

MySQL 및 PostgreSQL: 성능 비교 및 ​​최적화 팁 MySQL 및 PostgreSQL: 성능 비교 및 ​​최적화 팁 Jul 13, 2023 pm 03:33 PM

MySQL 및 PostgreSQL: 성능 비교 및 ​​최적화 팁 웹 애플리케이션을 개발할 때 데이터베이스는 필수적인 구성 요소입니다. 데이터베이스 관리 시스템을 선택할 때 MySQL과 PostgreSQL은 두 가지 일반적인 선택입니다. 둘 다 오픈 소스 관계형 데이터베이스 관리 시스템(RDBMS)이지만 성능과 최적화에는 약간의 차이가 있습니다. 이 기사에서는 MySQL과 PostgreSQL의 성능을 비교하고 몇 가지 최적화 팁을 제공합니다. 두 데이터베이스 관리를 비교한 성능 비교

Go 언어로 데이터베이스 기능을 배우고 PostgreSQL 데이터의 추가, 삭제, 수정 및 쿼리 작업을 구현합니다. Go 언어로 데이터베이스 기능을 배우고 PostgreSQL 데이터의 추가, 삭제, 수정 및 쿼리 작업을 구현합니다. Jul 31, 2023 pm 12:54 PM

Go 언어의 데이터베이스 기능을 배우고 PostgreSQL 데이터의 추가, 삭제, 수정 및 쿼리 작업을 구현합니다. 현대 소프트웨어 개발에서 데이터베이스는 없어서는 안 될 부분입니다. 강력한 프로그래밍 언어인 Go 언어는 데이터베이스의 추가, 삭제, 수정 및 쿼리 작업을 쉽게 구현할 수 있는 풍부한 데이터베이스 작업 기능과 툴킷을 제공합니다. 이번 글에서는 Go 언어로 데이터베이스 기능을 익히고 PostgreSQL 데이터베이스를 실제 작업에 활용하는 방법을 소개합니다. 1단계: 각 데이터베이스에 대해 Go 언어로 데이터베이스 드라이버 설치

Go에서 PostgreSQL 사용: 전체 가이드 Go에서 PostgreSQL 사용: 전체 가이드 Jun 18, 2023 am 09:28 AM

Go 언어는 웹 서비스 및 백엔드 애플리케이션 구축에 적합한 빠르고 효율적인 프로그래밍 언어입니다. PostgreSQL은 더 높은 신뢰성, 확장성 및 데이터 보안을 제공하는 오픈 소스 관계형 데이터베이스 관리 시스템입니다. 이 글에서는 Go에서 PostgreSQL을 사용하는 방법에 대해 자세히 알아보고 몇 가지 실용적인 코드 예제와 팁을 제공하겠습니다. PostgreSQL 설치 및 설정 먼저 PostgreSQL을 설치하고 설정해야 합니다. 공식 홈페이지에서 확인 가능

MySQL 및 PostgreSQL: 데이터 보안 및 백업 전략 MySQL 및 PostgreSQL: 데이터 보안 및 백업 전략 Jul 13, 2023 pm 03:31 PM

MySQL 및 PostgreSQL: 데이터 보안 및 백업 전략 소개: 현대 사회에서 데이터는 비즈니스와 개인 생활에서 없어서는 안 될 부분이 되었습니다. 데이터베이스 관리 시스템의 경우 데이터 손실이나 손상으로부터 데이터를 보호하고 복구된 데이터의 신뢰성과 무결성을 보장하기 위해 데이터 보안 및 백업 전략이 중요합니다. 이 기사에서는 두 가지 주류 관계형 데이터베이스 시스템인 MySQL과 PostgreSQL의 데이터 보안 및 백업 전략에 중점을 둘 것입니다. 1. 데이터 보안: (1) 사용자 권리

캔버스 프레임워크를 배우고 일반적으로 사용되는 캔버스 프레임워크에 대해 자세히 설명합니다. 캔버스 프레임워크를 배우고 일반적으로 사용되는 캔버스 프레임워크에 대해 자세히 설명합니다. Jan 17, 2024 am 11:03 AM

Canvas 프레임워크 탐색: 일반적으로 사용되는 Canvas 프레임워크가 무엇인지 이해하려면 특정 코드 예제가 필요합니다. 소개: Canvas는 풍부한 그래픽 및 애니메이션 효과를 얻을 수 있는 HTML5에서 제공되는 그리기 API입니다. 그리기의 효율성과 편의성을 향상시키기 위해 많은 개발자들이 다양한 Canvas 프레임워크를 개발했습니다. 이 기사에서는 일반적으로 사용되는 몇 가지 캔버스 프레임워크를 소개하고 독자가 이러한 프레임워크를 사용하는 방법을 더 깊이 이해하는 데 도움이 되는 특정 코드 예제를 제공합니다. 1. EaselJS 프레임워크 Ea

PHP 프로그래밍에서 PostgreSQL 데이터베이스를 사용하는 방법은 무엇입니까? PHP 프로그래밍에서 PostgreSQL 데이터베이스를 사용하는 방법은 무엇입니까? Jun 12, 2023 am 09:27 AM

데이터베이스 기술의 발전으로 데이터베이스 관리 시스템도 다양한 선택을 제시합니다. 개발자는 자신의 필요와 선호도에 따라 가장 적합한 데이터베이스를 선택할 수 있습니다. 고급 오픈 소스 관계형 데이터베이스 시스템인 PostgreSQL은 개발자들의 관심과 사용이 점점 더 늘어나고 있습니다. 그렇다면 PHP 프로그래밍에서 PostgreSQL 데이터베이스를 어떻게 사용합니까? 1. PostgreSQL 데이터베이스를 설치하고 구성하려면 PostgreSQL을 설치하고 구성해야 합니다. 첫 번째

람다 표현식의 구문과 구조적 특징은 무엇입니까? 람다 표현식의 구문과 구조적 특징은 무엇입니까? Apr 25, 2024 pm 01:12 PM

람다 표현식은 이름이 없는 익명 함수이며 구문은 (parameter_list)->expression입니다. 익명성, 다양성, 커링 및 폐쇄 기능이 특징입니다. 실제 응용 프로그램에서는 람다 표현식을 사용하여 합산 함수 sum_lambda=lambdax,y:x+y와 같은 함수를 간결하게 정의하고 map() 함수를 목록에 적용하여 합산 작업을 수행할 수 있습니다.

See all articles