Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is <strong>a lot</strong> more efficient to set the time zone for your import session than to update the values later.</p> <p>I get the impression that you think of the time zone like a setting that applies to otherwise unchanged values in the tables. But it's not like that at all. Think of it as an input / output modifier. Actual <code>timestamp</code> values (with or without time zone) are <em>always</em> stored as UTC timestamps internally (number of seconds since <code>'2000-01-01 00:00'</code>). A lot more details:</p> <ul> <li><a href="https://stackoverflow.com/questions/9571392/ignoring-timezones-altogether-in-rails-and-postgresql/9576170#9576170">Ignoring time zones altogether in Rails and PostgreSQL</a></li> </ul> <p>The <code>UPDATE</code> in your second example doubles the size of the table, as every single row is invalidated and a new version added (that's how <code>UPDATE</code> works with <a href="https://www.postgresql.org/docs/current/interactive/mvcc.html" rel="nofollow noreferrer">MVCC</a> in Postgres). In addition to the expensive operation, <code>VACUUM</code> will have to do more work later to clean up the table bloat. Very inefficient.</p> <p>It is <strong>perfectly safe</strong> to <code>SET</code> the local time zone for the session. This doesn't affect concurrent operations in any way. BTW, <code>SET SESSION</code> is the same as plain <code>SET</code> because <code>SESSION</code> is the default anyway.</p> <p>If you want to be <em>absolutely</em> sure, you can limit the setting to the current <strong>transaction</strong> with <code>SET LOCAL</code>. I quote the manual <a href="https://www.postgresql.org/docs/current/interactive/sql-set.html" rel="nofollow noreferrer">here</a></p> <blockquote> <p>The effects of <code>SET LOCAL</code> last only till the end of the current transaction, whether committed or not. A special case is <code>SET</code> followed by <code>SET LOCAL</code> within a single transaction: the <code>SET LOCAL</code> value will be seen until the end of the transaction, but afterwards (if the transaction is committed) the <code>SET</code> value will take effect.</p> </blockquote> <p>Put together:</p> <pre><code>BEGIN; SET LOCAL timezone = 'UTC'; COPY tabledata FROM 'c:\Users\Public\Downloads\test.csv' DELIMITERS ',' CSV; COMMIT; </code></pre> <p>Check:</p> <pre><code>SHOW timezone; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload