-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eafdeee
commit 1fe2582
Showing
4 changed files
with
128 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,86 @@ | ||
create domain domainvarchar varchar(5); | ||
create domain domainnumeric numeric(8,2); | ||
create domain domainint4 int4; | ||
create domain domaintext text; | ||
-- Test tables using domains | ||
create table basictest | ||
( testint4 domainint4 | ||
, testtext domaintext | ||
, testvarchar domainvarchar | ||
, testnumeric domainnumeric | ||
); | ||
INSERT INTO basictest values ('88', 'haha', 'short'); -- Good | ||
INSERT INTO basictest values ('88', 'haha', 'short text'); -- Bad varchar | ||
INSERT INTO basictest values ('88', 'haha', 'short', '123.12'); -- Good | ||
INSERT INTO basictest values ('88', 'haha', 'short text', '123.12'); -- Bad varchar | ||
ERROR: value too long for type character varying(5) | ||
INSERT INTO basictest values ('888', 'haha', 'short'); | ||
INSERT INTO basictest values ('88', 'haha', 'short', '123.1212'); -- Truncate numeric | ||
select * from basictest; | ||
testint4 | testtext | testvarchar | ||
----------+----------+------------- | ||
88 | haha | short | ||
888 | haha | short | ||
testint4 | testtext | testvarchar | testnumeric | ||
----------+----------+-------------+------------- | ||
88 | haha | short | 123.12 | ||
88 | haha | short | 123.12 | ||
(2 rows) | ||
|
||
select testtext || testvarchar as concat, testint4 + 12 as sum | ||
select testtext || testvarchar as concat, testnumeric + 42 as sum | ||
from basictest; | ||
concat | sum | ||
-----------+----- | ||
hahashort | 100 | ||
hahashort | 900 | ||
concat | sum | ||
-----------+-------- | ||
hahashort | 165.12 | ||
hahashort | 165.12 | ||
(2 rows) | ||
|
||
select * from basictest where testtext = 'haha'; | ||
testint4 | testtext | testvarchar | testnumeric | ||
----------+----------+-------------+------------- | ||
88 | haha | short | 123.12 | ||
88 | haha | short | 123.12 | ||
(2 rows) | ||
|
||
select * from basictest where testvarchar = 'short'; | ||
testint4 | testtext | testvarchar | testnumeric | ||
----------+----------+-------------+------------- | ||
88 | haha | short | 123.12 | ||
88 | haha | short | 123.12 | ||
(2 rows) | ||
|
||
-- array_domain | ||
create domain domain_int_array as INT[]; | ||
CREATE TABLE domain_int_array_1d(a domain_int_array); | ||
INSERT INTO domain_int_array_1d SELECT CAST(a as domain_int_array) FROM (VALUES | ||
('{1, 2, 3}'), | ||
(NULL), | ||
('{4, 5, NULL, 7}'), | ||
('{}') | ||
) t(a); | ||
SELECT * FROM domain_int_array_1d; | ||
a | ||
-------------- | ||
{1,2,3} | ||
|
||
{4,5,NULL,7} | ||
{} | ||
(4 rows) | ||
|
||
CREATE TABLE domain_int_array_2d(a domainint4[]); | ||
INSERT INTO domain_int_array_2d SELECT CAST(a as domain_int_array) FROM (VALUES | ||
('{1, 2, 3}'), | ||
(NULL), | ||
('{4, 5, NULL, 7}'), | ||
('{}') | ||
) t(a); | ||
SELECT * FROM domain_int_array_2d; | ||
a | ||
-------------- | ||
{1,2,3} | ||
|
||
{4,5,NULL,7} | ||
{} | ||
(4 rows) | ||
|
||
drop table domain_int_array_2d; | ||
drop table domain_int_array_1d; | ||
drop domain domain_int_array; | ||
drop table basictest; | ||
drop domain domainvarchar restrict; | ||
drop domain domainnumeric restrict; | ||
drop domain domainint4 restrict; | ||
drop domain domaintext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,53 @@ | ||
create domain domainvarchar varchar(5); | ||
create domain domainnumeric numeric(8,2); | ||
create domain domainint4 int4; | ||
create domain domaintext text; | ||
|
||
-- Test tables using domains | ||
create table basictest | ||
( testint4 domainint4 | ||
, testtext domaintext | ||
, testvarchar domainvarchar | ||
, testnumeric domainnumeric | ||
); | ||
|
||
INSERT INTO basictest values ('88', 'haha', 'short'); -- Good | ||
INSERT INTO basictest values ('88', 'haha', 'short text'); -- Bad varchar | ||
INSERT INTO basictest values ('888', 'haha', 'short'); | ||
INSERT INTO basictest values ('88', 'haha', 'short', '123.12'); -- Good | ||
INSERT INTO basictest values ('88', 'haha', 'short text', '123.12'); -- Bad varchar | ||
INSERT INTO basictest values ('88', 'haha', 'short', '123.1212'); -- Truncate numeric | ||
|
||
select * from basictest; | ||
|
||
select testtext || testvarchar as concat, testint4 + 12 as sum | ||
select testtext || testvarchar as concat, testnumeric + 42 as sum | ||
from basictest; | ||
|
||
select * from basictest where testtext = 'haha'; | ||
select * from basictest where testvarchar = 'short'; | ||
|
||
-- array_domain | ||
create domain domain_int_array as INT[]; | ||
CREATE TABLE domain_int_array_1d(a domain_int_array); | ||
INSERT INTO domain_int_array_1d SELECT CAST(a as domain_int_array) FROM (VALUES | ||
('{1, 2, 3}'), | ||
(NULL), | ||
('{4, 5, NULL, 7}'), | ||
('{}') | ||
) t(a); | ||
SELECT * FROM domain_int_array_1d; | ||
|
||
CREATE TABLE domain_int_array_2d(a domainint4[]); | ||
INSERT INTO domain_int_array_2d SELECT CAST(a as domain_int_array) FROM (VALUES | ||
('{1, 2, 3}'), | ||
(NULL), | ||
('{4, 5, NULL, 7}'), | ||
('{}') | ||
) t(a); | ||
SELECT * FROM domain_int_array_2d; | ||
|
||
drop table domain_int_array_2d; | ||
drop table domain_int_array_1d; | ||
drop domain domain_int_array; | ||
drop table basictest; | ||
drop domain domainvarchar restrict; | ||
drop domain domainnumeric restrict; | ||
drop domain domainint4 restrict; | ||
drop domain domaintext; |