pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
How to quote date value?
6+ messages / 4 participants
[nested] [flat]

* How to quote date value?
@ 2003-11-21 09:39 nobody <nobody@nowhere.near.here>
  2003-11-21 10:53 ` Re: How to quote date value? nobody <nobody@nowhere.near.here>
  0 siblings, 1 reply; 6+ messages in thread

From: nobody @ 2003-11-21 09:39 UTC (permalink / raw)
  To: pgsql-sql

What is correct character to quote date values in SELECT. Is is single
quote?

When I do:

SELECT '1/11/2003' AS "InvoiceDate";

the returned value is of unknown type (not a date).

Then I tried:

SELECT 1/11/2003 AS "InvoiceDate";

and the InvoiceDate was set to zero (I guess the engine divided the numbers
in date).

Then I tried:

SELECT 1-11-2003 AS "InvoiceDate";

and the numbers in date value got substracted.

Using PostgreSQL 7.4 and PgAdmin 3.

Any insight is welcome.





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

* Re: How to quote date value?
  2003-11-21 09:39 How to quote date value? nobody <nobody@nowhere.near.here>
@ 2003-11-21 10:53 ` nobody <nobody@nowhere.near.here>
  2003-11-21 18:01   ` Re: How to quote date value? Gaetano Mendola <mendola@bigfoot.com>
  0 siblings, 1 reply; 6+ messages in thread

From: nobody @ 2003-11-21 10:53 UTC (permalink / raw)
  To: pgsql-sql

I have found it in documentation, it is single quote. But it does not
explain why

SELECT '1/11/2003' AS "InvoiceDate";

returns "unknown" data type instead of "date".

"nobody" <nobody@nowhere.near.here> wrote in message
news:bpkmg7$2aj3$1@news.hub.org...
> What is correct character to quote date values in SELECT. Is is single
> quote?
>
> When I do:
>
> SELECT '1/11/2003' AS "InvoiceDate";
>
> the returned value is of unknown type (not a date).
>
> Then I tried:
>
> SELECT 1/11/2003 AS "InvoiceDate";
>
> and the InvoiceDate was set to zero (I guess the engine divided the
numbers
> in date).
>
> Then I tried:
>
> SELECT 1-11-2003 AS "InvoiceDate";
>
> and the numbers in date value got substracted.
>
> Using PostgreSQL 7.4 and PgAdmin 3.
>
> Any insight is welcome.
>
>





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

* Re: How to quote date value?
  2003-11-21 09:39 How to quote date value? nobody <nobody@nowhere.near.here>
  2003-11-21 10:53 ` Re: How to quote date value? nobody <nobody@nowhere.near.here>
@ 2003-11-21 18:01   ` Gaetano Mendola <mendola@bigfoot.com>
  2003-11-21 19:04     ` Re: How to quote date value? Stephan Szabo <sszabo@megazone.bigpanda.com>
  0 siblings, 1 reply; 6+ messages in thread

From: Gaetano Mendola @ 2003-11-21 18:01 UTC (permalink / raw)
  To: pgsql-sql; +Cc: nobody <nobody@nowhere.near.here>

nobody wrote:
> I have found it in documentation, it is single quote. But it does not
> explain why
> 
> SELECT '1/11/2003' AS "InvoiceDate";
> 
> returns "unknown" data type instead of "date".

Why not a string ? or a fancy custom type ?


Regards
Gaetano Mendola





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

* Re: How to quote date value?
  2003-11-21 09:39 How to quote date value? nobody <nobody@nowhere.near.here>
  2003-11-21 10:53 ` Re: How to quote date value? nobody <nobody@nowhere.near.here>
  2003-11-21 18:01   ` Re: How to quote date value? Gaetano Mendola <mendola@bigfoot.com>
@ 2003-11-21 19:04     ` Stephan Szabo <sszabo@megazone.bigpanda.com>
  2003-11-21 19:16       ` Re: How to quote date value? terry@greatgulfhomes.com
  2003-11-23 16:18       ` Re: How to quote date value? nobody <nobody@nowhere.near.here>
  0 siblings, 2 replies; 6+ messages in thread

From: Stephan Szabo @ 2003-11-21 19:04 UTC (permalink / raw)
  To: pgsql-sql


On Fri, 21 Nov 2003, Gaetano Mendola wrote:

> nobody wrote:
> > I have found it in documentation, it is single quote. But it does not
> > explain why
> >
> > SELECT '1/11/2003' AS "InvoiceDate";
> >
> > returns "unknown" data type instead of "date".

(I haven't seen the original message yet, so I'm replying to a reply)
Date literals are generally written as:
DATE '1/11/2003'

PostgreSQL will try to guess what type you meant with quoted strings in
expressions, but in the above there isn't enough context to do guess that
you meant a date really (it should probably actually be thought of as a
string in such cases).




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

* Re: How to quote date value?
  2003-11-21 09:39 How to quote date value? nobody <nobody@nowhere.near.here>
  2003-11-21 10:53 ` Re: How to quote date value? nobody <nobody@nowhere.near.here>
  2003-11-21 18:01   ` Re: How to quote date value? Gaetano Mendola <mendola@bigfoot.com>
  2003-11-21 19:04     ` Re: How to quote date value? Stephan Szabo <sszabo@megazone.bigpanda.com>
@ 2003-11-21 19:16       ` terry@greatgulfhomes.com
  1 sibling, 0 replies; 6+ messages in thread

From: terry@greatgulfhomes.com @ 2003-11-21 19:16 UTC (permalink / raw)
  To: 'Stephan Szabo' <sszabo@megazone.bigpanda.com>; pgsql-sql

If you want an explicit date, then cast it like this:

SELECT '1/11/2003'::date AS "InvoiceDate";

Terry Fielder
Manager Software Development and Deployment
Great Gulf Homes / Ashton Woods Homes
terry@greatgulfhomes.com 
Fax: (416) 441-9085


> -----Original Message-----
> From: pgsql-sql-owner@postgresql.org
> [mailto:pgsql-sql-owner@postgresql.org]On Behalf Of Stephan Szabo
> Sent: Friday, November 21, 2003 2:04 PM
> To: pgsql-sql@postgresql.org
> Subject: Re: [SQL] How to quote date value?
> 
> 
> 
> On Fri, 21 Nov 2003, Gaetano Mendola wrote:
> 
> > nobody wrote:
> > > I have found it in documentation, it is single quote. But 
> it does not
> > > explain why
> > >
> > > SELECT '1/11/2003' AS "InvoiceDate";
> > >
> > > returns "unknown" data type instead of "date".
> 
> (I haven't seen the original message yet, so I'm replying to a reply)
> Date literals are generally written as:
> DATE '1/11/2003'
> 
> PostgreSQL will try to guess what type you meant with quoted 
> strings in
> expressions, but in the above there isn't enough context to 
> do guess that
> you meant a date really (it should probably actually be 
> thought of as a
> string in such cases).
> 
> 
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
> 



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

* Re: How to quote date value?
  2003-11-21 09:39 How to quote date value? nobody <nobody@nowhere.near.here>
  2003-11-21 10:53 ` Re: How to quote date value? nobody <nobody@nowhere.near.here>
  2003-11-21 18:01   ` Re: How to quote date value? Gaetano Mendola <mendola@bigfoot.com>
  2003-11-21 19:04     ` Re: How to quote date value? Stephan Szabo <sszabo@megazone.bigpanda.com>
@ 2003-11-23 16:18       ` nobody <nobody@nowhere.near.here>
  1 sibling, 0 replies; 6+ messages in thread

From: nobody @ 2003-11-23 16:18 UTC (permalink / raw)
  To: pgsql-sql

Thanks, I learnt to use:

SELECT CAST('1/11/2003' AS DATE) AS invoice_number;

and it does what I would expect ;-).

"Stephan Szabo" <sszabo@megazone.bigpanda.com> wrote in message
news:20031121110022.U75942@megazone.bigpanda.com...
>
> On Fri, 21 Nov 2003, Gaetano Mendola wrote:
>
> > nobody wrote:
> > > I have found it in documentation, it is single quote. But it does not
> > > explain why
> > >
> > > SELECT '1/11/2003' AS "InvoiceDate";
> > >
> > > returns "unknown" data type instead of "date".
>
> (I haven't seen the original message yet, so I'm replying to a reply)
> Date literals are generally written as:
> DATE '1/11/2003'
>
> PostgreSQL will try to guess what type you meant with quoted strings in
> expressions, but in the above there isn't enough context to do guess that
> you meant a date really (it should probably actually be thought of as a
> string in such cases).
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>





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


end of thread, other threads:[~2003-11-23 16:18 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-11-21 09:39 How to quote date value? nobody <nobody@nowhere.near.here>
2003-11-21 10:53 ` nobody <nobody@nowhere.near.here>
2003-11-21 18:01   ` Gaetano Mendola <mendola@bigfoot.com>
2003-11-21 19:04     ` Stephan Szabo <sszabo@megazone.bigpanda.com>
2003-11-21 19:16       ` terry@greatgulfhomes.com
2003-11-23 16:18       ` nobody <nobody@nowhere.near.here>

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