pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joe Conway <mail@joeconway.com>
To: Bhuvan A <bhuvansql@linuxfreemail.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: Preserving datatypes in dblink.
Date: Fri, 23 Aug 2002 07:03:28 -0700
Message-ID: <3D6640B0.1010704@joeconway.com> (raw)
References: <Pine.LNX.4.44.0208231520110.1584-100000@Bhuvan.bksys.co.in>

Bhuvan A wrote:
> On Thu, 22 Aug 2002, Joe Conway wrote:
> 
> 
>>That's because dblink_tok is declared to return text (it *has* to be 
>>declared to return something, so text is the best choice). Explicitly 
>>cast the columns in you view to whatever datatype is correct. I.e. 
>>(untested)
>>
>>CREATE VIEW dbl_my_view AS
>>SELECT
>>  dblink_tok(t.ptr, 0) AS "key",
>>  dblink_tok(t.ptr,1) AS value,
>>  dblink_tok(t.ptr, 2)::timestamp with time zone AS ctime,
>>  dblink_tok(t.ptr, 3)::timestamp with time zone AS mtime
>>FROM (SELECT dblink('hostaddr=192.168.1.15 port=5432 dbname=db1
>>  user=my_user password=my_pass', 'select key, value, ctime, mtime from
>>  my_table'::text) AS ptr) t;
>>
>>Joe
>>
> 
> 
> Thankx for your suggestion. This casting method is applicable for all
> datatypes like int, decimal, date, timestamp. But how about arrays like
> text[]? How do we cast from text to text[]? Its where i stick again.  
> Expecting your much valuable suggestion.
> 

I think it would be:
   dblink_tok(t.ptr, 2)::_text

Array types are the base type name with an underscore in front.

Joe




view thread (7+ messages)  latest in thread

Message-ID: <3D6640B0.1010704@joeconway.com>
Permalink:  ../3D6640B0.1010704@joeconway.com/
Also on:    postgresql.org/message-id/3D6640B0.1010704@joeconway.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: mail@joeconway.com, bhuvansql@linuxfreemail.com
  Subject: Re: Preserving datatypes in dblink.
  In-Reply-To: <3D6640B0.1010704@joeconway.com>
  References: <Pine.LNX.4.44.0208231520110.1584-100000@Bhuvan.bksys.co.in> <3D6640B0.1010704@joeconway.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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