PostgreSQL
Posted lonelyrains
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PostgreSQL相关的知识,希望对你有一定的参考价值。
# PostgreSQL Schema
--查所有数据表
SELECT
tables.table_name,
tables.table_schema,
tables.table_type
FROM
information_schema.tables
Where
tables.table_name like '%DATA_HISTORY%'
order by tables.table_name
--查数据表的所有字段
SELECT
*,
column_name,
data_type
FROM
information_schema.columns
WHERE
table_name = 'DATA_HISTORY_20211025_001';
-- 查字段值
SELECT
"DATA_HISTORY_2020"."time",
"DATA_HISTORY_2020"."data1",
"DATA_HISTORY_2020"."data2",
FROM
public."DATA_HISTORY_2020",
-- 查字段值
SELECT time,"data1"
FROM "DATA_HISTORY_2021"
WHERE time >= 637708000000000000 And time <=637709000000000000
# bigint datetime 转换
PostgreSQL: Re: Datetime stored in bigint
CREATE OR REPLACE FUNCTION yearzero_to_timestamp(BIGINT)
RETURNS TIMESTAMP
IMMUTABLE
LANGUAGE SQL
AS $bc$
SELECT '0001-01-01'::date + ('1 hour'::interval * (SELECT $1/10000000/60.0/60.0));
$bc$;
SELECT yearzero_to_timestamp(634459985818906250);
上面超链接的代码,有个bug是,秒显示为0。下面的代码
SELECT $1/10000000/60/60.0
要改为
SELECT $1/10000000/60.0/60
以上是关于PostgreSQL的主要内容,如果未能解决你的问题,请参考以下文章
prometheus使用postgresql-adapter连接postgresql
PostgreSQL介绍以及如何开发框架中使用PostgreSQL数据库