[SQL] Finding Max Value in a Row

2012-05-11 Thread Carlos Mennens
I have a problem in SQL I don't know how to solve and while I'm sure there are 100+ ways to do this in ANSI SQL, I'm trying to find the most cleanest / efficient way. I have a table called 'users' and the field 'users_id' is listed as the PRIMARY KEY. I know I can use the COUNT function, then I kno

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread Viktor Bojović
On Fri, May 11, 2012 at 9:03 PM, Carlos Mennens wrote: > I have a problem in SQL I don't know how to solve and while I'm sure > there are 100+ ways to do this in ANSI SQL, I'm trying to find the > most cleanest / efficient way. I have a table called 'users' and the > field 'users_id' is listed as

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread Wes James
On Fri, May 11, 2012 at 1:03 PM, Carlos Mennens wrote: > I have a problem in SQL I don't know how to solve and while I'm sure > there are 100+ ways to do this in ANSI SQL, I'm trying to find the > most cleanest / efficient way. I have a table called 'users' and the > field 'users_id' is listed as

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread David Johnston
> -Original Message- > From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql- > ow...@postgresql.org] On Behalf Of Carlos Mennens > Sent: Friday, May 11, 2012 3:04 PM > To: PostgreSQL (SQL) > Subject: [SQL] Finding Max Value in a Row > > I have a problem in SQL I don't know how to solve a

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread Thomas Kellerer
Carlos Mennens wrote on 11.05.2012 21:03: I have a problem in SQL I don't know how to solve and while I'm sure there are 100+ ways to do this in ANSI SQL, I'm trying to find the most cleanest / efficient way. I have a table called 'users' and the field 'users_id' is listed as the PRIMARY KEY. I k

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread Carlos Mennens
Thanks for all the help thus far everyone! I sadly didn't create/design the table and would love to create a SEQUENCE on that particular field but not sure how unless I DROP the table and create from scratch. Currently the data TYPE on the primary key field (users_id) is CHAR and I have no idea wh

Re: [SQL] pg_dump: aborting because of server version mismatch

2012-05-11 Thread Adrian Klaver
On 05/02/2012 12:55 PM, Mitesh Shah wrote: Hi, I am trying to create a daily backup cron script but it fails with an error as below: Any pointers to resolve this will be greatly appreciated. Thanks, Mitesh Shah mitesh.s...@stripes39.com *(1) Error:* bash-3.2$

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread Thomas Kellerer
Carlos Mennens wrote on 11.05.2012 21:30: Thanks for all the help thus far everyone! I sadly didn't create/design the table and would love to create a SEQUENCE on that particular field but not sure how unless I DROP the table and create from scratch. Currently the data TYPE on the primary key fi

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread Adrian Klaver
On 05/11/2012 12:30 PM, Carlos Mennens wrote: Thanks for all the help thus far everyone! I sadly didn't create/design the table and would love to create a SEQUENCE on that particular field but not sure how unless I DROP the table and create from scratch. Currently the data TYPE on the primary ke

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread Carlos Mennens
On Fri, May 11, 2012 at 3:44 PM, Thomas Kellerer wrote: > Use this: > > alter table users >    alter column users_id type integer using to_number(users_id, '9'); > > (Adjust the '9' to the length of the char column) When you wrote "Adjust the '9' to the length of the char column, do y

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread Carlos Mennens
On Fri, May 11, 2012 at 3:43 PM, Adrian Klaver wrote: > Well the question to ask is if it is declared CHAR was that done for a > legitimate reason? One reason I can think of is to have leading 0s in a > 'number'. Might want to double check that code downstream is not depending > on CHAR behavior.

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread Thomas Kellerer
Carlos Mennens wrote on 11.05.2012 21:50: On Fri, May 11, 2012 at 3:44 PM, Thomas Kellerer wrote: Use this: alter table users alter column users_id type integer using to_number(users_id, '9'); (Adjust the '9' to the length of the char column) When you wrote "Adjust the '9' t

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread Thomas Kellerer
Carlos Mennens wrote on 11.05.2012 21:53: Very good question and asked by myself to the original SQL author and he explained while he didn't use the most efficient data types, he used ones "he" felt would be more transparent across a multitude of RDBMS vendors. So the answer is no, it would not

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread Viktor Bojović
you can convert from type to type using ::varchar or ::char(size) or ::integer so you can use sequence but you will have to convert it's result to suitable type (that can also be put in default value of user_id attribute) On Fri, May 11, 2012 at 9:30 PM, Carlos Mennens wrote: > Thanks for all the

Re: [SQL] Finding Max Value in a Row

2012-05-11 Thread Jasen Betts
On 2012-05-11, Carlos Mennens wrote: > I have a problem in SQL I don't know how to solve and while I'm sure > there are 100+ ways to do this in ANSI SQL, I'm trying to find the > most cleanest / efficient way. I have a table called 'users' and the > field 'users_id' is listed as the PRIMARY KEY. I