pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedreferencing column names properly
5+ messages / 3 participants
[nested] [flat]
* referencing column names properly
@ 2003-02-08 23:34 Sill-II, Stephen <Stephen.Sill-II@ost.dot.gov>
2003-02-09 04:38 ` Re: referencing column names properly Bruno Wolff III <bruno@wolff.to>
2003-02-09 05:50 ` Re: referencing column names properly Ross J. Reedstrom <reedstrm@rice.edu>
0 siblings, 2 replies; 5+ messages in thread
From: Sill-II, Stephen @ 2003-02-08 23:34 UTC (permalink / raw)
To: pgsql-sql
I have a table called logs with several columns whose names have '-' in
them, e.g. User-Name
I'm having trouble referencing these columns with SELECT statements.
What would the proper way to address these in a statement like this?
SELECT User-Name, max(Date), max(Time) from logs;
I want to return the last login date and time for each username.
Thanks
Stephen Sill II
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: referencing column names properly
2003-02-08 23:34 referencing column names properly Sill-II, Stephen <Stephen.Sill-II@ost.dot.gov>
@ 2003-02-09 04:38 ` Bruno Wolff III <bruno@wolff.to>
1 sibling, 0 replies; 5+ messages in thread
From: Bruno Wolff III @ 2003-02-09 04:38 UTC (permalink / raw)
To: Sill-II, Stephen <Stephen.Sill-II@ost.dot.gov>; +Cc: pgsql-sql
On Sat, Feb 08, 2003 at 18:34:31 -0500,
"Sill-II, Stephen" <Stephen.Sill-II@ost.dot.gov> wrote:
> I have a table called logs with several columns whose names have '-' in
> them, e.g. User-Name
>
> I'm having trouble referencing these columns with SELECT statements.
>
> What would the proper way to address these in a statement like this?
>
> SELECT User-Name, max(Date), max(Time) from logs;
You need to use double quotes around the column name. When you do that
case will become significant. If you didn't quote the column name on
the create table command, then the name would have been converted to
lower case.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: referencing column names properly
2003-02-08 23:34 referencing column names properly Sill-II, Stephen <Stephen.Sill-II@ost.dot.gov>
@ 2003-02-09 05:50 ` Ross J. Reedstrom <reedstrm@rice.edu>
1 sibling, 0 replies; 5+ messages in thread
From: Ross J. Reedstrom @ 2003-02-09 05:50 UTC (permalink / raw)
To: Sill-II, Stephen <Stephen.Sill-II@ost.dot.gov>; +Cc: pgsql-sql
On Sat, Feb 08, 2003 at 06:34:31PM -0500, Sill-II, Stephen wrote:
> I have a table called logs with several columns whose names have '-' in
> them, e.g. User-Name
>
> I'm having trouble referencing these columns with SELECT statements.
>
> What would the proper way to address these in a statement like this?
>
> SELECT User-Name, max(Date), max(Time) from logs;
SELECT "User-Name", max("Date"), max("Time") from logs;
Assuming the MulTiCasIng you show is also in the table. SQL lets you
put anything at all in an identifier (table or column name) as long
as you quote it with double-quotes (")
Ross
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: referencing column names properly
@ 2003-02-09 14:18 Sill-II, Stephen <Stephen.Sill-II@ost.dot.gov>
2003-02-09 22:56 ` Re: referencing column names properly Ross J. Reedstrom <reedstrm@rice.edu>
0 siblings, 1 reply; 5+ messages in thread
From: Sill-II, Stephen @ 2003-02-09 14:18 UTC (permalink / raw)
To: 'Ross J. Reedstrom ' <reedstrm@rice.edu>; +Cc: pgsql-sql
Thanks much! After much experimentation, I figured it out. I remember
reading in the postgres oreily book that if you don't quote the identifiers,
that it converts them all to lowercase for processing. Does the dash in the
name also require the name to be quoted?
Thanks again!
Stephen Sill II
-----Original Message-----
From: Ross J. Reedstrom
To: Sill-II, Stephen
Cc: 'pgsql-sql@postgresql.org'
Sent: 2/9/2003 12:50 AM
Subject: Re: [SQL] referencing column names properly
On Sat, Feb 08, 2003 at 06:34:31PM -0500, Sill-II, Stephen wrote:
> I have a table called logs with several columns whose names have '-'
in
> them, e.g. User-Name
>
> I'm having trouble referencing these columns with SELECT statements.
>
> What would the proper way to address these in a statement like this?
>
> SELECT User-Name, max(Date), max(Time) from logs;
SELECT "User-Name", max("Date"), max("Time") from logs;
Assuming the MulTiCasIng you show is also in the table. SQL lets you
put anything at all in an identifier (table or column name) as long
as you quote it with double-quotes (")
Ross
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: referencing column names properly
2003-02-09 14:18 Re: referencing column names properly Sill-II, Stephen <Stephen.Sill-II@ost.dot.gov>
@ 2003-02-09 22:56 ` Ross J. Reedstrom <reedstrm@rice.edu>
0 siblings, 0 replies; 5+ messages in thread
From: Ross J. Reedstrom @ 2003-02-09 22:56 UTC (permalink / raw)
To: Sill-II, Stephen <Stephen.Sill-II@ost.dot.gov>; +Cc: pgsql-sql
On Sun, Feb 09, 2003 at 09:18:05AM -0500, Sill-II, Stephen wrote:
> Thanks much! After much experimentation, I figured it out. I remember
> reading in the postgres oreily book that if you don't quote the identifiers,
> that it converts them all to lowercase for processing. Does the dash in the
> name also require the name to be quoted?
Yup, so the expression parser can differentiate between a-b (column"a"
- column "b") and a-b (column named "a-b").
Ross
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2003-02-09 22:56 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-02-08 23:34 referencing column names properly Sill-II, Stephen <Stephen.Sill-II@ost.dot.gov>
2003-02-09 04:38 ` Bruno Wolff III <bruno@wolff.to>
2003-02-09 05:50 ` Ross J. Reedstrom <reedstrm@rice.edu>
2003-02-09 14:18 Re: referencing column names properly Sill-II, Stephen <Stephen.Sill-II@ost.dot.gov>
2003-02-09 22:56 ` Ross J. Reedstrom <reedstrm@rice.edu>
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