Thread: Re: How to quote date value?

Re: How to quote date value?

From
Gaetano Mendola
Date:
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




Re: How to quote date value?

From
Stephan Szabo
Date:
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).



Re: How to quote date value?

From
"nobody"
Date:
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
>




Re: How to quote date value?

From
Date:
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
>