Unix Technical Forum

Shorthand column labels (SELECT col1 foo, ...) vs (SELECT col1 ASfoo, ...)

This is a discussion on Shorthand column labels (SELECT col1 foo, ...) vs (SELECT col1 ASfoo, ...) within the pgsql Sql forums, part of the PostgreSQL category; --> I notice PG doesn't allow shorthand column labels -- it requires the 'AS' operand. SELECT col1 foo, ...; -> ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Sql

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 06:00 PM
Ken Johanson
 
Posts: n/a
Default Shorthand column labels (SELECT col1 foo, ...) vs (SELECT col1 ASfoo, ...)

I notice PG doesn't allow shorthand column labels -- it requires the
'AS' operand.

SELECT col1 foo, ...; -> ERROR: syntax error at or near "foo"

For compatibility with other databases, what objections might be argued
in allowing this syntax in the future?

On the 'pros' side I think it eases migration to PG, shortens code, is
similar syntax to shorthand table aliases, and some users might argue it
has become defacto syntax among DBs.

Regards,
Ken



---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 06:00 PM
Paul Lambert
 
Posts: n/a
Default Re: Shorthand column labels (SELECT col1 foo, ...) vs (SELECTcol1 AS foo, ...)

Ken Johanson wrote:
> I notice PG doesn't allow shorthand column labels -- it requires the
> 'AS' operand.
>
> SELECT col1 foo, ...; -> ERROR: syntax error at or near "foo"
>
> For compatibility with other databases, what objections might be argued
> in allowing this syntax in the future?
>
> On the 'pros' side I think it eases migration to PG, shortens code, is
> similar syntax to shorthand table aliases, and some users might argue it
> has become defacto syntax among DBs.
>
> Regards,
> Ken


Briefly discussed a couple of weeks ago.

See http://archives.postgresql.org/pgsql...1/msg00089.php

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-19-2008, 06:00 PM
Ken Johanson
 
Posts: n/a
Default Re: Shorthand column labels (SELECT col1 foo, ...) vs (SELECTcol1 AS foo, ...)

Paul Lambert wrote:
> Ken Johanson wrote:
>> I notice PG doesn't allow shorthand column labels -- it requires the
>> 'AS' operand.
>>
>> SELECT col1 foo, ...; -> ERROR: syntax error at or near "foo"

>
> Briefly discussed a couple of weeks ago.
>
> See http://archives.postgresql.org/pgsql...1/msg00089.php
>



Interesting thread(s)!

What I didn't see discussed was the possibility of making a server
and/or session option, where we could elect to turn-off the old behavior
(PG specific behavior) and enable the standard/shorthand syntax. Users
need a migration path.

I personally cant ever see using those PGisms/features and would choose
to enable the standard mode. I think I'd have fewer compatibility problems.

Ken



---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-19-2008, 06:00 PM
Paul Lambert
 
Posts: n/a
Default Re: Shorthand column labels (SELECT col1 foo, ...) vs (SELECTcol1 AS foo, ...)

Ken Johanson wrote:
> Interesting thread(s)!
>
> What I didn't see discussed was the possibility of making a server
> and/or session option, where we could elect to turn-off the old behavior
> (PG specific behavior) and enable the standard/shorthand syntax. Users
> need a migration path.
>
> I personally cant ever see using those PGisms/features and would choose
> to enable the standard mode. I think I'd have fewer compatibility problems.
>
> Ken


What was discussed is that the AS keyword is required because of the way
the interpreter parses the commands.

With the example given, how does it know that 1::character varying isn't
casting to a character field with an alias of varying or a character
varying field with no alias?

If there was simply a switch to turn the requirement on or off that's
not going to stop things from breaking - the postfix operators still
need to be picked up somehow, it's a technical limitation rather than a
"let's just be difficult and be incompatible with other dbms's" limitation

I think it would be nice as well, I had to migrate a system that didn't
bother putting AS in any of it's views/stored procedures etc and went
through this pain - but I think having to change everything was worth it
to make sure all my scripts were correctly written and free from
possible misinterpretation.

My thoughts anyway.

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:22 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com