Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgresql_query: fix datetime.timedelta type handling #51

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- postgresql_query - fix datetime.timedelta type handling (https://github.com/ansible-collections/community.postgresql/issues/47).
4 changes: 4 additions & 0 deletions plugins/modules/postgresql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@
# ansible.module_utils.postgres
pass

import datetime
import decimal
import re

Expand Down Expand Up @@ -450,6 +451,9 @@ def main():
if isinstance(val, decimal.Decimal):
row[key] = float(val)

elif isinstance(val, datetime.timedelta):
row[key] = str(val)

query_result.append(row)

except Psycopg2ProgrammingError as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,37 @@
- assert:
that:
- result.rowcount == 1

#############################################################################
# Issue https://github.com/ansible-collections/community.postgresql/issues/47
- name: Get datetime.timedelta value
become_user: '{{ pg_user }}'
become: true
postgresql_query:
login_user: '{{ pg_user }}'
db: postgres
query: "SELECT EXTRACT(epoch from make_interval(secs => 3))"
register: result
when: postgres_version_resp.stdout is version('10', '>=')

- assert:
that:
- result.rowcount == 1
- result.query_result[0]["date_part"] == 3
when: postgres_version_resp.stdout is version('10', '>=')

- name: Get interval value
become_user: '{{ pg_user }}'
become: true
postgresql_query:
login_user: '{{ pg_user }}'
db: postgres
query: "SELECT make_interval(secs => 3)"
register: result
when: postgres_version_resp.stdout is version('10', '>=')

- assert:
that:
- result.rowcount == 1
- result.query_result[0]["make_interval"] == "0:00:03"
when: postgres_version_resp.stdout is version('10', '>=')