diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-08-30 23:34:22 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-08-30 23:34:22 +0000 |
| commit | 85188ab8838bf19cdf12298e1b6c29e12f9b9a3c (patch) | |
| tree | 285f4ee5fe8c623b8eea4caa5a664aeffd3fe96a /src/bin | |
| parent | 0d5065781dd1486d57357c49384a034b45bb027a (diff) | |
| download | postgresql-85188ab8838bf19cdf12298e1b6c29e12f9b9a3c.tar.gz | |
Extend COPY to support COPY (SELECT ...) TO ...
Bernd Helmle
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/psql/copy.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index 0d7cb5b4e0..6e514c1c06 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.67 2006/08/29 15:19:50 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.68 2006/08/30 23:34:22 tgl Exp $ */ #include "postgres_fe.h" #include "copy.h" @@ -39,6 +39,9 @@ * \copy tablename [(columnlist)] from|to filename * [ with ] [ binary ] [ oids ] [ delimiter [as] char ] [ null [as] string ] * + * \copy ( select stmt ) to filename + * [ with ] [ binary ] [ delimiter [as] char ] [ null [as] string ] + * * The pre-7.3 syntax was: * \copy [ binary ] tablename [(columnlist)] [with oids] from|to filename * [ [using] delimiters char ] [ with null as string ] @@ -142,6 +145,26 @@ parse_slash_copy(const char *args) result->table = pg_strdup(token); + /* Handle COPY (SELECT) case */ + if (token[0] == '(') + { + int parens = 1; + + while (parens > 0) + { + token = strtokx(NULL, whitespace, ".,()", "\"'", + nonstd_backslash, true, false, pset.encoding); + if (!token) + goto error; + if (token[0] == '(') + parens++; + else if (token[0] == ')') + parens--; + xstrcat(&result->table, " "); + xstrcat(&result->table, token); + } + } + token = strtokx(NULL, whitespace, ".,()", "\"", 0, false, false, pset.encoding); if (!token) |
