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>
To:
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: b11ea23c0710261459k354763c6v9b54801f3e1bb8b1@mail.gmail.com (view raw or flat)
Thread:
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
application.

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.

-W
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/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-2014 The PostgreSQL Global Development Group