File tree Expand file tree Collapse file tree
Урок 10.3 Преобразования типов данных Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Преобразования типов данных
2+ ``` sql
3+ select
4+ f .rental_rate ,
5+ cast(f .rental_rate as varchar (10 ))
6+ from
7+ film f;
8+ ```
9+ ``` sql
10+ select
11+ 1 as filed1
12+ union all
13+ select
14+ 1 .5 as filed1;
15+ ```
16+ ``` sql
17+ with cte as (
18+ select
19+ 1 as filed1
20+ union all
21+ select
22+ 1 .5 as filed1
23+
24+ )
25+
26+ select
27+ filed1,
28+ pg_typeof(filed1)
29+ from
30+ cte;
31+ ```
32+ ``` sql
33+ select
34+ cast(1 as numeric ) as filed1
35+ union all
36+
37+ select
38+ 1 .5 as filed1;
39+ ```
40+ ``` sql
41+ select
42+ 1 ::numeric as filed1
43+ union all
44+ select
45+ 1 .5 as filed1;
46+ ```
47+ ``` sql
48+ with cte as (
49+ select
50+ 1 as filed1
51+ union all
52+ select
53+ 1 as filed1
54+ )
55+ select
56+ filed1,
57+ pg_typeof(filed1)
58+ from
59+ cte;
60+ ```
61+ ``` sql
62+ select
63+ 1 as filed1
64+ union all
65+
66+ select
67+ ' 2' as filed1;
68+ ```
69+ ``` sql
70+ select
71+ 1 as filed1
72+ union all
73+ select
74+ ' some text' as filed1;
75+ ```
76+ ``` sql
77+ select
78+ cast(1 as varchar ) as filed1
79+ union all
80+ select
81+ ' 2' as filed1;
82+ ```
83+ ``` sql
84+ select
85+ 1 as field1
86+ union all
87+ select
88+ false as field1;
89+ ```
90+ ``` sql
91+ select
92+ now();
93+ ```
94+ ``` sql
95+ select
96+ to_char(now(), ' yyyy---mm---dd hh:mi' );
97+ ```
98+ ``` sql
99+ select
100+ to_char(now(), ' dd/mm/yyyy' );
101+ ```
102+ ``` sql
103+ select
104+ to_char(now(), ' dd/mon/yyyy' );
105+ ```
106+ ``` sql
107+ select
108+ to_char(now(), ' dd/month/yy hh24:mi:ss' );
109+ ```
110+ ``` sql
111+ select
112+ cast(' 2021-10-01' as date );
113+ ```
114+ ``` sql
115+ select
116+ cast(' 01/10/2021 10:21' as timestamp );
117+ ```
118+ ``` sql
119+ select
120+ to_date(' 21/10/01' , ' yy/mm/dd' );
121+ ```
122+ ``` sql
123+ select
124+ to_timestamp(' 21/10/01 10:11' , ' yy/mm/dd hh24:mi' );
125+ ```
You can’t perform that action at this time.
0 commit comments