pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #16977: SET LC_TIME TO local_variable don't work
2+ messages / 2 participants
[nested] [flat]

* BUG #16977: SET LC_TIME TO local_variable don't work
@ 2021-04-22 13:12 PG Bug reporting form <noreply@postgresql.org>
  2021-04-22 13:42 ` Re: BUG #16977: SET LC_TIME TO local_variable don't work David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2021-04-22 13:12 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: dusan.djuric@istratech.hr

The following bug has been logged on the website:

Bug reference:      16977
Logged by:          Dusan Djuric
Email address:      dusan.djuric@istratech.hr
PostgreSQL version: 13.2
Operating system:   Windows 10
Description:        

-- THIS DON'T WORK!
CREATE OR REPLACE FUNCTION lctest(p_parameter varchar)
    RETURNS varchar
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE PARALLEL UNSAFE
AS $BODY$
DECLARE
  l_lc_time varchar;
  l_dateFormat varchar := 'TMDay, TMMonth dd.mm.yyyy';
  l_current_date varchar;
BEGIN
  l_lc_time := p_parameter;
  SET LC_TIME TO l_lc_time;
  select to_char(current_date, l_dateFormat)
  into l_current_date;
  RETURN l_current_date;
END;
$BODY$;

-- THIS WORKS!
CREATE OR REPLACE FUNCTION lctest(p_parameter varchar)
    RETURNS varchar
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE PARALLEL UNSAFE
AS $BODY$
DECLARE
  l_lc_time varchar;
  l_dateFormat varchar := 'TMDay, TMMonth dd.mm.yyyy';
  l_current_date varchar;
BEGIN
  l_lc_time := p_parameter;
  SET LC_TIME TO l_lc_time;
  IF l_lc_time = 'hr_HR.UTF8' THEN 
    SET LC_TIME TO 'hr_HR.UTF8'; 
  END IF;
  IF l_lc_time = 'en_EN.UTF8' THEN 
      SET LC_TIME TO 'en_EN.UTF8'; 
  END IF;
  select to_char(current_date, l_dateFormat)
  into l_current_date;
  RETURN l_current_date;
END;
$BODY$;



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #16977: SET LC_TIME TO local_variable don't work
  2021-04-22 13:12 BUG #16977: SET LC_TIME TO local_variable don't work PG Bug reporting form <noreply@postgresql.org>
@ 2021-04-22 13:42 ` David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: David G. Johnston @ 2021-04-22 13:42 UTC (permalink / raw)
  To: dusan.djuric@istratech.hr, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Thu, Apr 22, 2021 at 6:26 AM PG Bug reporting form <
noreply@postgresql.org> wrote:

> The following bug has been logged on the website:
>
> Bug reference:      16977
> Logged by:          Dusan Djuric
> Email address:      dusan.djuric@istratech.hr
> PostgreSQL version: 13.2
> Operating system:   Windows 10
> Description:
>
> -- THIS DON'T WORK!
>
>   SET LC_TIME TO l_lc_time;
>
>
> -- THIS WORKS!
>
>   l_lc_time := p_parameter;
>
I don't think this next line isn't doing what you think...


>   SET LC_TIME TO l_lc_time;
>   IF l_lc_time = 'hr_HR.UTF8' THEN
>     SET LC_TIME TO 'hr_HR.UTF8';
>   END IF;
>   IF l_lc_time = 'en_EN.UTF8' THEN
>       SET LC_TIME TO 'en_EN.UTF8';
>   END IF;
>
>
This isn't a bug.  The SQL Command "SET" is not something that can take a
parameter.  Doing "EXECUTE sql_string;" is probably the simplest solution -
build the SET command as a string and execute it.

David J.

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2021-04-22 13:42 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-04-22 13:12 BUG #16977: SET LC_TIME TO local_variable don't work PG Bug reporting form <noreply@postgresql.org>
2021-04-22 13:42 ` David G. Johnston <david.g.johnston@gmail.com>

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