Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

How can I address a specific field in record, or can I even define record like in Oracle for example

DECLARE
   TYPE timerec IS RECORD (hours SMALLINT, minutes SMALLINT);
BEGIN
-- something
END;

Here is example of what I mean

do $$
declare
radek record; -- is it posible to define elements in record, I found nothing in postgres documentation
begin
select 'c1', timestamp 'now' , 8 into radek ;
raise notice '% ' , radek;
-- I want to display/select only the middle value (time) 
-- so I need something like raise notice '% ' , radek(2)
radek := (1::int , 'text'::text, date 'tomorrow' );
raise notice '% ' , radek;
-- same case here
end $$

I am using different data types so array is not a solution

share|improve this question
    
I don't need to create type I need to declare it in the code – Baker Aug 24 at 10:34

1 Answer 1

Use a column name after period. You can use aliases:

do $$
declare
    radek record;
begin
    select 'c1' as c1, timestamp 'now' as tstamp, 8 as eight into radek ;
    raise notice '% % %' , radek.c1, radek.tstamp, radek.eight;
end $$
share|improve this answer
    
Thanks it works, ...........I tried aliases before but only here radek := (1::int , 'text'::text /*as cl1*/, date 'tomorrow' ); and it gave me an error – Baker Aug 24 at 10:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.