How to get the list of timezones supported by PostgreSQL? - postgresql

The question is pretty self-explanatory. I found this documentation here:
https://www.postgresql.org/docs/current/view-pg-timezone-names.html
However, it does not really mention how to get a list of all the supported timezones. How can I do this?

You may try selecting from the view pg_timezone_names, as the documentation says:
The view pg_timezone_names provides a list of time zone names that are recognized by SET TIMEZONE, along with their associated abbreviations, UTC offsets, and daylight-savings status.
Try the following query:
SELECT
name,
abbrev,
utc_offset,
is_dst
FROM pg_timezone_names;

The answer from Tim was excellent.
For whatever reason my Postgres DB also contained a bunch of fluff with the prefix "posix/" and I also needed these in alphabetical order to use on a website, so I did this:
SELECT
name,
abbrev,
utc_offset,
is_dst
FROM pg_timezone_names
WHERE name !~ 'posix'
ORDER BY name asc;

I ran this query and pasted the results here if anybody wants to save the time of running it themselves.

The query returns time zones grouped by offset so that it will be easier to chose:
SELECT utc_offset, is_dst,
ltrim(
trim(string_agg(distinct (CASE WHEN abbrev NOT LIKE '+%' AND abbrev NOT LIKE '-%' AND abbrev != name THEN abbrev ELSE '' END), ' ')) ||
' ' || string_agg(name, ', ' ORDER BY name)
)
FROM pg_timezone_names
WHERE name NOT LIKE 'posix/%'
AND name NOT LIKE 'Etc/%'
AND name NOT IN ('HST', 'Factory', 'GMT', 'GMT+0', 'GMT-0', 'GMT0', 'localtime', 'UCT', 'Universal', 'UTC', 'PST8PDT', 'ROK', 'W-SU', 'MST', 'CST6CDT')
GROUP BY utc_offset, is_dst
ORDER BY utc_offset, is_dst
And result is:
-11,false,"SST Pacific/Midway, Pacific/Niue, Pacific/Pago_Pago, Pacific/Samoa, US/Samoa"
-10,false,"HST Pacific/Honolulu, Pacific/Johnston, Pacific/Rarotonga, Pacific/Tahiti, US/Hawaii"
-9:30,false,Pacific/Marquesas
-9,false,Pacific/Gambier
-9,true,"HDT America/Adak, America/Atka, US/Aleutian"
-8,false,Pacific/Pitcairn
-8,true,"AKDT America/Anchorage, America/Juneau, America/Metlakatla, America/Nome, America/Sitka, America/Yakutat, US/Alaska"
-7,false,"MST America/Creston, America/Dawson, America/Dawson_Creek, America/Fort_Nelson, America/Hermosillo, America/Phoenix, America/Whitehorse, Canada/Yukon, US/Arizona"
-7,true,"PDT America/Ensenada, America/Los_Angeles, America/Santa_Isabel, America/Tijuana, America/Vancouver, Canada/Pacific, Mexico/BajaNorte, US/Pacific"
-6,false,"CST America/Belize, America/Costa_Rica, America/El_Salvador, America/Guatemala, America/Managua, America/Regina, America/Swift_Current, America/Tegucigalpa, Canada/Saskatchewan, Chile/EasterIsland, Pacific/Easter, Pacific/Galapagos"
-6,true,"MDT America/Boise, America/Cambridge_Bay, America/Chihuahua, America/Denver, America/Edmonton, America/Inuvik, America/Mazatlan, America/Ojinaga, America/Shiprock, America/Yellowknife, Canada/Mountain, Mexico/BajaSur, MST7MDT, Navajo, US/Mountain"
-5,false,"EST America/Atikokan, America/Bogota, America/Cancun, America/Cayman, America/Coral_Harbour, America/Eirunepe, America/Guayaquil, America/Jamaica, America/Lima, America/Panama, America/Porto_Acre, America/Rio_Branco, Brazil/Acre, EST, Jamaica"
-5,true,"CDT America/Bahia_Banderas, America/Chicago, America/Indiana/Knox, America/Indiana/Tell_City, America/Knox_IN, America/Matamoros, America/Menominee, America/Merida, America/Mexico_City, America/Monterrey, America/North_Dakota/Beulah, America/North_Dakota/Center, America/North_Dakota/New_Salem, America/Rainy_River, America/Rankin_Inlet, America/Resolute, America/Winnipeg, Canada/Central, Mexico/General, US/Central, US/Indiana-Starke"
-4,false,"AST America/Anguilla, America/Antigua, America/Aruba, America/Asuncion, America/Barbados, America/Blanc-Sablon, America/Boa_Vista, America/Campo_Grande, America/Caracas, America/Cuiaba, America/Curacao, America/Dominica, America/Grenada, America/Guadeloupe, America/Guyana, America/Kralendijk, America/La_Paz, America/Lower_Princes, America/Manaus, America/Marigot, America/Martinique, America/Montserrat, America/Port_of_Spain, America/Porto_Velho, America/Puerto_Rico, America/Santiago, America/Santo_Domingo, America/St_Barthelemy, America/St_Kitts, America/St_Lucia, America/St_Thomas, America/St_Vincent, America/Tortola, America/Virgin, Brazil/West, Chile/Continental"
-4,true,"CDT EDT America/Detroit, America/Fort_Wayne, America/Grand_Turk, America/Havana, America/Indiana/Indianapolis, America/Indiana/Marengo, America/Indiana/Petersburg, America/Indianapolis, America/Indiana/Vevay, America/Indiana/Vincennes, America/Indiana/Winamac, America/Iqaluit, America/Kentucky/Louisville, America/Kentucky/Monticello, America/Louisville, America/Montreal, America/Nassau, America/New_York, America/Nipigon, America/Pangnirtung, America/Port-au-Prince, America/Thunder_Bay, America/Toronto, Canada/Eastern, Cuba, EST5EDT, posixrules, US/Eastern, US/East-Indiana, US/Michigan"
-3,false,"America/Araguaina, America/Argentina/Buenos_Aires, America/Argentina/Catamarca, America/Argentina/ComodRivadavia, America/Argentina/Cordoba, America/Argentina/Jujuy, America/Argentina/La_Rioja, America/Argentina/Mendoza, America/Argentina/Rio_Gallegos, America/Argentina/Salta, America/Argentina/San_Juan, America/Argentina/San_Luis, America/Argentina/Tucuman, America/Argentina/Ushuaia, America/Bahia, America/Belem, America/Buenos_Aires, America/Catamarca, America/Cayenne, America/Cordoba, America/Fortaleza, America/Jujuy, America/Maceio, America/Mendoza, America/Montevideo, America/Paramaribo, America/Punta_Arenas, America/Recife, America/Rosario, America/Santarem, America/Sao_Paulo, Antarctica/Palmer, Antarctica/Rothera, Atlantic/Stanley, Brazil/East"
-3,true,"ADT America/Glace_Bay, America/Goose_Bay, America/Halifax, America/Moncton, America/Thule, Atlantic/Bermuda, Canada/Atlantic"
-2:30,true,"NDT America/St_Johns, Canada/Newfoundland"
-2,false,"America/Noronha, Atlantic/South_Georgia, Brazil/DeNoronha"
-2,true,"America/Godthab, America/Miquelon, America/Nuuk"
-1,false,Atlantic/Cape_Verde
+0,false,"GMT UTC Africa/Abidjan, Africa/Accra, Africa/Bamako, Africa/Banjul, Africa/Bissau, Africa/Conakry, Africa/Dakar, Africa/Freetown, Africa/Lome, Africa/Monrovia, Africa/Nouakchott, Africa/Ouagadougou, Africa/Sao_Tome, Africa/Timbuktu, America/Danmarkshavn, Atlantic/Reykjavik, Atlantic/St_Helena, Greenwich, Iceland, Zulu"
+0,true,"America/Scoresbysund, Atlantic/Azores"
+1,false,"CET IST WAT Africa/Algiers, Africa/Bangui, Africa/Brazzaville, Africa/Casablanca, Africa/Douala, Africa/El_Aaiun, Africa/Kinshasa, Africa/Lagos, Africa/Libreville, Africa/Luanda, Africa/Malabo, Africa/Ndjamena, Africa/Niamey, Africa/Porto-Novo, Africa/Tunis, Eire, Europe/Dublin"
+1,true,"BST WEST Atlantic/Canary, Atlantic/Faeroe, Atlantic/Faroe, Atlantic/Madeira, Europe/Belfast, Europe/Guernsey, Europe/Isle_of_Man, Europe/Jersey, Europe/Lisbon, Europe/London, GB, GB-Eire, Portugal, WET"
+2,false,"CAT EET SAST Africa/Blantyre, Africa/Bujumbura, Africa/Cairo, Africa/Gaborone, Africa/Harare, Africa/Johannesburg, Africa/Juba, Africa/Khartoum, Africa/Kigali, Africa/Lubumbashi, Africa/Lusaka, Africa/Maputo, Africa/Maseru, Africa/Mbabane, Africa/Tripoli, Africa/Windhoek, Egypt, Europe/Kaliningrad, Libya"
+2,true,"CEST MEST Africa/Ceuta, Antarctica/Troll, Arctic/Longyearbyen, Atlantic/Jan_Mayen, CET, Europe/Amsterdam, Europe/Andorra, Europe/Belgrade, Europe/Berlin, Europe/Bratislava, Europe/Brussels, Europe/Budapest, Europe/Busingen, Europe/Copenhagen, Europe/Gibraltar, Europe/Ljubljana, Europe/Luxembourg, Europe/Madrid, Europe/Malta, Europe/Monaco, Europe/Oslo, Europe/Paris, Europe/Podgorica, Europe/Prague, Europe/Rome, Europe/San_Marino, Europe/Sarajevo, Europe/Skopje, Europe/Stockholm, Europe/Tirane, Europe/Vaduz, Europe/Vatican, Europe/Vienna, Europe/Warsaw, Europe/Zagreb, Europe/Zurich, MET, Poland"
+3,false,"EAT MSK Africa/Addis_Ababa, Africa/Asmara, Africa/Asmera, Africa/Dar_es_Salaam, Africa/Djibouti, Africa/Kampala, Africa/Mogadishu, Africa/Nairobi, Antarctica/Syowa, Asia/Aden, Asia/Baghdad, Asia/Bahrain, Asia/Istanbul, Asia/Kuwait, Asia/Qatar, Asia/Riyadh, Europe/Istanbul, Europe/Kirov, Europe/Minsk, Europe/Moscow, Europe/Simferopol, Europe/Volgograd, Indian/Antananarivo, Indian/Comoro, Indian/Mayotte, Turkey"
+3,true,"EEST IDT Asia/Amman, Asia/Beirut, Asia/Damascus, Asia/Famagusta, Asia/Gaza, Asia/Hebron, Asia/Jerusalem, Asia/Nicosia, Asia/Tel_Aviv, EET, Europe/Athens, Europe/Bucharest, Europe/Chisinau, Europe/Helsinki, Europe/Kiev, Europe/Mariehamn, Europe/Nicosia, Europe/Riga, Europe/Sofia, Europe/Tallinn, Europe/Tiraspol, Europe/Uzhgorod, Europe/Vilnius, Europe/Zaporozhye, Israel"
+4,false,"Asia/Baku, Asia/Dubai, Asia/Muscat, Asia/Tbilisi, Asia/Yerevan, Europe/Astrakhan, Europe/Samara, Europe/Saratov, Europe/Ulyanovsk, Indian/Mahe, Indian/Mauritius, Indian/Reunion"
+4:30,false,Asia/Kabul
+4:30,true,"Asia/Tehran, Iran"
+5,false,"PKT Antarctica/Mawson, Asia/Aqtau, Asia/Aqtobe, Asia/Ashgabat, Asia/Ashkhabad, Asia/Atyrau, Asia/Dushanbe, Asia/Karachi, Asia/Oral, Asia/Qyzylorda, Asia/Samarkand, Asia/Tashkent, Asia/Yekaterinburg, Indian/Kerguelen, Indian/Maldives"
+5:30,false,"IST Asia/Calcutta, Asia/Colombo, Asia/Kolkata"
+5:45,false,"Asia/Kathmandu, Asia/Katmandu"
+6,false,"Antarctica/Vostok, Asia/Almaty, Asia/Bishkek, Asia/Dacca, Asia/Dhaka, Asia/Kashgar, Asia/Omsk, Asia/Qostanay, Asia/Thimbu, Asia/Thimphu, Asia/Urumqi, Indian/Chagos"
+6:30,false,"Asia/Rangoon, Asia/Yangon, Indian/Cocos"
+7,false,"WIB Antarctica/Davis, Asia/Bangkok, Asia/Barnaul, Asia/Ho_Chi_Minh, Asia/Hovd, Asia/Jakarta, Asia/Krasnoyarsk, Asia/Novokuznetsk, Asia/Novosibirsk, Asia/Phnom_Penh, Asia/Pontianak, Asia/Saigon, Asia/Tomsk, Asia/Vientiane, Indian/Christmas"
+8,false,"AWST CST HKT PST WITA Asia/Brunei, Asia/Choibalsan, Asia/Chongqing, Asia/Chungking, Asia/Harbin, Asia/Hong_Kong, Asia/Irkutsk, Asia/Kuala_Lumpur, Asia/Kuching, Asia/Macao, Asia/Macau, Asia/Makassar, Asia/Manila, Asia/Shanghai, Asia/Singapore, Asia/Taipei, Asia/Ujung_Pandang, Asia/Ulaanbaatar, Asia/Ulan_Bator, Australia/Perth, Australia/West, Hongkong, PRC, ROC, Singapore"
+8:45,false,Australia/Eucla
+9,false,"JST KST WIT Asia/Chita, Asia/Dili, Asia/Jayapura, Asia/Khandyga, Asia/Pyongyang, Asia/Seoul, Asia/Tokyo, Asia/Yakutsk, Japan, Pacific/Palau"
+9:30,false,"ACST Australia/Adelaide, Australia/Broken_Hill, Australia/Darwin, Australia/North, Australia/South, Australia/Yancowinna"
+10,false,"AEST ChST Antarctica/DumontDUrville, Antarctica/Macquarie, Asia/Ust-Nera, Asia/Vladivostok, Australia/ACT, Australia/Brisbane, Australia/Canberra, Australia/Currie, Australia/Hobart, Australia/Lindeman, Australia/Melbourne, Australia/NSW, Australia/Queensland, Australia/Sydney, Australia/Tasmania, Australia/Victoria, Pacific/Chuuk, Pacific/Guam, Pacific/Port_Moresby, Pacific/Saipan, Pacific/Truk, Pacific/Yap"
+10:30,false,"Australia/LHI, Australia/Lord_Howe"
+11,false,"Antarctica/Casey, Asia/Magadan, Asia/Sakhalin, Asia/Srednekolymsk, Pacific/Bougainville, Pacific/Efate, Pacific/Guadalcanal, Pacific/Kosrae, Pacific/Norfolk, Pacific/Noumea, Pacific/Pohnpei, Pacific/Ponape"
+12,false,"NZST Antarctica/McMurdo, Antarctica/South_Pole, Asia/Anadyr, Asia/Kamchatka, Kwajalein, NZ, Pacific/Auckland, Pacific/Fiji, Pacific/Funafuti, Pacific/Kwajalein, Pacific/Majuro, Pacific/Nauru, Pacific/Tarawa, Pacific/Wake, Pacific/Wallis"
+12:45,false,"NZ-CHAT, Pacific/Chatham"
+13,false,"Pacific/Apia, Pacific/Enderbury, Pacific/Fakaofo, Pacific/Kanton, Pacific/Tongatapu"
+14,false,Pacific/Kiritimati
This is ready to use for a Time Zone selector. The DST i.e. a summer time items I show in a different color.

Related

PostGIS ST_Difference function returns wrong geometry in result

I'm trying to run ST_Difference but my result is incorrect
The code is here:
SELECT ST_AsText(
ST_Difference(
ST_GeomFromEWKT('SRID=4326;POLYGON ((106.694934906617 10.8530437566453, 106.694980963617 10.8529740046453, 106.695035468617 10.8528861486454, 106.695059276617 10.8528373486454, 106.695165321617 10.8526200556455, 106.695231846616 10.8524577606456, 106.695267968616 10.8523695986457, 106.695318066616 10.8522472206457, 106.695317868616 10.8522426106458, 106.695142407616 10.8521968636457, 106.694954351617 10.8521300896456, 106.694838748617 10.8520996186456, 106.694814976617 10.8521306086455, 106.694659358617 10.8521132776454, 106.694606107617 10.8524256896453, 106.694594079617 10.8524396486453, 106.694544500617 10.8526400426452, 106.694498703617 10.8528507296451, 106.694487505617 10.8528959666451, 106.694476373617 10.8529041356451, 106.694435062618 10.8529125806451, 106.694427525617 10.8529585276451, 106.694404341618 10.853118700645, 106.694370784618 10.8533247416449, 106.694437521618 10.8533458706449, 106.694721801617 10.8533875776451, 106.694733694617 10.8533889876451, 106.694934906617 10.8530437566453))'),
ST_GeomFromEWKT('SRID=4326;POLYGON ((106.69473290032974 10.85337259541688, 106.69469456226234 10.853366656136817, 106.69473803624265 10.853260751886767, 106.69478665997649 10.853280310349916, 106.69473290032974 10.85337259541688))')
)
)
Result:
POLYGON((106.694934906617 10.8530437566453,106.694980963617 10.8529740046453,106.695035468617 10.8528861486454,106.695059276617 10.8528373486454,106.695165321617 10.8526200556455,106.695231846616 10.8524577606456,106.695267968616 10.8523695986457,106.695318066616 10.8522472206457,106.695317868616 10.8522426106458,106.695142407616 10.8521968636457,106.694954351617 10.8521300896456,106.694838748617 10.8520996186456,106.694814976617 10.8521306086455,106.694659358617 10.8521132776454,106.694606107617 10.8524256896453,106.694594079617 10.8524396486453,106.694544500617 10.8526400426452,106.694498703617 10.8528507296451,106.694487505617 10.8528959666451,106.694476373617 10.8529041356451,106.694435062618 10.8529125806451,106.694427525617 10.8529585276451,106.694404341618 10.853118700645,106.694370784618 10.8533247416449,106.694437521618 10.8533458706449,106.694721801617 10.8533875776451,106.694733694617 10.8533889876451,106.694934906617 10.8530437566453),(106.69473290033 10.8533725954169,106.694694562262 10.8533666561368,106.694738036243 10.8532607518868,106.694786659976 10.8532803103499,106.69473290033 10.8533725954169))
I would like a query similar to the tools erase and intersect from ArcGIS.
What's wrong in my code?

Timeout Expired during Link server query

I have a SQL Server 2017 database which has 10 tables. Each table is filled by 3rd party application.
When there is any insert/update in any table, a trigger is fired. The trigger updates another table located in remote SQL Server 2017 instance & database (linkserver).
That remote database includes only one table which maintains the information of source database (10 tables). So I have 10 after insert triggers and 10 after update triggers. Each table has about 172 column.
Sometimes, I get an error
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding
My after insert trigger is:
ALTER TRIGGER [dbo].[AfterINSERTTriggerONE] on [dbo].[ONE]
FOR INSERT AS
INSERT INTO [TargetServer].[TargetDb].[dbo].[DataLogs](
[DeviceId],
[DateTime],
[TimeStampUTC],
[StationIsOpen],
[PanelIsOpen],
[PowerIsOscillating],
[Heater1_FlameIsOn],
[Heater1_Flame2IsOn],
[Heater1_WaterLevelSwitch],
[Heater2_FlameIsOn],
[Heater2_Flame2IsOn],
[Heater2_WaterLevelSwitch],
[Heater3_FlameIsOn],
[Heater3_Flame2IsOn],
[Heater3_WaterLevelSwitch],
[Heater4_FlameIsOn],
[Heater4_Flame2IsOn],
[Heater4_WaterLevelSwitch],
[Ups_BatteryMode],
[Ups_BatteryCharging],
[Ups_ShutdownEvent],
[Ups_Remote],
[Filter1],
[Filter2],
[Filter3],
[AirConditionerIsOn],
[R1_P],
[R1_T],
[R1_Qb],
[R1_Qm],
[R1_C],
[R1_CarbonDioxide],
[R1_Nitrogen],
[R1_TbX],
[R1_PbX],
[R1_Methane],
[R1_Ethane],
[R1_Propane],
[R1_iButane],
[R1_BatRemain],
[R1_Productivity],
[R2_P],
[R2_T],
[R2_Qb],
[R2_Qm],
[R2_C],
[R2_CarbonDioxide],
[R2_Nitrogen],
[R2_TbX],
[R2_PbX],
[R2_Methane],
[R2_Ethane],
[R2_Propane],
[R2_iButane],
[R2_BatRemain],
[R2_Productivity],
[R3_P],
[R3_T],
[R3_Qb],
[R3_Qm],
[R3_C],
[R3_CarbonDioxide],
[R3_Nitrogen],
[R3_TbX],
[R3_PbX],
[R3_Methane],
[R3_Ethane],
[R3_Propane],
[R3_iButane],
[R3_BatRemain],
[R3_Productivity],
[R4_P],
[R4_T],
[R4_Qb],
[R4_Qm],
[R4_C],
[R4_CarbonDioxide],
[R4_Nitrogen],
[R4_TbX],
[R4_PbX],
[R4_Methane],
[R4_Ethane],
[R4_Propane],
[R4_iButane],
[R4_BatRemain],
[R4_Productivity],
[Total_Qb],
[Total_Qm],
[InGasP],
[InGasT],
[OutGasP],
[OutGasT],
[AirT],
[AirHumadity],
[PanelT],
[PanelHumadity],
[ConexTemperature],
[ConexHumadity],
[StationCapacity],
[Productivity],
[Heater1_InGasT],
[Heater1_WaterT],
[Heater1_OutGasT],
[Heater1_WaterLevel],
[Heater2_InGasT],
[Heater2_WaterT],
[Heater2_OutGasT],
[Heater2_WaterLevel],
[Heater3_InGasT],
[Heater3_WaterT],
[Heater3_OutGasT],
[Heater3_WaterLevel],
[Heater4_InGasT],
[Heater4_WaterT],
[Heater4_OutGasT],
[Heater4_WaterLevel],
[OdorizerLevel1],
[OdorizerLevel2],
[Ups_AmbientTemperature],
[Ups_BatteryDischargeCurrent],
[Ups_BatteryVoltage],
[Ups_OutputVoltage],
[TBS_OutGasP],
[R1_VbT],
[R1_Vb],
[R1_Vbd],
[R1_VmT],
[R1_Vm],
[R1_Vmd],
[R1_Vb_PrevDay],
[R1_Vm_PrevDay],
[R2_VbT],
[R2_Vb],
[R2_Vbd],
[R2_VmT],
[R2_Vm],
[R2_Vmd],
[R2_Vb_PrevDay],
[R2_Vm_PrevDay],
[R3_VbT],
[R3_Vb],
[R3_Vbd],
[R3_VmT],
[R3_Vm],
[R3_Vmd],
[R3_Vb_PrevDay],
[R3_Vm_PrevDay],
[R4_VbT],
[R4_Vb],
[R4_Vbd],
[R4_VmT],
[R4_Vm],
[R4_Vmd],
[R4_Vb_PrevDay],
[R4_Vm_PrevDay],
[Total_Vb_PrevDay]
)
select
StationName,
Time_Stamp,
Utc,
StationIsOpen,
PanelIsOpen,
PowerIsOscillating,
Heater1_FlameIsOn,
Heater1_Flame2IsOn,
Heater1_WaterLevelSwitch,
Heater2_FlameIsOn,
Heater2_Flame2IsOn,
Heater2_WaterLevelSwitch,
Heater3_FlameIsOn,
Heater3_Flame2IsOn,
Heater3_WaterLevelSwitch,
Heater4_FlameIsOn,
Heater4_Flame2IsOn,
Heater4_WaterLevelSwitch,
Ups_BatteryMode,
Ups_BatteryCharging,
Ups_ShutdownEvent,
Ups_Remote,
Filter1,
Filter2,
Filter3,
AirConditionerIsOn,
R1_P,
R1_T,
R1_Qb,
R1_Qm,
R1_C,
R1_CarbonDioxide,
R1_Nitrogen,
R1_TbX,
R1_PbX,
R1_Methane,
R1_Ethane,
R1_Propane,
R1_iButane,
R1_BatRemain,
R1_Productivity,
R2_P,
R2_T,
R2_Qb,
R2_Qm,
R2_C,
R2_CarbonDioxide,
R2_Nitrogen,
R2_TbX,
R2_PbX,
R2_Methane,
R2_Ethane,
R2_Propane,
R2_iButane,
R2_BatRemain,
R2_Productivity,
R3_P,
R3_T,
R3_Qb,
R3_Qm,
R3_C,
R3_CarbonDioxide,
R3_Nitrogen,
R3_TbX,
R3_PbX,
R3_Methane,
R3_Ethane,
R3_Propane,
R3_iButane,
R3_BatRemain,
R3_Productivity,
R4_P,
R4_T,
R4_Qb,
R4_Qm,
R4_C,
R4_CarbonDioxide,
R4_Nitrogen,
R4_TbX,
R4_PbX,
R4_Methane,
R4_Ethane,
R4_Propane,
R4_iButane,
R4_BatRemain,
R4_Productivity,
Total_Qb,
Total_Qm,
InGasP,
InGasT,
OutGasP,
OutGasT,
AirT,
AirHumadity,
PanelT,
PanelHumadity,
ConexTemperature,
ConexHumadity,
StationCapacity,
Productivity,
Heater1_InGasT,
Heater1_WaterT,
Heater1_OutGasT,
Heater1_WaterLevel,
Heater2_InGasT,
Heater2_WaterT,
Heater2_OutGasT,
Heater2_WaterLevel,
Heater3_InGasT,
Heater3_WaterT,
Heater3_OutGasT,
Heater3_WaterLevel,
Heater4_InGasT,
Heater4_WaterT,
Heater4_OutGasT,
Heater4_WaterLevel,
OdorizerLevel1,
OdorizerLevel2,
Ups_AmbientTemperature,
Ups_BatteryDischargeCurrent,
Ups_BatteryVoltage,
Ups_OutputVoltage,
TBS_OutGasP,
R1_VbT,
R1_Vb,
R1_Vbd,
R1_VmT,
R1_Vm,
R1_Vmd,
R1_Vb_PrevDay,
R1_Vm_PrevDay,
R2_VbT,
R2_Vb,
R2_Vbd,
R2_VmT,
R2_Vm,
R2_Vmd,
R2_Vb_PrevDay,
R2_Vm_PrevDay,
R3_VbT,
R3_Vb,
R3_Vbd,
R3_VmT,
R3_Vm,
R3_Vmd,
R3_Vb_PrevDay,
R3_Vm_PrevDay,
R4_VbT,
R4_Vb,
R4_Vbd,
R4_VmT,
R4_Vm,
R4_Vmd,
R4_Vb_PrevDay,
R4_Vm_PrevDay,
Total_Vb_PrevDay
from inserted;
PRINT 'We Successfully Fired the AFTER INSERT Trigger for Table [ONE] in SQL Server.'
and AfterUpdate:
ALTER TRIGGER [dbo].[AfterUpdateTriggerONE] ON [dbo].[ONE]
AFTER UPDATE
AS
if (UPDATE (StationIsOpen))
BEGIN
UPDATE [TargetServer].[TargetDBDb].[dbo].[DataLogs]
SET Trg.StationIsOpen = ins.StationIsOpen , Trg.Updated = 1
FROM [TargetServer].[TargetDBDb].[dbo].[DataLogs] Trg
JOIN inserted ins
ON Trg.[DateTime] = ins.[Time_Stamp] AND
Trg.[DeviceId] = ins.[StationName]
END
if (UPDATE (PanelIsOpen))
BEGIN
UPDATE [TargetServer].[TargetDBDb].[dbo].[DataLogs]
SET Trg.PanelIsOpen = ins.PanelIsOpen , Trg.Updated = 1
FROM [TargetServer].[TargetDBDb].[dbo].[DataLogs] Trg
JOIN inserted ins
ON Trg.[DateTime] = ins.[Time_Stamp] AND
Trg.[DeviceId] = ins.[StationName]
END
.
.
.
and all other 170 columns

HTL AEM conditional OR operator issue

I want to be able to use the "||" OR operator in this context
inside a schema, i have two dates I need to pull from the JCR content if the value in the field has not been the author
<script type="application/ld+json" >
"datePublished": "${properties.datePublishedArticle #context="html" ||'yyyy-MM-dd' # format=currentPage.lastModified }",
"dateModified": "${properties.dateModifiedArticle # context="html" || 'yyyy-MM-dd' # format=currentPage.lastModified}"
</script>
org.apache.sling.api.scripting.ScriptEvaluationException:
mismatched input '#' expecting {'}', '.', 'in', '&&', '||', ',', '['} in line 67 where datepublished is located.
In order words, if author has not authored a value, it will take the value from the jcr content. They work fine when done separately.
Do not understand the error that is indicating.
Have you tried to use it like this:
<script type="application/ld+json" >
"datePublished": "${properties.datePublishedArticle ||'yyyy-MM-dd' # context="html", format = currentPage.lastModified }",
"dateModified": "${properties.dateModifiedArticle || 'yyyy-MM-dd' # context="html", format = currentPage.lastModified}"
</script>
I would think that the error is happening because you shouldn't be repeating the '#' block in the same HTL statement.
Although #atgar's solution does not throw an error, I think it does not do what the author asked for: output either the authored date or the JCR (lastModified) date.
Something like this would be closer to what he needs:
<script type="application/ld+json" >
"datePublished": "${'yyyy-MM-dd' # context='html', format = (properties.datePublishedArticle ? properties.datePublishedArticle : currentPage.lastModified) }",
"dateModified": "${'yyyy-MM-dd' # context='html', format = (properties.dateModifiedArticle ? properties.dateModifiedArticle : currentPage.lastModified)}"
</script>
Please note, when using HTL date formatting, the actual values should be in the format option.

TypeORM : How to search for a range of Date in PostgresSQL?

consider an ISO8601 date
and want to do a query using Typeorm and PostgreSQL
if (orderInput.begining && orderInput.ending)
query.andWhere(`order.createdAt
BETWEEN to_timestamp(${orderInput.begining} / 1000 )
AND to_timestamp(${orderInput.ending} / 1000 );
`);
These are my argument:
"2010-12-24T21:32:33.477Z"
"2019-12-24T21:32:33.477Z"
and this is the underhood query and the err :
query failed: SELECT DISTINCT "distinctAlias"."order_id" as "ids_order_id" FROM (SELECT "order"."id" AS "order_id", "order"."createdAt" AS "order_createdAt"
FROM "order" "order" INNER JOIN "ware" "ware" ON "ware"."id"="order"."wareId" WHERE "order"."organizationId" = $1 AND "order"."createdAt"
BETWEEN Wed Dec 25 2019 01:02:33 GMT+0330 (Iran Standard Time)
AND Wed Dec 25 2019 01:02:33 GMT+0330 (Iran Standard Time) ;) "distinctAlias" ORDER BY "order_id" ASC LIMIT 25 -- PARAMETERS: ["8fd87ced-eb58-4460-b74e-d5a2b1491622"]
error: { error: syntax error at or near "Dec"
I guess it's because of that the arguments are not taken wraped in ' ' (qoutes)
I don't know how to pass the arguments to typescript as standard ISO8606 Date(typescript) with ' '(qoutes) to be then passed to PostgreSQL
My solution as of now(2021-05-26) using Between of TypeORM (docs):
const orders = await this.orderRepo.find({
where: {
createdAt: Between(
new Date(orderInput.begining).toISOString(),
new Date(orderInput.ending)).toISOString(),
),
},
skip: skip || 0,
take: take || 10,
});
Both Typescript And PostgreSQL know ISO8601 well and there is no need to to_timestamp() for PostgreSQL.
So this works like a chram:
if (orderInput.begining && orderInput.ending)
query.andWhere(
`"order"."createdAt"
BETWEEN :begin
AND :end`
,{ begin: orderInput.begining, end: orderInput.ending);
NOTE: in JavaScript, you can easily make a ISO8601 standard Date in this way:
const date = new Date(2020,2,2)
const iso = date.toISOString()
Try this:
await this.YOUR_REPOSITORY
.createQueryBuilder("order")
.where('order.createdAt BETWEEN :startDate AND :endDate', { startDate: orderInput.begining, endDate: orderInput.ending })
.getMany();

UTC_TIMESTAMP() to user defined timezone?

I am storing timestamps in my db using UTC_TIMESTAMP().
I want to output them based on user selected timezone. I tried writing a small function to do this, however, it does not output correctly.
// Date/time converter
function convertTZ($date, $tz, $tzFormat)
{
$date = new DateTime($date);
$date->setTimezone(new DateTimeZone($tz));
return $date->format($tzFormat);
}
echo $_SESSION['dtCurrLogin'].'<br />';
echo convertTZ($_SESSION['dtCurrLogin'], 'UTC', 'F j, Y # g:i:s a e');
dtCurrLogin from db = 2013-09-12 01:23:45
the above outputs :
2013-09-12 01:23:45
September 12, 2013 # 5:23:45 am UTC
Obviously this is not correct as I went from UTC to UTC so they should be equal. If I change to output EST then it shows 1:23:45 am, but of course that would not be right either.
Didn't realize I needed to specify incoming timezone... using the following worked for me...
function convertTZ($date_time, $from_tz, $to_tz, $format_tz)
{
$time_object = new DateTime($date_time, new DateTimeZone($from_tz));
$time_object->setTimezone(new DateTimeZone($to_tz));
return $time_object->format($format_tz);
}