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
de7531a9
Commit
de7531a9
authored
Jul 25, 2009
by
Andrew Dunstan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow * as parameter for FORCE QUOTE for COPY CSV. Itagaki Takahiro.
parent
8af12bca
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
7 deletions
+32
-7
doc/src/sgml/ref/copy.sgml
doc/src/sgml/ref/copy.sgml
+5
-3
src/backend/commands/copy.c
src/backend/commands/copy.c
+17
-3
src/backend/parser/gram.y
src/backend/parser/gram.y
+5
-1
src/test/regress/expected/copy2.out
src/test/regress/expected/copy2.out
+4
-0
src/test/regress/sql/copy2.sql
src/test/regress/sql/copy2.sql
+1
-0
No files found.
doc/src/sgml/ref/copy.sgml
View file @
de7531a9
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/copy.sgml,v 1.8
5 2009/02/06 21:22:49 tgl
Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/copy.sgml,v 1.8
6 2009/07/25 00:07:10 adunstan
Exp $
PostgreSQL documentation
-->
...
...
@@ -44,7 +44,7 @@ COPY { <replaceable class="parameter">tablename</replaceable> [ ( <replaceable c
[ CSV [ HEADER ]
[ QUOTE [ AS ] '<replaceable class="parameter">quote</replaceable>' ]
[ ESCAPE [ AS ] '<replaceable class="parameter">escape</replaceable>' ]
[ FORCE QUOTE
<replaceable class="parameter">column</replaceable> [, ...]
]
[ FORCE QUOTE
{ <replaceable class="parameter">column</replaceable> [, ...] | * }
]
</synopsis>
</refsynopsisdiv>
...
...
@@ -248,7 +248,9 @@ COPY { <replaceable class="parameter">tablename</replaceable> [ ( <replaceable c
<para>
In <literal>CSV</> <command>COPY TO</> mode, forces quoting to be
used for all non-<literal>NULL</> values in each specified column.
<literal>NULL</> output is never quoted.
<literal>NULL</> output is never quoted. If <literal>*</> is specified,
non-<literal>NULL</> values for all columns of the table will be
quoted.
</para>
</listitem>
</varlistentry>
...
...
src/backend/commands/copy.c
View file @
de7531a9
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.31
2 2009/06/11 14:48:55 momji
an Exp $
* $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.31
3 2009/07/25 00:07:11 adunst
an Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -730,6 +730,9 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
int
num_phys_attrs
;
uint64
processed
;
/* a dummy list that represents 'all-columns' */
List
all_columns
=
{
T_List
};
/* Allocate workspace and zero all fields */
cstate
=
(
CopyStateData
*
)
palloc0
(
sizeof
(
CopyStateData
));
...
...
@@ -808,7 +811,11 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
ereport
(
ERROR
,
(
errcode
(
ERRCODE_SYNTAX_ERROR
),
errmsg
(
"conflicting or redundant options"
)));
force_quote
=
(
List
*
)
defel
->
arg
;
if
(
IsA
(
defel
->
arg
,
A_Star
))
force_quote
=
&
all_columns
;
else
force_quote
=
(
List
*
)
defel
->
arg
;
}
else
if
(
strcmp
(
defel
->
defname
,
"force_notnull"
)
==
0
)
{
...
...
@@ -1092,7 +1099,14 @@ DoCopy(const CopyStmt *stmt, const char *queryString)
/* Convert FORCE QUOTE name list to per-column flags, check validity */
cstate
->
force_quote_flags
=
(
bool
*
)
palloc0
(
num_phys_attrs
*
sizeof
(
bool
));
if
(
force_quote
)
if
(
force_quote
==
&
all_columns
)
{
int
i
;
for
(
i
=
0
;
i
<
num_phys_attrs
;
i
++
)
cstate
->
force_quote_flags
[
i
]
=
true
;
}
else
if
(
force_quote
)
{
List
*
attnums
;
ListCell
*
cur
;
...
...
src/backend/parser/gram.y
View file @
de7531a9
...
...
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.67
1 2009/07/20 02:42:28
adunstan Exp $
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.67
2 2009/07/25 00:07:11
adunstan Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
...
...
@@ -2028,6 +2028,10 @@ copy_opt_item:
{
$$ = makeDefElem("force_quote", (Node *)$3);
}
| FORCE QUOTE '*'
{
$$ = makeDefElem("force_quote", (Node *)makeNode(A_Star));
}
| FORCE NOT NULL_P columnList
{
$$ = makeDefElem("force_notnull", (Node *)$4);
...
...
src/test/regress/expected/copy2.out
View file @
de7531a9
...
...
@@ -191,6 +191,10 @@ COPY y TO stdout WITH CSV FORCE QUOTE col2 ESCAPE E'\\';
"Jackson, Sam","\\h"
"It is \"perfect\"."," "
"",
COPY y TO stdout WITH CSV FORCE QUOTE *;
"Jackson, Sam","\h"
"It is ""perfect""."," "
"",
--test that we read consecutive LFs properly
CREATE TEMP TABLE testnl (a int, b text, c int);
COPY testnl FROM stdin CSV;
...
...
src/test/regress/sql/copy2.sql
View file @
de7531a9
...
...
@@ -128,6 +128,7 @@ INSERT INTO y VALUES ('', NULL);
COPY
y
TO
stdout
WITH
CSV
;
COPY
y
TO
stdout
WITH
CSV
QUOTE
'
''
'
DELIMITER
'|'
;
COPY
y
TO
stdout
WITH
CSV
FORCE
QUOTE
col2
ESCAPE
E
'
\\
'
;
COPY
y
TO
stdout
WITH
CSV
FORCE
QUOTE
*
;
--test that we read consecutive LFs properly
...
...
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