postgresql_copy – Copy data between a file/program and a PostgreSQL table¶
New in version 2.9.
Parameters¶
Parameter | Choices/Defaults | Comments | ||
---|---|---|---|---|
ca_cert
string
|
Specifies the name of a file containing SSL certificate authority (CA) certificate(s).
If the file exists, the server's certificate will be verified to be signed by one of these authorities.
aliases: ssl_rootcert |
|||
columns
list
/ elements=string
|
List of column names for the src/dst table to COPY FROM/TO.
aliases: column |
|||
copy_from
path
|
Copy data from a file to a table (appending the data to whatever is in the table already).
Mutually exclusive with copy_to and src.
aliases: from |
|||
copy_to
path
|
Copy the contents of a table to a file.
Can also copy the results of a SELECT query.
Mutually exclusive with copy_from and dst.
aliases: to |
|||
db
string
|
Name of database to connect to.
aliases: login_db |
|||
dst
string
|
Copy data to dst=tablename from copy_from=/path/to/data.file.
Used with copy_from only.
aliases: destination |
|||
login_host
string
|
Host running the database.
|
|||
login_password
string
|
The password used to authenticate with.
|
|||
login_unix_socket
string
|
Path to a Unix domain socket for local connections.
|
|||
login_user
string
|
Default: "postgres"
|
The username used to authenticate with.
|
||
options
dictionary
|
Options of COPY command.
|
Default: 5432
|
Database port to connect to.
aliases: login_port |
|
program
boolean
|
|
Mark src/dst as a program. Data will be copied to/from a program.
|
Switch to session_role after connecting. The specified session_role must be a role that the current login_user is a member of.
Permissions checking for SQL commands is carried out as though the session_role were the one that had logged in originally.
|
|
src
string
|
Copy data from copy_from to src=tablename.
Used with copy_to only.
aliases: source |
|||
ssl_mode
string
|
|
Determines whether or with what priority a secure SSL TCP/IP connection will be negotiated with the server.
See
Notes¶Note
See Also¶See also
Examples¶- name: Copy text TAB-separated data from file /tmp/data.txt to acme table
postgresql_copy:
copy_from: /tmp/data.txt
dst: acme
- name: Copy CSV (comma-separated) data from file /tmp/data.csv to columns id, name of table acme
postgresql_copy:
copy_from: /tmp/data.csv
dst: acme
columns: id,name
options:
format: csv
- name: >
Copy text vertical-bar-separated data from file /tmp/data.txt to bar table.
The NULL values are specified as N
postgresql_copy:
copy_from: /tmp/data.csv
dst: bar
options:
delimiter: '|'
null: 'N'
- name: Copy data from acme table to file /tmp/data.txt in text format, TAB-separated
postgresql_copy:
src: acme
copy_to: /tmp/data.txt
- name: Copy data from SELECT query to/tmp/data.csv in CSV format
postgresql_copy:
src: 'SELECT * FROM acme'
copy_to: /tmp/data.csv
options:
format: csv
- name: Copy CSV data from my_table to gzip
postgresql_copy:
src: my_table
copy_to: 'gzip > /tmp/data.csv.gz'
program: yes
options:
format: csv
- name: >
Copy data from columns id, name of table bar to /tmp/data.txt.
Output format is text, vertical-bar-separated, NULL as N
postgresql_copy:
src: bar
columns:
- id
- name
copy_to: /tmp/data.csv
options:
delimiter: '|'
null: 'N'
Return Values¶Common return values are documented here, the following are the fields unique to this module: Status¶
Authors¶
Hint If you notice any issues in this documentation, you can edit this document to improve it. |