mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-08-02 07:24:21 +02:00
errors=r.SET_NULL/r.IGNORE options for parsedate/parsedatetime, closes #416
This commit is contained in:
parent
433813612f
commit
878d5f5cea
6 changed files with 108 additions and 20 deletions
|
|
@ -547,15 +547,25 @@ See :ref:`cli_convert`.
|
|||
|
||||
r.jsonsplit(value, delimiter=',', type=<class 'str'>)
|
||||
|
||||
Convert a string like a,b,c into a JSON array ["a", "b", "c"]
|
||||
Convert a string like a,b,c into a JSON array ["a", "b", "c"]
|
||||
|
||||
r.parsedate(value, dayfirst=False, yearfirst=False)
|
||||
r.parsedate(value, dayfirst=False, yearfirst=False, errors=None)
|
||||
|
||||
Parse a date and convert it to ISO date format: yyyy-mm-dd
|
||||
Parse a date and convert it to ISO date format: yyyy-mm-dd
|
||||
|
||||
- dayfirst=True: treat xx as the day in xx/yy/zz
|
||||
- yearfirst=True: treat xx as the year in xx/yy/zz
|
||||
- errors=r.IGNORE to ignore values that cannot be parsed
|
||||
- errors=r.SET_NULL to set values that cannot be parsed to null
|
||||
|
||||
r.parsedatetime(value, dayfirst=False, yearfirst=False)
|
||||
r.parsedatetime(value, dayfirst=False, yearfirst=False, errors=None)
|
||||
|
||||
Parse a datetime and convert it to ISO datetime format: yyyy-mm-ddTHH:MM:SS
|
||||
Parse a datetime and convert it to ISO datetime format: yyyy-mm-ddTHH:MM:SS
|
||||
|
||||
- dayfirst=True: treat xx as the day in xx/yy/zz
|
||||
- yearfirst=True: treat xx as the year in xx/yy/zz
|
||||
- errors=r.IGNORE to ignore values that cannot be parsed
|
||||
- errors=r.SET_NULL to set values that cannot be parsed to null
|
||||
|
||||
You can use these recipes like so:
|
||||
|
||||
|
|
|
|||
12
docs/cli.rst
12
docs/cli.rst
|
|
@ -1303,12 +1303,20 @@ Various built-in recipe functions are available for common operations. These are
|
|||
|
||||
Would produce an array like this: ``[1.2, 3.0, 4.5]``
|
||||
|
||||
``r.parsedate(value, dayfirst=False, yearfirst=False)``
|
||||
``r.parsedate(value, dayfirst=False, yearfirst=False, errors=None)``
|
||||
Parse a date and convert it to ISO date format: ``yyyy-mm-dd``
|
||||
|
||||
In the case of dates such as ``03/04/05`` U.S. ``MM/DD/YY`` format is assumed - you can use ``dayfirst=True`` or ``yearfirst=True`` to change how these ambiguous dates are interpreted.
|
||||
|
||||
``r.parsedatetime(value, dayfirst=False, yearfirst=False)``
|
||||
Use the ``errors=`` parameter to specify what should happen if a value cannot be parsed.
|
||||
|
||||
By default, if any value cannot be parsed an error will be occurred and all values will be left as they were.
|
||||
|
||||
Set ``errors=r.IGNORE`` to ignore any values that cannot be parsed, leaving them unchanged.
|
||||
|
||||
Set ``errors=r.SET_NULL`` to set any values that cannot be parsed to ``null``.
|
||||
|
||||
``r.parsedatetime(value, dayfirst=False, yearfirst=False, errors=None)``
|
||||
Parse a datetime and convert it to ISO datetime format: ``yyyy-mm-ddTHH:MM:SS``
|
||||
|
||||
These recipes can be used in the code passed to ``sqlite-utils convert`` like this::
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue