PostgreSQL ๋ฌธ๋ฒ
์์ Table - Ticker information

NOTE
https://www.postgresql.org/docs/current/functions-string.html
9.4. String Functions and Operators
9.4. String Functions and Operators 9.4.1. format This section describes functions and operators for examining and manipulating string values. Strings in โฆ
www.postgresql.org
๋ฌธ๋ฒ์ ์์ PostgreSQL์ ์ฌ์ฉ ๋๋ ๋ฌธ์์ด ํจ์์ ์ฐ์ฐ์ ์ฌ์ฉ์
SQL์ ์ผํ๊ฐ ์๋ ํค์๋๋ฅผ ์ฌ์ฉํ์ฌ ์ธ์๋ฅผ ๊ตฌ๋ถํ๋ ์ผ๋ถ ๋ฌธ์์ด ํจ์๋ฅผ ์ ์ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ ํ 9.9์ ๋์ ์์ต๋๋ค. PostgreSQL์ ์ผ๋ฐ ํจ์ ํธ์ถ ๊ตฌ๋ฌธ์ ์ฌ์ฉํ๋ ์ด๋ฌํ ํจ์์ ๋ฒ์ ๋ ์ ๊ณตํฉ๋๋ค(ํ 9.10 ์ฐธ์กฐ).
๋ฌธ์์ด ์ฐ๊ฒฐ ์ฐ์ฐ์(||)๋ ํ 9.9์ ํ์๋ ๊ฒ์ฒ๋ผ ํ๋ ์ด์์ ์ ๋ ฅ์ด ๋ฌธ์์ด ์ ํ์ธ ํ ๋ฌธ์์ด์ด ์๋ ์ ๋ ฅ์ ํ์ฉํฉ๋๋ค. ๊ทธ ์ธ์ ๊ฒฝ์ฐ์๋ ํ ์คํธ์ ๋ช ์์ ๊ฐ์ ๋ฅผ ์ฝ์ ํ์ฌ ๋ฌธ์์ด์ด ์๋ ์ ๋ ฅ์ ํ์ฉํ ์ ์์ต๋๋ค. ๋ฌธ์์ด ์๋ ์ ๋ ฅ์ ํ์ฉํจ์ผ๋ก์จ ์์นซ ALL ๋ชจ๋ ๊ฒฝ์ฐ์ ์๋ฅผ ๊ฐ์ ธ์ฌ์ ์๋ค.
1) LEFT
left ( string text, n integer ) โ text
Returns first n characters in the string, or when n is negative, returns all but last |n| characters.
left('abcde', 2) โ ab
LEFT(๋ฌธ์์ด, ์ผ์ชฝ๋ถํฐ ์ถ์ถ ๋ฌธ์์ด ์)
SELECT LEFT(si.SYMBOL,1) LEFT1
, LEFT(si.SYMBOL,2) LEFT2
, LEFT(si.SYMBOL,3) LEFT3
, LEFT(si.SYMBOL,4) LEFT4
, LEFT(si.SYMBOL,5) LEFT5
, si.SYMBOL
FROM re_stock.STOCK_INFO si
WHERE si.SYMBOL IN ("AAPL","GOOGL","TSLA","LCID","MSFT","OPEN")
ORDER BY si.SYMBOL DESC

0์ดํ์ ๊ฐ์ ๋ชจ๋ "" ๋น ๋ฌธ์์ด์ Returnํ๋ค. NULL ๊ฐ์ Returnํ์ง ์์ผ๋ฏ๋ก ์ฃผ์
2) REPLACE
replace ( string text, from text, to text ) โ text
Replaces all occurrences in string of substring from with substring to.
replace('abcdefabcdef', 'cd', 'XX') โ abXXefabXXef
REPLACE( ๋ฌธ์์ด, ๋ณ๊ฒฝ ์ ๋ฌธ์์ด, ๋ณ๊ฒฝ ํ ๋ฌธ์์ด)
SELECT si.SYMBOL SYMBOL
, REPLACE(si.SYMBOL, "FB", "META") "REPLACE"
FROM re_stock.STOCK_INFO si
WHERE si.SYMBOL IN ("FB");

FB(Facebook)์์ Meta๋ก ์ฌ๋ช ์ ๋ฐ๊ฟ REPLACE ํจ์๋ก ๋ณ๊ฒฝ
3) SUBSTRING
/*1*/
substring(string [from int] [for int]) text Extract substring substring('Thomas' from 2 for 3) hom
/*2*/
substring(string from pattern) text Extract substring matching POSIX regular expression. See Section 9.7 for more information on pattern matching. substring('Thomas' from '...$') mas
/*3*/
substring(string from pattern for escape) text Extract substring matching SQL regular expression. See Section 9.7 for more information on pattern matching. substring('Thomas' from '%#"o_a#"_' for '#') oma
1) SUBSTRING(string , n,f) n์๋ฆฌ๋ถํฐ f๊น์ง ๋ฌธ์์ด ์ถ์ถ

2) SUBSTRING(string , 'regex format') n์๋ฆฌ๋ถํฐ f๊น์ง ๋ฌธ์์ด ์ถ์ถ

3) SUBSTRING(string , '#a-b#') escape letter "##"
'๐ข๏ธ Database' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[WSL] ssh: connect to host localhost port 22: Connection refused (0) | 2023.10.29 |
---|---|
[SQL]Window ํจ์ First_value/Last_value ํ์ฉํ๊ธฐ (0) | 2023.08.26 |
[SQL] LIKE (0) | 2023.08.20 |
[SQL] NULLIF, NVL(COALESCE) ํจ์ (0) | 2023.08.19 |
[SQL] Count ํจ์, Sequel vs SQL (0) | 2023.08.19 |
PostgreSQL ๋ฌธ๋ฒ
์์ Table - Ticker information

NOTE
https://www.postgresql.org/docs/current/functions-string.html
9.4. String Functions and Operators
9.4. String Functions and Operators 9.4.1. format This section describes functions and operators for examining and manipulating string values. Strings in โฆ
www.postgresql.org
๋ฌธ๋ฒ์ ์์ PostgreSQL์ ์ฌ์ฉ ๋๋ ๋ฌธ์์ด ํจ์์ ์ฐ์ฐ์ ์ฌ์ฉ์
SQL์ ์ผํ๊ฐ ์๋ ํค์๋๋ฅผ ์ฌ์ฉํ์ฌ ์ธ์๋ฅผ ๊ตฌ๋ถํ๋ ์ผ๋ถ ๋ฌธ์์ด ํจ์๋ฅผ ์ ์ํฉ๋๋ค. ์์ธํ ๋ด์ฉ์ ํ 9.9์ ๋์ ์์ต๋๋ค. PostgreSQL์ ์ผ๋ฐ ํจ์ ํธ์ถ ๊ตฌ๋ฌธ์ ์ฌ์ฉํ๋ ์ด๋ฌํ ํจ์์ ๋ฒ์ ๋ ์ ๊ณตํฉ๋๋ค(ํ 9.10 ์ฐธ์กฐ).
๋ฌธ์์ด ์ฐ๊ฒฐ ์ฐ์ฐ์(||)๋ ํ 9.9์ ํ์๋ ๊ฒ์ฒ๋ผ ํ๋ ์ด์์ ์ ๋ ฅ์ด ๋ฌธ์์ด ์ ํ์ธ ํ ๋ฌธ์์ด์ด ์๋ ์ ๋ ฅ์ ํ์ฉํฉ๋๋ค. ๊ทธ ์ธ์ ๊ฒฝ์ฐ์๋ ํ ์คํธ์ ๋ช ์์ ๊ฐ์ ๋ฅผ ์ฝ์ ํ์ฌ ๋ฌธ์์ด์ด ์๋ ์ ๋ ฅ์ ํ์ฉํ ์ ์์ต๋๋ค. ๋ฌธ์์ด ์๋ ์ ๋ ฅ์ ํ์ฉํจ์ผ๋ก์จ ์์นซ ALL ๋ชจ๋ ๊ฒฝ์ฐ์ ์๋ฅผ ๊ฐ์ ธ์ฌ์ ์๋ค.
1) LEFT
left ( string text, n integer ) โ text
Returns first n characters in the string, or when n is negative, returns all but last |n| characters.
left('abcde', 2) โ ab
LEFT(๋ฌธ์์ด, ์ผ์ชฝ๋ถํฐ ์ถ์ถ ๋ฌธ์์ด ์)
SELECT LEFT(si.SYMBOL,1) LEFT1
, LEFT(si.SYMBOL,2) LEFT2
, LEFT(si.SYMBOL,3) LEFT3
, LEFT(si.SYMBOL,4) LEFT4
, LEFT(si.SYMBOL,5) LEFT5
, si.SYMBOL
FROM re_stock.STOCK_INFO si
WHERE si.SYMBOL IN ("AAPL","GOOGL","TSLA","LCID","MSFT","OPEN")
ORDER BY si.SYMBOL DESC

0์ดํ์ ๊ฐ์ ๋ชจ๋ "" ๋น ๋ฌธ์์ด์ Returnํ๋ค. NULL ๊ฐ์ Returnํ์ง ์์ผ๋ฏ๋ก ์ฃผ์
2) REPLACE
replace ( string text, from text, to text ) โ text
Replaces all occurrences in string of substring from with substring to.
replace('abcdefabcdef', 'cd', 'XX') โ abXXefabXXef
REPLACE( ๋ฌธ์์ด, ๋ณ๊ฒฝ ์ ๋ฌธ์์ด, ๋ณ๊ฒฝ ํ ๋ฌธ์์ด)
SELECT si.SYMBOL SYMBOL
, REPLACE(si.SYMBOL, "FB", "META") "REPLACE"
FROM re_stock.STOCK_INFO si
WHERE si.SYMBOL IN ("FB");

FB(Facebook)์์ Meta๋ก ์ฌ๋ช ์ ๋ฐ๊ฟ REPLACE ํจ์๋ก ๋ณ๊ฒฝ
3) SUBSTRING
/*1*/
substring(string [from int] [for int]) text Extract substring substring('Thomas' from 2 for 3) hom
/*2*/
substring(string from pattern) text Extract substring matching POSIX regular expression. See Section 9.7 for more information on pattern matching. substring('Thomas' from '...$') mas
/*3*/
substring(string from pattern for escape) text Extract substring matching SQL regular expression. See Section 9.7 for more information on pattern matching. substring('Thomas' from '%#"o_a#"_' for '#') oma
1) SUBSTRING(string , n,f) n์๋ฆฌ๋ถํฐ f๊น์ง ๋ฌธ์์ด ์ถ์ถ

2) SUBSTRING(string , 'regex format') n์๋ฆฌ๋ถํฐ f๊น์ง ๋ฌธ์์ด ์ถ์ถ

3) SUBSTRING(string , '#a-b#') escape letter "##"
'๐ข๏ธ Database' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[WSL] ssh: connect to host localhost port 22: Connection refused (0) | 2023.10.29 |
---|---|
[SQL]Window ํจ์ First_value/Last_value ํ์ฉํ๊ธฐ (0) | 2023.08.26 |
[SQL] LIKE (0) | 2023.08.20 |
[SQL] NULLIF, NVL(COALESCE) ํจ์ (0) | 2023.08.19 |
[SQL] Count ํจ์, Sequel vs SQL (0) | 2023.08.19 |