Hi,
First I'm trying to move a MySQL database to Postgres. I have to emulate a
MySQL sql statement - ''Describe tablename' which in general is '\d
tablename' from psql. If I use '-E' my 7.3.x provides three sql statements
and by 7.4.x produces four statements. But what I want is a single SQL
statement that produces the following:
------------------------------
fieldname | field type | isPK
-----------------------------------
clientid int true
last char false
first char false
The following will give me columns 1 and 2 but not 3
SELECT c.oid,a.attname, t.typname
FROM pg_class c, pg_attribute a, pg_type t
WHERE c.relname = tablename
AND a.attnum > 0
AND a.attrelid = c.oid
AND a.atttypid = t.oid
ORDER BY a.attnum
And this sort of gets the PK (does not provide the actual field name) where
the oid is the one from the above SQL statement.
SELECT c2.relname, i.indisprimary, i.indisunique,
pg_catalog.pg_get_constraintdef(i.indexrelid) \
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i \
WHERE c.oid = %s AND c.oid = i.indrelid AND i.indexrelid = c2.oid \
AND i.indisprimary =TRUE \
ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname
How can I get this done??????? Is it possible?????
John
---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings 6 2224
On Mon, 1 Nov 2004 09:59:44 -0800, John Fabiani <jf******@yolo.com> wrote: Hi,
First I'm trying to move a MySQL database to Postgres. I have to emulate a MySQL sql statement - ''Describe tablename' which in general is '\d tablename' from psql. If I use '-E' my 7.3.x provides three sql statements and by 7.4.x produces four statements. But what I want is a single SQL statement that produces the following:
------------------------------ fieldname | field type | isPK ----------------------------------- clientid int true last char false first char false
Unfortunately the guru certificate is still "in the post", but below
is a nasty kludge which might be going in the general direction you
want:
SELECT c.column_name AS fieldname,
c.data_type AS fieldtype,
COALESCE(i.indisprimary,FALSE) AS is_pkey
FROM information_schema.columns c
LEFT JOIN information_schema.key_column_usage cu
ON (c.table_name=cu.table_name AND c.column_name=cu.column_name)
LEFT JOIN pg_class cl ON(cl.relname=cu.table_name)
LEFT JOIN pg_index i ON(cl.oid= i.indrelid)
WHERE c.table_name='insert_tablename_here'
Caveats:
- this is _not_ schema-aware.
- requires the information schema, e.g. 7.4 and later
- might just be horribly wrong anyway, but you get the general idea ;-)
HTH
Ian Barwick ba*****@gmail.com
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org
On Mon, 1 Nov 2004 09:59:44 -0800, John Fabiani <jf******@yolo.com> wrote: Hi,
First I'm trying to move a MySQL database to Postgres. I have to emulate a MySQL sql statement - ''Describe tablename' which in general is '\d tablename' from psql. If I use '-E' my 7.3.x provides three sql statements and by 7.4.x produces four statements. But what I want is a single SQL statement that produces the following:
------------------------------ fieldname | field type | isPK ----------------------------------- clientid int true last char false first char false
Unfortunately the guru certificate is still "in the post", but below
is a nasty kludge which might be going in the general direction you
want:
SELECT c.column_name AS fieldname,
c.data_type AS fieldtype,
COALESCE(i.indisprimary,FALSE) AS is_pkey
FROM information_schema.columns c
LEFT JOIN information_schema.key_column_usage cu
ON (c.table_name=cu.table_name AND c.column_name=cu.column_name)
LEFT JOIN pg_class cl ON(cl.relname=cu.table_name)
LEFT JOIN pg_index i ON(cl.oid= i.indrelid)
WHERE c.table_name='insert_tablename_here'
Caveats:
- this is _not_ schema-aware.
- requires the information schema, e.g. 7.4 and later
- might just be horribly wrong anyway, but you get the general idea ;-)
HTH
Ian Barwick ba*****@gmail.com
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org
On Monday 01 November 2004 16:13, Ian Barwick wrote: On Mon, 1 Nov 2004 09:59:44 -0800, John Fabiani <jf******@yolo.com> wrote: Hi,
First I'm trying to move a MySQL database to Postgres. I have to emulate a MySQL sql statement - ''Describe tablename' which in general is '\d tablename' from psql. If I use '-E' my 7.3.x provides three sql statements and by 7.4.x produces four statements. But what I want is a single SQL statement that produces the following:
------------------------------ fieldname | field type | isPK ----------------------------------- clientid int true last char false first char false
Unfortunately the guru certificate is still "in the post", but below is a nasty kludge which might be going in the general direction you want:
SELECT c.column_name AS fieldname, c.data_type AS fieldtype, COALESCE(i.indisprimary,FALSE) AS is_pkey FROM information_schema.columns c LEFT JOIN information_schema.key_column_usage cu ON (c.table_name=cu.table_name AND c.column_name=cu.column_name) LEFT JOIN pg_class cl ON(cl.relname=cu.table_name) LEFT JOIN pg_index i ON(cl.oid= i.indrelid) WHERE c.table_name='insert_tablename_here'
Caveats: - this is _not_ schema-aware. - requires the information schema, e.g. 7.4 and later - might just be horribly wrong anyway, but you get the general idea ;-)
God bless you! It works as expected. But is it possible to create a SQL
statement using only the pg files. This will allow it to be used with 7.3.x
and later. I have been trying for a full day. Actually, I really need to
understand the relationship between the pg files. Is there a description
somewhere???
From the bottom of my heart thanks.
John
John
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org
On Monday 01 November 2004 16:13, Ian Barwick wrote: On Mon, 1 Nov 2004 09:59:44 -0800, John Fabiani <jf******@yolo.com> wrote: Hi,
First I'm trying to move a MySQL database to Postgres. I have to emulate a MySQL sql statement - ''Describe tablename' which in general is '\d tablename' from psql. If I use '-E' my 7.3.x provides three sql statements and by 7.4.x produces four statements. But what I want is a single SQL statement that produces the following:
------------------------------ fieldname | field type | isPK ----------------------------------- clientid int true last char false first char false
Unfortunately the guru certificate is still "in the post", but below is a nasty kludge which might be going in the general direction you want:
SELECT c.column_name AS fieldname, c.data_type AS fieldtype, COALESCE(i.indisprimary,FALSE) AS is_pkey FROM information_schema.columns c LEFT JOIN information_schema.key_column_usage cu ON (c.table_name=cu.table_name AND c.column_name=cu.column_name) LEFT JOIN pg_class cl ON(cl.relname=cu.table_name) LEFT JOIN pg_index i ON(cl.oid= i.indrelid) WHERE c.table_name='insert_tablename_here'
Caveats: - this is _not_ schema-aware. - requires the information schema, e.g. 7.4 and later - might just be horribly wrong anyway, but you get the general idea ;-)
God bless you! It works as expected. But is it possible to create a SQL
statement using only the pg files. This will allow it to be used with 7.3.x
and later. I have been trying for a full day. Actually, I really need to
understand the relationship between the pg files. Is there a description
somewhere???
From the bottom of my heart thanks.
John
John
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org
On Mon, Nov 01, 2004 at 05:34:21PM -0800, John Fabiani wrote: God bless you! It works as expected. But is it possible to create a SQL statement using only the pg files. This will allow it to be used with 7.3.x and later. I have been trying for a full day. Actually, I really need to understand the relationship between the pg files. Is there a description somewhere???
Yes, see the "System Catalogs" section in the "Internals" chapter of the
documentation. http://www.postgresql.org/docs/7.4/static/catalogs.html
--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"On the other flipper, one wrong move and we're Fatal Exceptions"
(T.U.X.: Term Unit X - http://www.thelinuxreview.com/TUX/)
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
On Mon, Nov 01, 2004 at 05:34:21PM -0800, John Fabiani wrote: God bless you! It works as expected. But is it possible to create a SQL statement using only the pg files. This will allow it to be used with 7.3.x and later. I have been trying for a full day. Actually, I really need to understand the relationship between the pg files. Is there a description somewhere???
Yes, see the "System Catalogs" section in the "Internals" chapter of the
documentation. http://www.postgresql.org/docs/7.4/static/catalogs.html
--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"On the other flipper, one wrong move and we're Fatal Exceptions"
(T.U.X.: Term Unit X - http://www.thelinuxreview.com/TUX/)
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mike Cox |
last post by:
After writing an article trashing java, and C++, notable LISP guru
Paul Graham is getting roasted on slashdot. Apart from AutoCAD and
Emacs, what has LISP done anyway? Most real work is done in...
|
by: Saturnin Kepa |
last post by:
The Scenario:
We have some data that can be in three states. One is a saved state,
a temporary state, and a complete state.
The complete state is the bulk of the data. This data will be...
|
by: Accolo1 |
last post by:
Help we are looking for this person, do you know them?
William
wjohnson@accolo.com
Title: BEA WebLogic Portal Guru
Job #: 03-04468
Check the pulse of your career! Evolve our eCommerce web...
|
by: Klaus Friese |
last post by:
Hi,
i'm currently working on a plugin for Adobe InDesign and i have some
problems with that. I'm not really a c++ guru, maybe somebody here has
an idea how to solve this.
The plugin is...
|
by: Steve B. |
last post by:
Is it good programming practice to call an event within an event?
I'm I creating recursion somehow somewhere? Does an event (e.g. send, e)
ever end?
I'm sorry, I'm not sure I know what I mean,...
|
by: Michael Suess |
last post by:
Hi,
please feel free to correct me if this is the wrong group to ask this
question. I have a blog about parallel programming and concurrency
(http://www.thinkingparallel.com if you are...
|
by: Singulus |
last post by:
Hello all,
I've searched for similar threads, I've found some bit of useful info
here and there, but nevertheless I want to post my questions...So, how
can I (we, in fact the forum can benefit...
|
by: stevenjs |
last post by:
Greeings, all,
Flash 8 has quiz templates which are coded for multiple choice, true/false, text statement, and matching types of questions, along with hotspots and probably anoher type I am...
|
by: Andrey |
last post by:
Hi,
I will be hiring a php guru to help us architect a highly scalable web
site/web application; the problem is I am coming from Microsoft .NET
world and not too much familiar with the platform....
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |