Wednesday, March 21, 2012

PostgreSQL

In a Union query, I have initialized one new column for sorting purpose. For
ex :
select ORD = 1 , t1.a, t1.b from table1 as t1
Union
select ORD = 0, t2.a, t2.b from table2 as t2
order by ORD.
ORD column is not present in thw table. It is used here for putting all the
rows of the second query before the rows of first query. The query is
getting executed in Windows which uses SQL 2000 server. But in Linux(RedHat)
when we are using PostgresSQL database, the same query gives error - "Unable
to parse 'ORD' ".
Is this thing not supported in PostgresSQL? If this is not supported then
what is the method of acheiving the same result?
Thanks,
VenkatTry:
select 1 AS ORD , t1.a, t1.b from table1 as t1
Union
select 0, t2.a, t2.b from table2 as t2
order by ORD
column_alias = expression is T-SQL specific and not ANSI-SQL standard, as
opposed to expression AS column_alias which is standard SQL.
Jacco Schalkwijk
SQL Server MVP
"Venkat" <venkat_kp@.yahoo.com> wrote in message
news:1092226310.253625@.sj-nntpcache-5...
> In a Union query, I have initialized one new column for sorting purpose.
> For
> ex :
> select ORD = 1 , t1.a, t1.b from table1 as t1
> Union
> select ORD = 0, t2.a, t2.b from table2 as t2
> order by ORD.
> ORD column is not present in thw table. It is used here for putting all
> the
> rows of the second query before the rows of first query. The query is
> getting executed in Windows which uses SQL 2000 server. But in
> Linux(RedHat)
> when we are using PostgresSQL database, the same query gives error -
> "Unable
> to parse 'ORD' ".
> Is this thing not supported in PostgresSQL? If this is not supported then
> what is the method of acheiving the same result?
>
> Thanks,
> Venkat
>
>|||"Jacco Schalkwijk" <jacco.please.reply@.to.newsgroups.mvps.org.invalid> wrote
in message news:#YjU$q7fEHA.2848@.TK2MSFTNGP10.phx.gbl...
> Try:
> select 1 AS ORD , t1.a, t1.b from table1 as t1
> Union
> select 0, t2.a, t2.b from table2 as t2
> order by ORD
> column_alias = expression is T-SQL specific and not ANSI-SQL standard, as
> opposed to expression AS column_alias which is standard SQL.
>
Thanks Jacco it worked for me.
regards,
Venkat

No comments:

Post a Comment