pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
time zone setting.
7+ messages / 4 participants
[nested] [flat]

* time zone setting.
@ 2011-08-24 10:25  dexdyne <from_postgresql_forum@dexdyne.com>
  0 siblings, 1 reply; 7+ messages in thread

From: dexdyne @ 2011-08-24 10:25 UTC (permalink / raw)
  To: pgsql-jdbc

I have played about a bit with time zones, and think I am getting a grip on
them.

If I use PgAdmin to submit queries, I can put

set time zone 'us/hawaii';

in front of some other queries, and they will operate as I expect. In fact I
find the change persist across multiple PgAdmin queries, so it is obviously
a "session setting"

I'm aware that I can change the JVM timezone suing setdefault.

But I can't put the "set time zone" stretring on the front of a jdbc
preparedStatement - it just barfs.

So the question is - can I, from a java program, set the time zone for the
database [ not for the jvm ].

--
View this message in context: http://postgresql.1045698.n5.nabble.com/time-zone-setting-tp4729960p4729960.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: time zone setting.
@ 2011-08-24 17:27  Maciek Sakrejda <msakrejda@truviso.com>
  parent: dexdyne <from_postgresql_forum@dexdyne.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Maciek Sakrejda @ 2011-08-24 17:27 UTC (permalink / raw)
  To: dexdyne <from_postgresql_forum@dexdyne.com>; +Cc: pgsql-jdbc

> in front of some other queries, and they will operate as I expect. In fact I
> find the change persist across multiple PgAdmin queries, so it is obviously
> a "session setting"

Right (you can use SET LOCAL for this-transaction-only changes).

> But I can't put the "set time zone" stretring on the front of a jdbc
> preparedStatement - it just barfs.

You can't just prepend it to the statement text because JDBC prepared
statements need to correspond to a single SQL statement. But you
should be able to issue a separate "set time zone" statement (either
normal or prepared) and get the session behavior you see through
pgAdmin.  Does that not work? What is the error?

---
Maciek Sakrejda | System Architect | Truviso

1065 E. Hillsdale Blvd., Suite 215
Foster City, CA 94404
(650) 242-3500 Main
www.truviso.com



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: time zone setting.
@ 2011-08-24 21:42  Oliver Jowett <oliver@opencloud.com>
  parent: Maciek Sakrejda <msakrejda@truviso.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Oliver Jowett @ 2011-08-24 21:42 UTC (permalink / raw)
  To: Maciek Sakrejda <msakrejda@truviso.com>; +Cc: dexdyne <from_postgresql_forum@dexdyne.com>; pgsql-jdbc

On 25 August 2011 05:27, Maciek Sakrejda <msakrejda@truviso.com> wrote:

> You can't just prepend it to the statement text because JDBC prepared
> statements need to correspond to a single SQL statement.

Actually, the driver is happy to handle multiple semicolon-separated
SQL statements in a single PreparedStatement.
(No idea what's going wrong with the timezone stuff without an error to look at)

Oliver



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: time zone setting.
@ 2011-08-30 09:51  dexdyne <from_postgresql_forum@dexdyne.com>
  parent: Oliver Jowett <oliver@opencloud.com>
  0 siblings, 1 reply; 7+ messages in thread

From: dexdyne @ 2011-08-30 09:51 UTC (permalink / raw)
  To: pgsql-jdbc

Well I know I tried it and I know it barfed.

I'll try both methods again.

Thanks all

David



> Actually, the driver is happy to handle multiple semicolon-separated
> SQL statements in a single PreparedStatement.
> (No idea what's going wrong with the timezone stuff without an error to
> look at)
> 


--
View this message in context: http://postgresql.1045698.n5.nabble.com/time-zone-setting-tp4729960p4749496.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: time zone setting.
@ 2011-08-30 17:21  Kris Jurka <books@ejurka.com>
  parent: dexdyne <from_postgresql_forum@dexdyne.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Kris Jurka @ 2011-08-30 17:21 UTC (permalink / raw)
  To: dexdyne <from_postgresql_forum@dexdyne.com>; +Cc: pgsql-jdbc



On Tue, 30 Aug 2011, dexdyne wrote:

> Well I know I tried it and I know it barfed.
> 

I think your problem is that not all postgresql commands can take 
parameters.  For example you cannot do "SET TIMEZONE = ?" with a prepared 
statement.  Instead you can do "SELECT set_config('timezone', ?, 
true/false)" with a prepared statement.

Kris Jurka



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: time zone setting.
@ 2011-08-31 09:36  dexdyne <from_postgresql_forum@dexdyne.com>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 1 reply; 7+ messages in thread

From: dexdyne @ 2011-08-31 09:36 UTC (permalink / raw)
  To: pgsql-jdbc

Kris,

Good Lord, how difficult this stuff is :-) I really don't do databases as my
main living - and it's darned hard to learn enough to get a proper grip.

Thank you for your suggestion - I had assumed the substitutions for ? chars
were simply done by search-and-replace, so the context wasn't important. Now
I know better. 

--------
as an aside, to aid my learnign process...

1. "you cannot do "SET TIMEZONE = ?" with a prepared statement"

  Where would I read up on what can and cannot be done with prepared
statement? Are we agreeijng that it has to be just what would be separated
by semi-colons interactively - in other words one statement per jdbc
execute? Or is the other comment right that sometimes you can include
semicolon-separated actions within a single preparedStatement

2. Any idea what tokens can appear as the first parameter to  set_config? I
tried searching the on-line manual for a list but couldn't find one.


TVM

David

--
View this message in context: http://postgresql.1045698.n5.nabble.com/time-zone-setting-tp4729960p4753538.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: time zone setting.
@ 2011-08-31 18:47  Maciek Sakrejda <msakrejda@truviso.com>
  parent: dexdyne <from_postgresql_forum@dexdyne.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Maciek Sakrejda @ 2011-08-31 18:47 UTC (permalink / raw)
  To: dexdyne <from_postgresql_forum@dexdyne.com>; +Cc: pgsql-jdbc

> Or is the other comment right that sometimes you can include
semicolon-separated actions within a single preparedStatement

I haven't tried it, but I'd trust Oliver on this one. I was thinking of the
underlying wire-level extended query protocol, which requires a single
"statement" per "query".

> Any idea what tokens can appear as the first parameter to  set_config? I
tried searching the on-line manual for a list but couldn't find one.

Any server settings (
http://www.postgresql.org/docs/9.0/static/runtime-config.html ) that are
updatable at runtime. For a quick reference, you can run:

select name, short_desc, extra_desc from pg_settings where context = 'user';

(context determines when you can change it).

---
Maciek Sakrejda | System Architect | Truviso

1065 E. Hillsdale Blvd., Suite 215
Foster City, CA 94404
(650) 242-3500 Main
www.truviso.com

^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2011-08-31 18:47 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-08-24 10:25 time zone setting. dexdyne <from_postgresql_forum@dexdyne.com>
2011-08-24 17:27 ` Maciek Sakrejda <msakrejda@truviso.com>
2011-08-24 21:42   ` Oliver Jowett <oliver@opencloud.com>
2011-08-30 09:51     ` dexdyne <from_postgresql_forum@dexdyne.com>
2011-08-30 17:21       ` Kris Jurka <books@ejurka.com>
2011-08-31 09:36         ` dexdyne <from_postgresql_forum@dexdyne.com>
2011-08-31 18:47           ` Maciek Sakrejda <msakrejda@truviso.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox