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
1e4b0384
Commit
1e4b0384
authored
Oct 05, 2008
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve behavior of WITH RECURSIVE with an untyped literal in the
non-recursive term. Per an example from Dickson S. Guedes.
parent
08142504
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
5 deletions
+56
-5
src/backend/parser/parse_cte.c
src/backend/parser/parse_cte.c
+21
-5
src/test/regress/expected/with.out
src/test/regress/expected/with.out
+24
-0
src/test/regress/sql/with.sql
src/test/regress/sql/with.sql
+11
-0
No files found.
src/backend/parser/parse_cte.c
View file @
1e4b0384
...
...
@@ -8,12 +8,13 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/parse_cte.c,v 2.
1 2008/10/04 21:56:54
tgl Exp $
* $PostgreSQL: pgsql/src/backend/parser/parse_cte.c,v 2.
2 2008/10/05 22:50:55
tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "catalog/pg_type.h"
#include "nodes/nodeFuncs.h"
#include "parser/analyze.h"
#include "parser/parse_cte.h"
...
...
@@ -339,6 +340,8 @@ analyzeCTETargetList(ParseState *pstate, CommonTableExpr *cte, List *tlist)
foreach
(
tlistitem
,
tlist
)
{
TargetEntry
*
te
=
(
TargetEntry
*
)
lfirst
(
tlistitem
);
Oid
coltype
;
int32
coltypmod
;
if
(
te
->
resjunk
)
continue
;
...
...
@@ -351,10 +354,23 @@ analyzeCTETargetList(ParseState *pstate, CommonTableExpr *cte, List *tlist)
attrname
=
pstrdup
(
te
->
resname
);
cte
->
ctecolnames
=
lappend
(
cte
->
ctecolnames
,
makeString
(
attrname
));
}
cte
->
ctecoltypes
=
lappend_oid
(
cte
->
ctecoltypes
,
exprType
((
Node
*
)
te
->
expr
));
cte
->
ctecoltypmods
=
lappend_int
(
cte
->
ctecoltypmods
,
exprTypmod
((
Node
*
)
te
->
expr
));
coltype
=
exprType
((
Node
*
)
te
->
expr
);
coltypmod
=
exprTypmod
((
Node
*
)
te
->
expr
);
/*
* If the CTE is recursive, force the exposed column type of any
* "unknown" column to "text". This corresponds to the fact that
* SELECT 'foo' UNION SELECT 'bar' will ultimately produce text.
* We might see "unknown" as a result of an untyped literal in
* the non-recursive term's select list, and if we don't convert
* to text then we'll have a mismatch against the UNION result.
*/
if
(
cte
->
cterecursive
&&
coltype
==
UNKNOWNOID
)
{
coltype
=
TEXTOID
;
coltypmod
=
-
1
;
/* should be -1 already, but be sure */
}
cte
->
ctecoltypes
=
lappend_oid
(
cte
->
ctecoltypes
,
coltype
);
cte
->
ctecoltypmods
=
lappend_int
(
cte
->
ctecoltypmods
,
coltypmod
);
}
if
(
varattno
<
numaliases
)
ereport
(
ERROR
,
...
...
src/test/regress/expected/with.out
View file @
1e4b0384
...
...
@@ -69,6 +69,30 @@ SELECT * FROM t LIMIT 10;
10
(10 rows)
-- Test behavior with an unknown-type literal in the WITH
WITH q AS (SELECT 'foo' AS x)
SELECT x, x IS OF (unknown) as is_unknown FROM q;
x | is_unknown
-----+------------
foo | t
(1 row)
WITH RECURSIVE t(n) AS (
SELECT 'foo'
UNION ALL
SELECT n || ' bar' FROM t WHERE length(n) < 20
)
SELECT n, n IS OF (text) as is_text FROM t;
n | is_text
-------------------------+---------
foo | t
foo bar | t
foo bar bar | t
foo bar bar bar | t
foo bar bar bar bar | t
foo bar bar bar bar bar | t
(6 rows)
--
-- Some examples with a tree
--
...
...
src/test/regress/sql/with.sql
View file @
1e4b0384
...
...
@@ -38,6 +38,17 @@ UNION ALL
SELECT
n
+
1
FROM
t
)
SELECT
*
FROM
t
LIMIT
10
;
-- Test behavior with an unknown-type literal in the WITH
WITH
q
AS
(
SELECT
'foo'
AS
x
)
SELECT
x
,
x
IS
OF
(
unknown
)
as
is_unknown
FROM
q
;
WITH
RECURSIVE
t
(
n
)
AS
(
SELECT
'foo'
UNION
ALL
SELECT
n
||
' bar'
FROM
t
WHERE
length
(
n
)
<
20
)
SELECT
n
,
n
IS
OF
(
text
)
as
is_text
FROM
t
;
--
-- Some examples with a tree
--
...
...
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