pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
type of a field
11+ messages / 8 participants
[nested] [flat]

* type of a field
@ 2002-05-02 09:48  ameen eetemadi <ameen78101@yahoo.com>
  0 siblings, 3 replies; 11+ messages in thread

From: ameen eetemadi @ 2002-05-02 09:48 UTC (permalink / raw)
  To: pgsql-php

Hello
I want to know the type of a field in a table
how can I khow it ?

__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: type of a field
@ 2002-05-02 14:59  Keary Suska <hierophant@pcisys.net>
  parent: ameen eetemadi <ameen78101@yahoo.com>
  2 siblings, 0 replies; 11+ messages in thread

From: Keary Suska @ 2002-05-02 14:59 UTC (permalink / raw)
  To: ameen eetemadi <ameen78101@yahoo.com>; pgsql-php

on 5/2/02 3:48 AM, ameen78101@yahoo.com purportedly said:

> Hello
> I want to know the type of a field in a table
> how can I khow it ?

There are different ways. You can use pg_field_type(), or a Postgres
function. It's all in the docs. RTFM.

Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"




^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: type of a field
@ 2002-05-02 16:49  Josh Berkus <josh@agliodbs.com>
  parent: ameen eetemadi <ameen78101@yahoo.com>
  2 siblings, 0 replies; 11+ messages in thread

From: Josh Berkus @ 2002-05-02 16:49 UTC (permalink / raw)
  To: ameen eetemadi <ameen78101@yahoo.com>; pgsql-php

Ameen,

> I want to know the type of a field in a table
> how can I khow it ?

Way #1:
1. Log into to your database using the command line utility PSQL.
2. Type "\d <name of table>"

Way #2:
1. Install phpPgAdmin database administration tool.
2. Examine the table using phpPgAdmin.

-Josh



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: type of a field
@ 2002-05-02 19:55  knut.suebert@web.de
  parent: ameen eetemadi <ameen78101@yahoo.com>
  2 siblings, 0 replies; 11+ messages in thread

From: knut.suebert@web.de @ 2002-05-02 19:55 UTC (permalink / raw)
  To: pgsql-php

ameen eetemadi schrieb:

> I want to know the type of a field in a table how can I khow it ?

  pg_fieldtype()

or something like

  SELECT a.attname, format_type(a.atttypid, a.atttypmod)
	 FROM pg_class c, pg_attribute a
	 WHERE c.relname = '$tablename'
	 AND a.attnum > 0 AND a.attrelid = c.oid
	 ORDER BY a.attnum;

?

Bye,
Knut Sübert



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: type of a field
@ 2002-05-03 07:46  Duncan Adams (DNS) <duncan.adams@vcontractor.co.za>
  0 siblings, 0 replies; 11+ messages in thread

From: Duncan Adams (DNS) @ 2002-05-03 07:46 UTC (permalink / raw)
  To: pgsql-php

Would pg_fieldname() and pg_fieldtype() also be an option?

-----Original Message-----
From: Josh Berkus [mailto:josh@agliodbs.com]
Sent: Thursday, May 02, 2002 6:49 PM
To: ameen eetemadi; pgsql-php@postgresql.org
Subject: Re: [PHP] type of a field


Ameen,

> I want to know the type of a field in a table
> how can I khow it ?

Way #1:
1. Log into to your database using the command line utility PSQL.
2. Type "\d <name of table>"

Way #2:
1. Install phpPgAdmin database administration tool.
2. Examine the table using phpPgAdmin.

-Josh

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* type of a field
@ 2002-05-07 13:00  ameen eetemadi <ameen78101@yahoo.com>
  0 siblings, 2 replies; 11+ messages in thread

From: ameen eetemadi @ 2002-05-07 13:00 UTC (permalink / raw)
  To: pgsql-php

I want to change the type of a field in postgres .
How can I do it ?

__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: type of a field
@ 2002-05-07 15:09  Duncan Adams (DNS) <duncan.adams@vcontractor.co.za>
  0 siblings, 0 replies; 11+ messages in thread

From: Duncan Adams (DNS) @ 2002-05-07 15:09 UTC (permalink / raw)
  To: pgsql-php

Hi

1 u will have to use alter table to change the tables name RTFM
2 then create the new table with the changed columns 
3 then insert into <newtable> values (select oldcolumn as newcolumn, ect...
from <renamedtable>);

but i did not read u'r question correctly.

i would do steps 1 and 2 above and then write a function in php 
that

select * from <renamed table>

and 

insert into <newtable>


-----Original Message-----
From: ameen eetemadi [mailto:ameen78101@yahoo.com]
Sent: Tuesday, May 07, 2002 3:01 PM
To: pgsql-php@postgresql.org
Subject: [PHP] type of a field


I want to change the type of a field in postgres.
How can I do it ?

__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html



^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: type of a field
@ 2002-05-07 15:20  Dan Wilson <phppgadmin@acucore.com>
  0 siblings, 1 reply; 11+ messages in thread

From: Dan Wilson @ 2002-05-07 15:20 UTC (permalink / raw)
  To: ameen eetemadi <ameen78101@yahoo.com>; +Cc: pgsql-php

You can't yet... at least not with an ALTER statement.  The only way to 
currenty do this is by dumping the table (through pg_dump), altering the type 
of the field, and then re-ipmorting the table.

Rumor has it that they are working on an ALTER statement to accomplish this 
for 7.3 or 7.4.

-Dan

Quoting ameen eetemadi <ameen78101@yahoo.com>:

> I want to change the type of a field in postgres .
> How can I do it ?




^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: type of a field
@ 2002-05-07 15:49  Scott Marlowe <scott.marlowe@ihs.com>
  parent: ameen eetemadi <ameen78101@yahoo.com>
  1 sibling, 0 replies; 11+ messages in thread

From: Scott Marlowe @ 2002-05-07 15:49 UTC (permalink / raw)
  To: ameen eetemadi <ameen78101@yahoo.com>; +Cc: pgsql-php

Short answer: You can't
Long answer: There are many workarounds.

Workaround 1: 
dump the table with pg_dump dbase -t tablename
edit dump file to change table definition
drop and reload table.

Workaround 2:
Let's say you wanna change a varchar to a text type.

Original table t1:
col | type
----------
nam | varchar(32)
id  | int4

select nam::text, id into t2 from t1;
drop table t1;
alter table t2 rename to t1;

You can do the above in a transaction if you are on a live database.  I'd 
back up the data first just to be sure.

On Tue, 7 May 2002, ameen eetemadi wrote:

> I want to change the type of a field in postgres .
> How can I do it ?
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Health - your guide to health and wellness
> http://health.yahoo.com
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
> 
> http://www.postgresql.org/users-lounge/docs/faq.html
> 




^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: type of a field
@ 2002-05-07 16:18  Keary Suska <hierophant@pcisys.net>
  parent: ameen eetemadi <ameen78101@yahoo.com>
  1 sibling, 0 replies; 11+ messages in thread

From: Keary Suska @ 2002-05-07 16:18 UTC (permalink / raw)
  To: pgsql-php

on 5/7/02 7:00 AM, ameen78101@yahoo.com purportedly said:

> I want to change the type of a field in postgres .
> How can I do it ?

You can't, at least not exactly. I believe there is some info in either the
FAQ, documentation, or non-FAQ documentation on the Postgres site.

In essence, your choices are:

1) recreate the field: rename the current field, then create a new field
with the same name and desired options; or

2) recreate the table: rename the current table, create a new table with the
proper name and field definitions as desired, drop the old table. You can
use SELECT INTO to transfer data from the old table to new.

In both cases, however, you can run into problems with triggers and other
server-side functions that use the field or table. I believe there are ways
around this, but I don't recall them at the moment.

Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"




^ permalink  raw  reply  [nested|flat] 11+ messages in thread

* Re: type of a field
@ 2002-05-08 02:09  Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  parent: Dan Wilson <phppgadmin@acucore.com>
  0 siblings, 0 replies; 11+ messages in thread

From: Christopher Kings-Lynne @ 2002-05-08 02:09 UTC (permalink / raw)
  To: Dan Wilson <phppgadmin@acucore.com>; ameen eetemadi <ameen78101@yahoo.com>; +Cc: pgsql-php

> You can't yet... at least not with an ALTER statement.  The only way to 
> currenty do this is by dumping the table (through pg_dump), 
> altering the type 
> of the field, and then re-ipmorting the table.
> 
> Rumor has it that they are working on an ALTER statement to 
> accomplish this 
> for 7.3 or 7.4.

Development currently stalled ;)  Don't bet on it being there...

Chris




^ permalink  raw  reply  [nested|flat] 11+ messages in thread


end of thread, other threads:[~2002-05-08 02:09 UTC | newest]

Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-05-02 09:48 type of a field ameen eetemadi <ameen78101@yahoo.com>
2002-05-02 14:59 ` Keary Suska <hierophant@pcisys.net>
2002-05-02 16:49 ` Josh Berkus <josh@agliodbs.com>
2002-05-02 19:55 ` knut.suebert@web.de
2002-05-03 07:46 Re: type of a field Duncan Adams (DNS) <duncan.adams@vcontractor.co.za>
2002-05-07 13:00 type of a field ameen eetemadi <ameen78101@yahoo.com>
2002-05-07 15:49 ` Scott Marlowe <scott.marlowe@ihs.com>
2002-05-07 16:18 ` Keary Suska <hierophant@pcisys.net>
2002-05-07 15:09 Re: type of a field Duncan Adams (DNS) <duncan.adams@vcontractor.co.za>
2002-05-07 15:20 Re: type of a field Dan Wilson <phppgadmin@acucore.com>
2002-05-08 02:09 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox