Thread: can a column be aliased?
I know this is probably a strange question, but can you give a column name an alias? The reason I ask is because I have recently realized I could use the oid to generate a unique key value for my tables, but I don't like that idea, because it does not give a very readable (and I assume portable) way of accessing the key value for the table. So I was thinking if I could "alias" the name of the oid field in a particular to something more palatable, then I would at least get around the readability problem. Is this doable with SQL (or with PostgreSQL for that matter)? ...james
Thus spake James Olin Oden > I know this is probably a strange question, but can you give a column > name an alias? The reason I ask is because I have recently realized I SELECT table1.oid AS custnum, table2.oid AS salesman FROM ... -- D'Arcy J.M. Cain <darcy@{druid|vex}.net> | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 424 2871 (DoD#0082) (eNTP) | what's for dinner.
D'Arcy J.M. Cain wrote: > Thus spake James Olin Oden > > I know this is probably a strange question, but can you give a column > > name an alias? The reason I ask is because I have recently realized I > > SELECT table1.oid AS custnum, table2.oid AS salesman FROM ... > OK, I get that, but what if you want to say: SELECT table1.custnum, table1.name, table2.invoicenum from table1, table2 WHERE table1.custnum = table2.custnum; and without using the AS clause table1.custnum is pointing to table1.oid? The idea is in perhaps the creation of the table to do something like the AS clause, so that I don't have to "know" later that custnum (the key field) is actually the oid column. The end result with this is to hide the implementation details of the database from those querying it. I might be really reaching, but it would be nice if something like this is a available...james > -- > D'Arcy J.M. Cain <darcy@{druid|vex}.net> | Democracy is three wolves > http://www.druid.net/darcy/ | and a sheep voting on > +1 416 424 2871 (DoD#0082) (eNTP) | what's for dinner.
On Mon, 3 Aug 1998, D'Arcy J.M. Cain wrote: > Thus spake James Olin Oden > > I know this is probably a strange question, but can you give a column > > name an alias? The reason I ask is because I have recently realized I > > SELECT table1.oid AS custnum, table2.oid AS salesman FROM ... > Hot as flame bait, but is the AS a SQL92 standard? Coming from an Oracle background I used select table1.oid custnum, table2.oid salesman from ... TIA, Rod -- Roderick A. Anderson raanders@altoplanos.net Altoplanos Information Systems, Inc. Voice: 208.765.6149 212 S. 11th Street, Suite 5 FAX: 208.664.5299 Coeur d'Alene, ID 83814
Thus spake James Olin Oden > > Thus spake James Olin Oden > > > I know this is probably a strange question, but can you give a column > > > name an alias? The reason I ask is because I have recently realized I > > > > SELECT table1.oid AS custnum, table2.oid AS salesman FROM ... > > > > OK, I get that, but what if you want to say: > > SELECT table1.custnum, table1.name, table2.invoicenum from table1, table2 > > WHERE table1.custnum = table2.custnum; > > and without using the AS clause table1.custnum is pointing to table1.oid? > The idea is in perhaps the creation of the table to do something like the AS > clause, so that I don't have to "know" later that custnum (the key field) is > actually the oid column. The end result with this is to hide the > implementation details of the database from those querying it. I might be > really reaching, but it would be nice if something like this is a > available...james I don't think so. Better use a sequence instead. You shouldn't be using OID as a key anyway. You lose the value if you dump and reload. -- D'Arcy J.M. Cain <darcy@{druid|vex}.net> | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 424 2871 (DoD#0082) (eNTP) | what's for dinner.
Thus spake Roderick A. Anderson > > Thus spake James Olin Oden > > > I know this is probably a strange question, but can you give a column > > > name an alias? The reason I ask is because I have recently realized I > > > > SELECT table1.oid AS custnum, table2.oid AS salesman FROM ... > > > > Hot as flame bait, but is the AS a SQL92 standard? Coming from an Oracle Yes it is. > background I used > > select table1.oid custnum, > table2.oid salesman > from ... This is accepted by the standard as well but doesn't seem to be accepted by PostgreSQL. Does Oracle accept AS? <select list> ::= <asterisk> | <select sublist> [ { <comma> <select sublist> }... ] <select sublist> ::= <derived column> | <qualifier> <period> <asterisk> <derived column> ::= <value expression> [ <as clause> ] <as clause> ::= [ AS ] <column name> -- D'Arcy J.M. Cain <darcy@{druid|vex}.net> | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 424 2871 (DoD#0082) (eNTP) | what's for dinner.
> I don't think so. Better use a sequence instead. You shouldn't be > using OID as a key anyway. You lose the value if you dump and reload. > Ah...there's the rub. Well, I haven't been doing that anyway; I was merely trying to explore the possiblity of doing so after I heard some users ask about it. At first thought I had the reservation of it not being portable, but with your thought (they change after a dump and reload) I can see that's a _real_ bad idea. Thanks...james > -- > D'Arcy J.M. Cain <darcy@{druid|vex}.net> | Democracy is three wolves > http://www.druid.net/darcy/ | and a sheep voting on > +1 416 424 2871 (DoD#0082) (eNTP) | what's for dinner.