[SQL] Understanding Binary Data Type

2012-05-22 Thread Carlos Mennens
Hello everyone! I wanted to ask the list a question about the 'bytea' data type & how I can picture this in my head. I've been reading SQL for about a few months now and since then, I've only been working with textual data. Basically I'm familiar with storing text and numerical characters into tabl

Re: [SQL] Finding Max Value in a Row

2012-05-13 Thread Carlos Mennens
On Fri, May 11, 2012 at 4:42 PM, Viktor Bojović wrote: > 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) I'm not unde

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 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
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

[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

[SQL] UPDATE Multiple Records At Once?

2012-04-11 Thread Carlos Mennens
FROM customers forza-# WHERE cust_name = 'iamUNIX' forza-# ; cust_id | cust_name | cust_address | cust_contact | cust_email +---+---++ 16 | MobileNX | 200 South Shore Drive | Carlo

[SQL] Type Ahead Issue

2012-03-07 Thread Carlos Mennens
I don't know if this is an issue with my client (Psql) or if it's something I'm doing wrong but I've noticed this issue before and can't figure it out. When I'm using the psql client, I really rely on the tab / type ahead auto completion. When I run my command on one single line, it works fine but

Re: [SQL] Change Ownership Recursively

2012-03-01 Thread Carlos Mennens
I changed to the suggested database which is owned by 'Carlos' and did as instructed. Everything worked fine. Thank you! On Thu, Mar 1, 2012 at 11:23 AM, Carlos Mennens wrote: > I did do a Google search for "PostgreSQL 9.1 change ownership > recursively" but eithe

Re: [SQL] Change Ownership Recursively

2012-03-01 Thread Carlos Mennens
On Thu, Mar 1, 2012 at 11:38 AM, Eric Ndengang wrote: > Hi > You can try this command "REASSIGN OWNED BY TO ..." like this: > REASSIGN OWNED BY previous_role TO new_role; >  DROP OWNED previous_role; I did as follows: iamunix=# \c postgres SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 2

[SQL] Change Ownership Recursively

2012-03-01 Thread Carlos Mennens
I have a database that I must assign ownership to a new role. I want this new role to own the entire database and all of it's tables, views, triggers, & all. When I run the ALTER DATABASE command below, it only changes the database role but the tables are all still owned by the previous role. Is th

[SQL] Display Length Between Var & Varchar

2012-01-31 Thread Carlos Mennens
I've noticed when I set a field to char, it takes up lots of space over varchar: iamunix=# SELECT * FROM music; id | band| album |date| asin|label +---+--+---

[SQL] Update Mass Data in Field?

2012-01-26 Thread Carlos Mennens
I'm new to SQL so I'm looking for a way to change several email addresses with one command. For example everyone has a 'holyghost.org' domain and I need to change a few 100 email addresses in the field 'emp_email'. I need to UPDATE employees table which has a COLUMN 'emp_email' and change %holyghos

[SQL] Unable To Modify Table

2012-01-12 Thread Carlos Mennens
I seem to have an issue where I can't modify a table due to another tables foreign key association: [CODE]trinity=# \d developers Table "public.developers" Column| Type | Modifiers --++--- id | character(10) | not null name

Re: [SQL] Unable To Alter Data Type

2012-01-11 Thread Carlos Mennens
On Wed, Jan 11, 2012 at 7:13 PM, David Johnston wrote: > However, I will say again, you DO NOT WANT TO ACTUALLY DO THIS! > > The specific issue is that some US Postal Code begin with a zero ( 0 ) and > so whenever you want to the zip_code value you need to pad leading zeros if > the length is less

[SQL] Unable To Alter Data Type

2012-01-11 Thread Carlos Mennens
I have an issue I can't figure out. I have the following TABLE: tysql=# \d customers Table "public.customers" Column| Type | Modifiers --++--- cust_id | character(10) | not null cust_name| character(50) | not null cust_a

[SQL] DECIMAL or NUMERIC Data Types

2012-01-05 Thread Carlos Mennens
Does it matter when writing SQL code in PostgreSQL if I use DECIMAL or NUMERIC date types for a column named 'price' assuming it's to store the associated items actual dollar amount? Reading the fine manual*, I can't find a single difference between either and they both are supported / recognized

[SQL] When To Use Quotes

2012-01-05 Thread Carlos Mennens
I'm trying to understand when in SELECT statements should and should I not use single quotes to filter my results. For example: SELECT * FROM people WHERE fname = 'James'; or SELECT * FROM price WHERE msrb BETWEEN 50 AND 100; Now is it correct to say that in PostgreSQL or ANSI SQL in general I