Re: Equivalent syntax of PL/SQL using array in PL/pgSQL

From: Dang Minh Huong <kakalot49(at)gmail(dot)com>
To: Elliot <yields(dot)falsehood(at)gmail(dot)com>
Cc: Elliot <yields(dot)falsehood(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Equivalent syntax of PL/SQL using array in PL/pgSQL
Date: 2013-11-14 15:56:08
Message-ID: 4521440B-28F6-472D-BA79-BB7CFA9A4F91@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

2013/11/15 0:38、Elliot <yields(dot)falsehood(at)gmail(dot)com> のメッセージ:

>> On 2013-11-14 10:32, Dang Minh Huong wrote:
>> Hi,
>>
>> 2013/11/15 0:20、Elliot <yields(dot)falsehood(at)gmail(dot)com> のメッセージ:
>>
>>>> On 2013-11-14 10:13, Dang Minh Huong wrote:
>>>> Hi all,
>>>>
>>>> I am using PostgreSQL 9.1 and get a syntax error with the following PL/pgSQL clause.
>>>> Is there any equivalent syntax in PL/pgSQL to solve it.
>>>>
>>>> ------
>>>> rec typ[];
>>>> (typ[1]).t1 := 1;
>>>> ------
>>>>
>>>> typ is type which was created by command below.
>>>>
>>>> Create type typ as(
>>>> t1 interger,
>>>> t2 text);
>>>>
>>>> I am migrating data from Oracle to PostgreSQL and encounter this issue.
>>>>
>>>> Thanks,
>>>> Huong,
>>> If typ is the type and rec is the variable, do you mean to access rec[1]?
>> Sorry for this miss.
>> Yes, typ is the type and rec is the variable.
>> I only want to assign a value to rec[1].t1.
>>
>> Thanks,
>> Huong,
>
> I can't recall a source on this but I'm not sure you can assign to
> composite types' members in plpgsql

I think so too.

> (unlike in straight sql where update
> set rec.t1 := 1 is valid). You can build the entire record at once like
> "rec[1] := (1, null)::typ;".
>

But if do like that, the rec[1].t2 will replaced by null.
Is there another way?

Thanks,
Huong,

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dang Minh Huong 2013-11-14 15:59:06 Re: Equivalent syntax of PL/SQL using array in PL/pgSQL
Previous Message David Johnston 2013-11-14 15:43:06 Re: Equivalent syntax of PL/SQL using array in PL/pgSQL