Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
a1d2e165
Commit
a1d2e165
authored
Oct 31, 2008
by
Heikki Linnakangas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test case for CREATE CAST.
parent
092bc496
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
132 additions
and
3 deletions
+132
-3
src/test/regress/expected/create_cast.out
src/test/regress/expected/create_cast.out
+74
-0
src/test/regress/parallel_schedule
src/test/regress/parallel_schedule
+2
-2
src/test/regress/serial_schedule
src/test/regress/serial_schedule
+2
-1
src/test/regress/sql/create_cast.sql
src/test/regress/sql/create_cast.sql
+54
-0
No files found.
src/test/regress/expected/create_cast.out
0 → 100644
View file @
a1d2e165
--
-- CREATE_CAST
--
-- Create some types to test with
CREATE TYPE casttesttype;
CREATE FUNCTION casttesttype_in(cstring)
RETURNS casttesttype
AS 'textin'
LANGUAGE internal STRICT;
NOTICE: return type casttesttype is only a shell
CREATE FUNCTION casttesttype_out(casttesttype)
RETURNS cstring
AS 'textout'
LANGUAGE internal STRICT;
NOTICE: argument type casttesttype is only a shell
CREATE TYPE casttesttype (
internallength = variable,
input = casttesttype_in,
output = casttesttype_out,
alignment = int4
);
-- a dummy function to test with
CREATE FUNCTION casttestfunc(casttesttype) RETURNS int4 LANGUAGE SQL AS
$$ SELECT 1; $$;
SELECT casttestfunc('foo'::text); -- fails, as there's no cast
ERROR: function casttestfunc(text) does not exist
LINE 1: SELECT casttestfunc('foo'::text);
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
-- Try binary coercion cast
CREATE CAST (text AS casttesttype) WITHOUT FUNCTION;
SELECT casttestfunc('foo'::text); -- doesn't work, as the cast is explicit
ERROR: function casttestfunc(text) does not exist
LINE 1: SELECT casttestfunc('foo'::text);
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
SELECT casttestfunc('foo'::text::casttesttype); -- should work
casttestfunc
--------------
1
(1 row)
DROP CAST (text AS casttesttype); -- cleanup
-- Try IMPLICIT binary coercion cast
CREATE CAST (text AS casttesttype) WITHOUT FUNCTION AS IMPLICIT;
SELECT casttestfunc('foo'::text); -- Should work now
casttestfunc
--------------
1
(1 row)
-- Try I/O conversion cast.
SELECT 1234::int4::casttesttype; -- No cast yet, should fail
ERROR: cannot cast type integer to casttesttype
LINE 1: SELECT 1234::int4::casttesttype;
^
CREATE CAST (int4 AS casttesttype) WITH INOUT;
SELECT 1234::int4::casttesttype; -- Should work now
casttesttype
--------------
1234
(1 row)
DROP CAST (int4 AS casttesttype);
-- Try cast with a function
CREATE FUNCTION int4_casttesttype(int4) RETURNS casttesttype LANGUAGE SQL AS
$$ SELECT ('foo'::text || $1::text)::casttesttype; $$;
CREATE CAST (int4 AS casttesttype) WITH FUNCTION int4_casttesttype(int4) AS IMPLICIT;
SELECT 1234::int4::casttesttype; -- Should work now
casttesttype
--------------
foo1234
(1 row)
src/test/regress/parallel_schedule
View file @
a1d2e165
# ----------
# $PostgreSQL: pgsql/src/test/regress/parallel_schedule,v 1.
49 2008/10/04 21:56:55 tgl
Exp $
# $PostgreSQL: pgsql/src/test/regress/parallel_schedule,v 1.
50 2008/10/31 09:17:16 heikki
Exp $
#
# By convention, we put no more than twenty tests in any one parallel group;
# this limits the number of connections needed to run the tests.
...
...
@@ -47,7 +47,7 @@ test: copy copyselect
# ----------
# Another group of parallel tests
# ----------
test: constraints triggers create_misc create_aggregate create_operator inherit vacuum drop_if_exists
test: constraints triggers create_misc create_aggregate create_operator inherit vacuum drop_if_exists
create_cast
# Depends on the above
test: create_index create_view
...
...
src/test/regress/serial_schedule
View file @
a1d2e165
# $PostgreSQL: pgsql/src/test/regress/serial_schedule,v 1.4
6 2008/10/04 21:56:55 tgl
Exp $
# $PostgreSQL: pgsql/src/test/regress/serial_schedule,v 1.4
7 2008/10/31 09:17:16 heikki
Exp $
# This should probably be in an order similar to parallel_schedule.
test: boolean
test: char
...
...
@@ -48,6 +48,7 @@ test: create_function_1
test: create_type
test: create_table
test: create_function_2
test: create_cast
test: copy
test: copyselect
test: constraints
...
...
src/test/regress/sql/create_cast.sql
0 → 100644
View file @
a1d2e165
--
-- CREATE_CAST
--
-- Create some types to test with
CREATE
TYPE
casttesttype
;
CREATE
FUNCTION
casttesttype_in
(
cstring
)
RETURNS
casttesttype
AS
'textin'
LANGUAGE
internal
STRICT
;
CREATE
FUNCTION
casttesttype_out
(
casttesttype
)
RETURNS
cstring
AS
'textout'
LANGUAGE
internal
STRICT
;
CREATE
TYPE
casttesttype
(
internallength
=
variable
,
input
=
casttesttype_in
,
output
=
casttesttype_out
,
alignment
=
int4
);
-- a dummy function to test with
CREATE
FUNCTION
casttestfunc
(
casttesttype
)
RETURNS
int4
LANGUAGE
SQL
AS
$$
SELECT
1
;
$$
;
SELECT
casttestfunc
(
'foo'
::
text
);
-- fails, as there's no cast
-- Try binary coercion cast
CREATE
CAST
(
text
AS
casttesttype
)
WITHOUT
FUNCTION
;
SELECT
casttestfunc
(
'foo'
::
text
);
-- doesn't work, as the cast is explicit
SELECT
casttestfunc
(
'foo'
::
text
::
casttesttype
);
-- should work
DROP
CAST
(
text
AS
casttesttype
);
-- cleanup
-- Try IMPLICIT binary coercion cast
CREATE
CAST
(
text
AS
casttesttype
)
WITHOUT
FUNCTION
AS
IMPLICIT
;
SELECT
casttestfunc
(
'foo'
::
text
);
-- Should work now
-- Try I/O conversion cast.
SELECT
1234
::
int4
::
casttesttype
;
-- No cast yet, should fail
CREATE
CAST
(
int4
AS
casttesttype
)
WITH
INOUT
;
SELECT
1234
::
int4
::
casttesttype
;
-- Should work now
DROP
CAST
(
int4
AS
casttesttype
);
-- Try cast with a function
CREATE
FUNCTION
int4_casttesttype
(
int4
)
RETURNS
casttesttype
LANGUAGE
SQL
AS
$$
SELECT
(
'foo'
::
text
||
$
1
::
text
)::
casttesttype
;
$$
;
CREATE
CAST
(
int4
AS
casttesttype
)
WITH
FUNCTION
int4_casttesttype
(
int4
)
AS
IMPLICIT
;
SELECT
1234
::
int4
::
casttesttype
;
-- Should work now
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment