Mc、pgsql学习总结

Dataworks(Maxcompute)

  1. 获取昨天日期
select replace(date_add(getdate(),-1),'-','')
select dateadd(to_date(getdate()), -1, 'dd')
  1. 获取上月日期
select substr(replace(ADD_MONTHS(to_date('${yesterday}','yyyymmdd'),-1),'-',''),1,6)
  1. 也支持||''

Hologres(pgsql)

  1. pg_typeof()类似python中的type()函数,用于获取数据类型
select pg_typeof(to_char(CURRENT_TIMESTAMP - '1 days'::interval, 'YYYY-mm-dd'::text)::date)
  1. 获取昨天日期
select to_char(CURRENT_TIMESTAMP - '1 days'::interval, 'YYYYmmdd'::text)
select to_char(now()::date - 1, 'yyyymmdd'::text)
select date(current_date - interval '1 day')
  1. sql中的||,起的是字符串拼接的作用,demo是整数强转字符串
SELECT  pg_typeof( (cast('202201' as int) - 89)||'')

   text

SELECT  pg_typeof( (cast('202201' as int) - 89))

  integer
4. 删除表中指定数据

DELETE from A
WHERE day_data = '2022-11-29'

  删除了A表中day_data = '2022-11-29'的全部数据。
5. 更改表中指定数据

update A set day_data = replace(day_data,'-','/')
where day_data = '2022-11-29';

  将A表中day_data的'2022-11-29'全更改为'2022/11/29'

posted @ 2022-10-27 09:24  anyiya  阅读(52)  评论(0编辑  收藏  举报