From: | Alvaro Herrera <alvherre(at)commandprompt(dot)com> |
---|---|
To: | Eliana Gutierrez <egp1962(at)yahoo(dot)com(dot)au> |
Cc: | ayuda postgres <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | Re: conversion de dato a bytea |
Date: | 2007-02-15 13:39:35 |
Message-ID: | 20070215133935.GA4682@alvh.no-ip.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
Eliana Gutierrez escribió:
> Hola a todos!!!!
>
> Conoce alguien alguna funcion o algo parecido en SQL, que me permita convertir un grupo de campos (long, strings) a bytea antes de hacer el insert.
> Para no pasarselo como string, pues me debe permitir nulos.
alvherre=# select record_out(row('t', 1, null, 'hello world', 'huh', now(), '', ' '));
record_out
-----------------------------------------------------------------
(t,1,,"hello world",huh,"2007-02-15 10:32:20.632041-03",""," ")
(1 fila)
Eso puedes expandirlo a un record posteriormente:
alvherre=# create type foo as (a bool, b int, c int, d text, e text, f timestamptz, g text, h text);
CREATE TYPE
alvherre=# select record_in('(t,1,,"hello world",huh,"2007-02-15 10:32:18.208098-03",""," ")', 'foo'::regtype, -1);
record_in
-----------------------------------------------------------------
(t,1,,"hello world",huh,"2007-02-15 10:32:18.208098-03",""," ")
(1 fila)
alvherre=# select * from record_in('(t,1,,"hello world",huh,"2007-02-15 10:32:18.208098-03",""," ")', 'foo'::regtype, -1) as (a bool, b int, c int, d text, e text, f timestamptz, g text, h text);
a | b | c | d | e | f | g | h
---+---+---+-------------+-----+-------------------------------+---+---
t | 1 | | hello world | huh | 2007-02-15 10:32:18.208098-03 | |
(1 fila)
Y verificas que realmente la columna C queda como nulo, que es lo que
ingresaste, pero no la G ni la H:
alvherre=# \x
Se ha activado el despliegue expandido.
alvherre=# select *, c is null, g is null, h is null from record_in('(t,1,,"hello world",huh,"2007-02-15 10:32:18.208098-03",""," ")', 'foo'::regtype, -1) as (a bool, b int, c int, d text, e text, f timestamptz, g text, h text);
-[ RECORD 1 ]---------------------------
a | t
b | 1
c |
d | hello world
e | huh
f | 2007-02-15 10:32:18.208098-03
g |
h |
?column? | t
?column? | f
?column? | f
--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2007-02-15 13:49:33 | Re: [pgsql-es-ayuda] tabla pg_user Ayuda...... |
Previous Message | Miguel A. Valero | 2007-02-15 13:13:54 | Lo que es ser bien bruto ah!!!!!! |