Re: Indicating DEFAULT values in INSERT statement

From: Postgres User <postgres(dot)developer(at)gmail(dot)com>
To: Diego Augusto Molina <diegoaugustomolina(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Indicating DEFAULT values in INSERT statement
Date: 2011-08-10 01:10:36
Message-ID: CADecbQnXjvTqn_MpWM6uaFdDeLeXatCv5jmb_xz=ZYQb-Whm-g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Good idea but you're right, if the default value is an expression such as a
the next serial value, it will need to be executed first. If Execute
doesn't return the interpreted value, I don't know of a way to make it
work..

On Tue, Aug 9, 2011 at 5:35 PM, Diego Augusto Molina <
diegoaugustomolina(at)gmail(dot)com> wrote:

> This is a bit hacky, but it may work (I haven't tried it yet). If it
> works let us know and if it doesn't then maybe we can debug it and get
> something useful, or move on to another solution.
>
> <code>
> INSERT INTO public.test
> (
> userid, object_id, user_notes, object_status, created_ts
> )
> VALUES
> (
> p_userid, p_obj_id, p_user_notes, p_obj_status,
> Case When p_created_ts Is Not Null Then p_created_ts Else
> ( -- You may want to be sure the field has a default value.
> SELECT d.adsrc -- or should it be d.adbin?
> FROM
> pg_catalog.pg_attribute a INNER JOIN
> pg_catalog.pg_attrdef d ON (a.attnum =
> d.adnum)
> WHERE
> a.attname = 'created_ts' AND
> a.attrelid = 'public.test'::REGCLASS AND
> d.adrelid = 'public.test'::REGCLASS
> ) End
> );
> </code>
>
> Well (thinking it thoroughly) it won't work at all as is. It will just
> put the source code of the default expression but you would need to
> *interpret* it first.
> Looked for a way to do this (without `EXECUTE') but couldn't find it.
> Sorry.
>
> --
> Diego Augusto Molina
> diegoaugustomolina(at)gmail(dot)com
>
> ES: Por favor, evite adjuntar documentos de Microsoft Office. Serán
> desestimados.
> EN: Please, avoid attaching Microsoft Office documents. They shall be
> discarded.
> LINK: http://www.gnu.org/philosophy/no-word-attachments.html
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message tamanna madaan 2011-08-10 05:07:05 canceling autovacuum task error
Previous Message Diego Augusto Molina 2011-08-10 00:35:13 Re: Indicating DEFAULT values in INSERT statement