Skip site navigation (1) Skip section navigation (2)

Re: find out data types using sql or php

From: "Webb Sprague" <webb(dot)sprague(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: find out data types using sql or php
Date: 2007-10-26 21:59:28
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
> ... to determine the field datatype (text, numeric,
> bool, etc.)

I am not sure if this helps, but you can dig around in the system
files (pg_catalog.*), and probably write a query that gets the types
of every column in the data table you want to insert to.

Not a big push, but maybe it will get you started.  I don't have links
at hand -- sorry.

> and then use some regex or something along those lines to
> attempt to verify that the data is good, and then mark the is_ok field
> (obviously a bool) as true, and use is_ok = TRUE in the insert/select
> statement. Can somebody give me a push in the right direction?

This sounds like a lot of programming, but that you have the right
idea.  I am not sure how you would use the "is_ok" within SQL; I would
probably only try to insert data that is ok, and filter that in the

I might also think in terms of wrapping everything in a transaction,
assuming it is all good, and then rolling back and catching your
exception and giving the user a decent error -- such as "reformat your
spreadsheet, doofus, and try uploading again"...  Very doable with
psycopg2 and python.

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

In response to

pgsql-general by date

Next:From: Michael GlaesemannDate: 2007-10-26 22:21:20
Subject: Re: find out data types using sql or php
Previous:From: Tom HartDate: 2007-10-26 21:55:08
Subject: Re: find out data types using sql or php

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group